class ServerOption implements Serializable {

	public static Gson getGson() {
		Gson gson = new GsonBuilder().
				registerTypeAdapter(ServerOption.class, new ServerOptionParentDeserializer()).
				excludeFieldsWithoutExposeAnnotation().
				create();
		return gson;
	}

}

class ServerOptionTest  {

	@Test
	public void testOptionSelectedParametersWithInheritance() throws Exception {

		URL url = Thread.currentThread().getContextClassLoader().getResource("at/rtr/rmbt/util/model/option/test2.json");
		File file = new File(url.getPath());
		ServerOptionContainer options = new ServerOptionContainer(
				new ArrayList<>(Arrays.asList(ServerOption.getGson().fromJson(new FileReader(file), ServerOption.class))));
		
		List<ServerOption> list = options.select(options.getRootOptions().get(0));
		assertNotNull("selected option sublist not null", list);
		
		List<ServerOption> subList = options.select(list.get(0));
		Map<String, Object> paramMap = options.getSelectedParams();		
		assertNull("selected option 0 sublist is null", subList);
		assertEquals("selected option 0 param 'option'", "a1", paramMap.get("option"));
		assertNull("selected option 0 dropped param 'title'", paramMap.get("title"));
		assertEquals("selected option 0 params size", 2, paramMap.size());
		assertEquals("selected option 0 overriden param 'parent_param'", true, paramMap.get("parent_param"));

		subList = options.select(list.get(1));
		paramMap = options.getSelectedParams();		
		assertNull("selected option 1 sublist is null", subList);
		assertEquals("selected option 1 param 'option'", "a2", paramMap.get("option"));
		assertNull("selected option 1 dropped param 'title'", paramMap.get("title"));
		assertEquals("selected option 1 params size", 2, paramMap.size());
		assertEquals("selected option 1 inherited param 'parent_param'", false, paramMap.get("parent_param"));

		subList = options.select(list.get(2));
		paramMap = options.getSelectedParams();		
		assertNull("selected option 2 sublist is null", subList);
		assertEquals("selected option 2 param 'option'", "a3", paramMap.get("option"));
		assertEquals("selected option 2 params size", 4, paramMap.size());
		assertEquals("selected option 2 param 'titles'", "a3", paramMap.get("titles"));
		assertEquals("selected option 2 inherited param 'parent_param'", false, paramMap.get("parent_param"));
		
		subList = options.select(list.get(3));
		paramMap = options.getSelectedParams();		
		assertNull("selected option 3 sublist is null", subList);
		assertEquals("selected option 3 params size", 1, paramMap.size());
		assertEquals("selected option 3 inherited param 'parent_param'", false, paramMap.get("parent_param"));
	}

}