ServerOption implements Serializable { public static Gson getGson() { Gson gson = new GsonBuilder(). registerTypeAdapter(ServerOption.class, new ServerOptionParentDeserializer()). excludeFieldsWithoutExposeAnnotation(). create(); return gson; } ServerOption();  ServerOption(final String title);  ServerOption(final String title, final String summary); static Gson getGson(); ServerOption getParent(); void setParent(ServerOption parent); String getTitle(); void setTitle(String title); String getSummary(); void setSummary(String summary); List<ServerOption> getEnabledOptionList(); List<ServerOption> getOptionList(); void setOptionList(List<ServerOption> optionList); void addOption(final ServerOption option); Map<String, Object> getParameterMap(); void setParameterMap(Map<String, Object> parameterMap); void addParameter(final String key, final Object value); List<OptionFunction> getFunctionList(); void setFunctionMap(List<OptionFunction> functionList); void addFunction(final OptionFunction value); Map<String, Object> getDependsOnMap(); void setDependsOnMap(Map<String, Object> dependsOnMap); void addDependsOn(final String key, final Object value); boolean isEnabled(); void setEnabled(boolean isEnabled); boolean isChecked(); void setChecked(boolean isChecked); boolean isDefault(); void setDefault(boolean isDefault); boolean isInHierarchyBelow(ServerOption option); @Override String toString();  }
@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")); }
@Test public void testOptionParameterOverrides() throws Exception { URL url = Thread.currentThread().getContextClassLoader().getResource("at/rtr/rmbt/util/model/option/test3.json"); File file = new File(url.getPath()); ServerOptionContainer options = new ServerOptionContainer( new ArrayList<>(Arrays.asList(ServerOption.getGson().fromJson(new FileReader(file), ServerOption.class)))); final List<ServerOption> list = options.getRootOptions(); List<ServerOption> sublist = options.select(list.get(0)); assertEquals("option 0 select param size", 0, options.getSelectedParams().size()); sublist = options.select(sublist.get(0)); assertEquals("option 0->0 select param size", 2, options.getSelectedParams().size()); assertEquals("option 0->0 param 'option'", "a1", options.getSelectedParams().get("option")); sublist = options.select(sublist.get(0)); assertEquals("option 0->0->0 select param size", 2, options.getSelectedParams().size()); assertEquals("option 0->0->0 override param 'option'", "a2", options.getSelectedParams().get("option")); sublist = options.select(sublist.get(0)); assertEquals("option 0->0->0->0 select param size", 2, options.getSelectedParams().size()); assertEquals("option 0->0->0->0 override param 'option'", "a3", options.getSelectedParams().get("option")); sublist = options.select(sublist.get(0)); assertEquals("option 0->0->0->0->0 select param size", 2, options.getSelectedParams().size()); assertEquals("option 0->0->0->0->0 override param 'option'", "a3", options.getSelectedParams().get("option")); }