ServiceModule extends BaseModule<ServiceModule, ServiceInfo> implements Validable { @Override public ServiceInfo getModuleInfo() { return serviceInfo; } ServiceModule(StackContext stackContext, ServiceInfo serviceInfo, ServiceDirectory serviceDirectory);  ServiceModule(
      StackContext stackContext, ServiceInfo serviceInfo, ServiceDirectory serviceDirectory, boolean isCommonService); @Override ServiceInfo getModuleInfo(); @Override void resolve(
      ServiceModule parentModule, Map<String, StackModule> allStacks, Map<String, ServiceModule> commonServices, Map<String, ExtensionModule> extensions); void resolveExplicit(
      ServiceModule parentModule, Map<String, StackModule> allStacks, Map<String, ServiceModule> commonServices, Map<String, ExtensionModule> extensions); void resolveInternal(
      ServiceModule parentModule, Map<String, StackModule> allStacks, Map<String, ServiceModule> commonServices,
      Map<String, ExtensionModule> extensions, boolean resolveExplicit); void resolveCommonService(Map<String, StackModule> allStacks, Map<String, ServiceModule> commonServices, Map<String, ExtensionModule> extensions); @Override boolean isDeleted(); @Override String getId(); @Override void finalizeModule(); @Override boolean isValid(); @Override void setValid(boolean valid); @Override void addError(String error); @Override Collection<String> getErrors(); ServiceDirectory getServiceDirectory(); @Override void addErrors(Collection<String> errors); @Override String toString();  }
@Test public void testResolve_Comment() throws Exception { String comment = "test comment"; ServiceInfo info = new ServiceInfo(); ServiceInfo parentInfo = new ServiceInfo(); info.setComment(comment); ServiceModule service = resolveService(info, parentInfo); assertEquals(comment, service.getModuleInfo().getComment()); info.setComment(null); parentInfo.setComment(comment); service = resolveService(info, parentInfo); assertEquals(comment, service.getModuleInfo().getComment()); info.setComment(comment); parentInfo.setComment("other comment"); service = resolveService(info, parentInfo); assertEquals(comment, service.getModuleInfo().getComment()); }
@Test public void testResolve_DisplayName() throws Exception { String displayName = "test_display_name"; ServiceInfo info = new ServiceInfo(); ServiceInfo parentInfo = new ServiceInfo(); info.setDisplayName(displayName); ServiceModule service = resolveService(info, parentInfo); assertEquals(displayName, service.getModuleInfo().getDisplayName()); info.setDisplayName(null); parentInfo.setDisplayName(displayName); service = resolveService(info, parentInfo); assertEquals(displayName, service.getModuleInfo().getDisplayName()); info.setDisplayName(displayName); parentInfo.setDisplayName("other display name"); service = resolveService(info, parentInfo); assertEquals(displayName, service.getModuleInfo().getDisplayName()); }
@Test public void testResolve_Version() throws Exception { String version = "1.1"; ServiceInfo info = new ServiceInfo(); ServiceInfo parentInfo = new ServiceInfo(); info.setVersion(version); ServiceModule service = resolveService(info, parentInfo); assertEquals(version, service.getModuleInfo().getVersion()); info.setVersion(null); parentInfo.setVersion(version); service = resolveService(info, parentInfo); assertEquals(version, service.getModuleInfo().getVersion()); info.setVersion(version); parentInfo.setVersion("1.0"); service = resolveService(info, parentInfo); assertEquals(version, service.getModuleInfo().getVersion()); }
@Test public void testResolve_RequiredServices() throws Exception { List<String> requiredServices = new ArrayList<String>(); requiredServices.add("foo"); requiredServices.add("bar"); ServiceInfo info = new ServiceInfo(); ServiceInfo parentInfo = new ServiceInfo(); info.setRequiredServices(requiredServices); ServiceModule service = resolveService(info, parentInfo); assertEquals(requiredServices, service.getModuleInfo().getRequiredServices()); info.setRequiredServices(null); parentInfo.setRequiredServices(requiredServices); service = resolveService(info, parentInfo); assertEquals(requiredServices, service.getModuleInfo().getRequiredServices()); info.setRequiredServices(requiredServices); parentInfo.setRequiredServices(Collections.singletonList("other")); service = resolveService(info, parentInfo); assertEquals(requiredServices, service.getModuleInfo().getRequiredServices()); info.setRequiredServices(null); parentInfo.setRequiredServices(null); service = resolveService(info, parentInfo); assertTrue(service.getModuleInfo().getRequiredServices().isEmpty()); }
@Test public void testResolve_RestartRequiredAfterChange() throws Exception { Boolean isRestartRequired = true; ServiceInfo info = new ServiceInfo(); ServiceInfo parentInfo = new ServiceInfo(); info.setRestartRequiredAfterChange(isRestartRequired); ServiceModule service = resolveService(info, parentInfo); assertEquals(isRestartRequired, service.getModuleInfo().isRestartRequiredAfterChange()); info.setRestartRequiredAfterChange(null); parentInfo.setRestartRequiredAfterChange(isRestartRequired); service = resolveService(info, parentInfo); assertEquals(isRestartRequired, service.getModuleInfo().isRestartRequiredAfterChange()); info.setRestartRequiredAfterChange(isRestartRequired); parentInfo.setRestartRequiredAfterChange(false); service = resolveService(info, parentInfo); assertEquals(isRestartRequired, service.getModuleInfo().isRestartRequiredAfterChange()); }
@Test public void testResolve_MonitoringService() throws Exception { Boolean isMonitoringService = true; ServiceInfo info = new ServiceInfo(); ServiceInfo parentInfo = new ServiceInfo(); info.setMonitoringService(isMonitoringService); ServiceModule service = resolveService(info, parentInfo); assertEquals(isMonitoringService, service.getModuleInfo().isMonitoringService()); info.setMonitoringService(null); parentInfo.setMonitoringService(isMonitoringService); service = resolveService(info, parentInfo); assertEquals(isMonitoringService, service.getModuleInfo().isMonitoringService()); info.setMonitoringService(isMonitoringService); parentInfo.setMonitoringService(false); service = resolveService(info, parentInfo); assertEquals(isMonitoringService, service.getModuleInfo().isMonitoringService()); }
@Test public void testResolve_OsSpecifics() throws Exception { Map<String, ServiceOsSpecific> osSpecifics = new HashMap<String, ServiceOsSpecific>(); osSpecifics.put("foo", new ServiceOsSpecific()); ServiceInfo info = new ServiceInfo(); ServiceInfo parentInfo = new ServiceInfo(); info.setOsSpecifics(osSpecifics); ServiceModule service = resolveService(info, parentInfo); assertEquals(osSpecifics, service.getModuleInfo().getOsSpecifics()); info.setOsSpecifics(null); parentInfo.setOsSpecifics(osSpecifics); service = resolveService(info, parentInfo); assertEquals(osSpecifics, service.getModuleInfo().getOsSpecifics()); Map<String, ServiceOsSpecific> osSpecifics2 = new HashMap<String, ServiceOsSpecific>(); osSpecifics.put("bar", new ServiceOsSpecific()); info.setOsSpecifics(osSpecifics); parentInfo.setOsSpecifics(osSpecifics2); service = resolveService(info, parentInfo); assertEquals(osSpecifics, service.getModuleInfo().getOsSpecifics()); }
@Test public void testResolve_CommandScript() throws Exception { CommandScriptDefinition commandScript = new CommandScriptDefinition(); ServiceInfo info = new ServiceInfo(); ServiceInfo parentInfo = new ServiceInfo(); info.setCommandScript(commandScript); ServiceModule service = resolveService(info, parentInfo); assertEquals(commandScript, service.getModuleInfo().getCommandScript()); info.setCommandScript(null); parentInfo.setCommandScript(commandScript); service = resolveService(info, parentInfo); assertEquals(commandScript, service.getModuleInfo().getCommandScript()); CommandScriptDefinition commandScript2 = new CommandScriptDefinition(); info.setCommandScript(commandScript); parentInfo.setCommandScript(commandScript2); service = resolveService(info, parentInfo); assertEquals(commandScript, service.getModuleInfo().getCommandScript()); }
@Test public void testResolve_ServicePackageFolder() throws Exception { String servicePackageFolder = "packageDir"; ServiceInfo info = new ServiceInfo(); ServiceInfo parentInfo = new ServiceInfo(); ServiceModule child = createServiceModule(info); ServiceModule parent = createServiceModule(parentInfo); assertEquals("packageDir", child.getModuleInfo().getServicePackageFolder()); parent.getModuleInfo().setServicePackageFolder(null); resolveService(child, parent); assertEquals(servicePackageFolder, child.getModuleInfo().getServicePackageFolder()); child = createServiceModule(info); parent = createServiceModule(parentInfo); parent.getModuleInfo().setServicePackageFolder(servicePackageFolder); child.getModuleInfo().setServicePackageFolder(null); resolveService(child, parent); assertEquals(servicePackageFolder, child.getModuleInfo().getServicePackageFolder()); child = createServiceModule(info); parent = createServiceModule(parentInfo); parent.getModuleInfo().setServicePackageFolder("someOtherDir"); child.getModuleInfo().setServicePackageFolder(servicePackageFolder); resolveService(child, parent); assertEquals(servicePackageFolder, child.getModuleInfo().getServicePackageFolder()); }
@Test public void testResolve_MetricsFile() throws Exception { File metricsFile = new File("testMetricsFile"); ServiceInfo info = new ServiceInfo(); ServiceInfo parentInfo = new ServiceInfo(); ServiceModule child = createServiceModule(info); ServiceModule parent = createServiceModule(parentInfo); assertEquals(metricsFile, child.getModuleInfo().getMetricsFile()); parent.getModuleInfo().setMetricsFile(null); resolveService(child, parent); assertEquals(metricsFile, child.getModuleInfo().getMetricsFile()); child = createServiceModule(info); parent = createServiceModule(parentInfo); parent.getModuleInfo().setMetricsFile(metricsFile); child.getModuleInfo().setMetricsFile(null); resolveService(child, parent); assertEquals(metricsFile, child.getModuleInfo().getMetricsFile()); child = createServiceModule(info); parent = createServiceModule(parentInfo); parent.getModuleInfo().setMetricsFile(new File("someOtherDir")); child.getModuleInfo().setMetricsFile(metricsFile); resolveService(child, parent); assertEquals(metricsFile, child.getModuleInfo().getMetricsFile()); }
@Test public void testResolve_AlertsFile() throws Exception { File alertsFile = new File("testAlertsFile"); ServiceInfo info = new ServiceInfo(); ServiceInfo parentInfo = new ServiceInfo(); ServiceModule child = createServiceModule(info); ServiceModule parent = createServiceModule(parentInfo); assertEquals(alertsFile, child.getModuleInfo().getAlertsFile()); parent.getModuleInfo().setAlertsFile(null); resolveService(child, parent); assertEquals(alertsFile, child.getModuleInfo().getAlertsFile()); child = createServiceModule(info); parent = createServiceModule(parentInfo); parent.getModuleInfo().setAlertsFile(alertsFile); child.getModuleInfo().setAlertsFile(null); resolveService(child, parent); assertEquals(alertsFile, child.getModuleInfo().getAlertsFile()); child = createServiceModule(info); parent = createServiceModule(parentInfo); parent.getModuleInfo().setAlertsFile(new File("someOtherDir")); child.getModuleInfo().setAlertsFile(alertsFile); resolveService(child, parent); assertEquals(alertsFile, child.getModuleInfo().getAlertsFile()); }
@Test public void testResolve_KerberosDescriptorFile() throws Exception { File kerberosDescriptorFile = new File("testKerberosDescriptorFile"); ServiceInfo info = new ServiceInfo(); ServiceInfo parentInfo = new ServiceInfo(); ServiceModule child = createServiceModule(info); ServiceModule parent = createServiceModule(parentInfo); assertEquals(kerberosDescriptorFile, child.getModuleInfo().getKerberosDescriptorFile()); parent.getModuleInfo().setKerberosDescriptorFile(null); resolveService(child, parent); assertEquals(kerberosDescriptorFile, child.getModuleInfo().getKerberosDescriptorFile()); child = createServiceModule(info); parent = createServiceModule(parentInfo); parent.getModuleInfo().setKerberosDescriptorFile(kerberosDescriptorFile); child.getModuleInfo().setKerberosDescriptorFile(null); resolveService(child, parent); assertEquals(kerberosDescriptorFile, child.getModuleInfo().getKerberosDescriptorFile()); child = createServiceModule(info); parent = createServiceModule(parentInfo); parent.getModuleInfo().setKerberosDescriptorFile(new File("someOtherDir")); child.getModuleInfo().setKerberosDescriptorFile(kerberosDescriptorFile); resolveService(child, parent); assertEquals(kerberosDescriptorFile, child.getModuleInfo().getKerberosDescriptorFile()); }
@Test public void testResolve_UpgradeCheckDirectory() throws Exception { File checks = new File("checks"); ServiceInfo info = new ServiceInfo(); ServiceInfo parentInfo = new ServiceInfo(); ServiceModule child = createServiceModule(info); ServiceModule parent = createServiceModule(parentInfo); child.getModuleInfo().setChecksFolder(checks); resolveService(child, parent); assertEquals(checks.getPath(), child.getModuleInfo().getChecksFolder().getPath()); child = createServiceModule(info); parent = createServiceModule(parentInfo); parent.getModuleInfo().setChecksFolder(checks); resolveService(child, parent); assertEquals(checks.getPath(), child.getModuleInfo().getChecksFolder().getPath()); info.setChecksFolder(checks); child = createServiceModule(info); child.getModuleInfo().setChecksFolder(checks); parent = createServiceModule(parentInfo); parent.getModuleInfo().setChecksFolder(new File("other")); resolveService(child, parent); assertEquals(checks.getPath(), child.getModuleInfo().getChecksFolder().getPath()); }
@Test public void testResolve_CustomCommands() throws Exception { List<CustomCommandDefinition> customCommands = new ArrayList<CustomCommandDefinition>(); CustomCommandDefinition cmd1 = new CustomCommandDefinition(); setPrivateField(cmd1, "name", "cmd1"); setPrivateField(cmd1, "background", false); CustomCommandDefinition cmd2 = new CustomCommandDefinition(); setPrivateField(cmd2, "name", "cmd2"); customCommands.add(cmd1); customCommands.add(cmd2); ServiceInfo info = new ServiceInfo(); ServiceInfo parentInfo = new ServiceInfo(); info.setCustomCommands(customCommands); ServiceModule service = resolveService(info, parentInfo); assertEquals(customCommands, service.getModuleInfo().getCustomCommands()); info.setCustomCommands(null); parentInfo.setCustomCommands(customCommands); service = resolveService(info, parentInfo); assertEquals(customCommands, service.getModuleInfo().getCustomCommands()); List<CustomCommandDefinition> parentCustomCommands = new ArrayList<CustomCommandDefinition>(); CustomCommandDefinition cmd3 = new CustomCommandDefinition(); setPrivateField(cmd3, "name", "cmd1"); setPrivateField(cmd3, "background", true); CustomCommandDefinition cmd4 = new CustomCommandDefinition(); setPrivateField(cmd4, "name", "cmd4"); parentCustomCommands.add(cmd3); parentCustomCommands.add(cmd4); info.setCustomCommands(customCommands); parentInfo.setCustomCommands(parentCustomCommands); service = resolveService(info, parentInfo); Collection<CustomCommandDefinition> mergedCommands = service.getModuleInfo().getCustomCommands(); assertEquals(3, mergedCommands.size()); assertTrue(mergedCommands.contains(cmd2)); assertTrue(mergedCommands.contains(cmd3)); assertTrue(mergedCommands.contains(cmd4)); info.setCustomCommands(null); parentInfo.setCustomCommands(null); service = resolveService(info, parentInfo); assertTrue(service.getModuleInfo().getCustomCommands().isEmpty()); }
@Test public void testResolve_ConfigDependencies() throws Exception { List<String> configDependencies = new ArrayList<String>(); configDependencies.add("foo"); configDependencies.add("bar"); ServiceInfo info = new ServiceInfo(); ServiceInfo parentInfo = new ServiceInfo(); info.setConfigDependencies(configDependencies); ServiceModule service = resolveService(info, parentInfo); assertEquals(configDependencies, service.getModuleInfo().getConfigDependencies()); info.setConfigDependencies(null); parentInfo.setConfigDependencies(configDependencies); service = resolveService(info, parentInfo); assertEquals(configDependencies, service.getModuleInfo().getConfigDependencies()); List<String> parentCustomCommands = new ArrayList<String>(); parentCustomCommands.add("bar"); parentCustomCommands.add("other"); info.setConfigDependencies(configDependencies); parentInfo.setConfigDependencies(parentCustomCommands); service = resolveService(info, parentInfo); Collection<String> mergedConfigDependencies = service.getModuleInfo().getConfigDependencies(); assertEquals(3, mergedConfigDependencies.size()); assertTrue(mergedConfigDependencies.contains("foo")); assertTrue(mergedConfigDependencies.contains("bar")); assertTrue(mergedConfigDependencies.contains("other")); info.setConfigDependencies(null); parentInfo.setConfigDependencies(null); service = resolveService(info, parentInfo); assertTrue(service.getModuleInfo().getConfigDependencies().isEmpty()); }
@Test public void testResolve_Components() throws Exception { ComponentInfo info1 = new ComponentInfo(); info1.setName("1"); ComponentInfo info2 = new ComponentInfo(); info2.setName("2"); ComponentInfo XX = new ComponentInfo(); XX.setName("XX"); ComponentInfo info3 = new ComponentInfo(); info3.setName("1"); info3.setCardinality("ALL"); info3.setCategory("category"); ComponentInfo info4 = new ComponentInfo(); info4.setName("4"); ComponentInfo info5 = new ComponentInfo(); info5.setName("XX"); info5.setDeleted(true); ServiceInfo info = new ServiceInfo(); ServiceInfo parentInfo = new ServiceInfo(); List<ComponentInfo> childComponents = info.getComponents(); childComponents.add(info3); childComponents.add(info4); childComponents.add(info5); List<ComponentInfo> parentComponents = parentInfo.getComponents(); parentComponents.add(info1); parentComponents.add(info2); ServiceModule child = createServiceModule(info); ServiceModule parent = createServiceModule(parentInfo); resolveService(child, parent); List<ComponentInfo> components = child.getModuleInfo().getComponents(); assertEquals(3, components.size()); Map<String, ComponentInfo> mergedComponents = new HashMap<String, ComponentInfo>(); for (ComponentInfo component : components) { mergedComponents.put(component.getName(), component); } assertTrue(mergedComponents.containsKey("1")); assertTrue(mergedComponents.containsKey("2")); assertTrue(mergedComponents.containsKey("4")); assertEquals("ALL", mergedComponents.get("1").getCardinality()); assertEquals("category", mergedComponents.get("1").getCategory()); }
@Test public void testResolve_Configuration__properties() throws Exception { ServiceInfo info = new ServiceInfo(); ServiceInfo parentInfo = new ServiceInfo(); Collection<PropertyInfo> childFooProperties = new ArrayList<PropertyInfo>(); PropertyInfo childProp1 = new PropertyInfo(); childProp1.setName("childName1"); childProp1.setValue("childVal1"); childFooProperties.add(childProp1); Collection<PropertyInfo> childBarProperties = new ArrayList<PropertyInfo>(); PropertyInfo childProp2 = new PropertyInfo(); childProp2.setName("childName2"); childProp2.setValue("childVal2"); childBarProperties.add(childProp2); Map<String, String> attributes = new HashMap<String, String>(); attributes.put(ConfigurationInfo.Supports.DO_NOT_EXTEND.getXmlAttributeName(), "true"); ConfigurationModule childConfigModule1 = createConfigurationModule("FOO", childFooProperties); ConfigurationModule childConfigModule2 = createConfigurationModule("BAR", childBarProperties, attributes); Collection<ConfigurationModule> childModules = new ArrayList<ConfigurationModule>(); childModules.add(childConfigModule1); childModules.add(childConfigModule2); Collection<PropertyInfo> parentFooProperties = new ArrayList<PropertyInfo>(); PropertyInfo parentProp1 = new PropertyInfo(); parentProp1.setName("parentName1"); parentProp1.setValue("parentVal1"); parentFooProperties.add(parentProp1); PropertyInfo parentProp12 = new PropertyInfo(); parentProp12.setName("childName1"); parentProp12.setValue("parentVal1"); parentFooProperties.add(parentProp12); Collection<PropertyInfo> parentBarProperties = new ArrayList<PropertyInfo>(); PropertyInfo parentProp2 = new PropertyInfo(); parentProp2.setName("parentName2"); parentProp2.setValue("parentVal2"); parentBarProperties.add(parentProp2); Collection<PropertyInfo> parentOtherProperties = new ArrayList<PropertyInfo>(); PropertyInfo parentProp3 = new PropertyInfo(); parentProp3.setName("parentName3"); parentProp3.setValue("parentVal3"); parentOtherProperties.add(parentProp3); ConfigurationModule parentConfigModule1 = createConfigurationModule("FOO", parentFooProperties); ConfigurationModule parentConfigModule2 = createConfigurationModule("BAR", parentBarProperties); ConfigurationModule parentConfigModule3 = createConfigurationModule("OTHER", parentOtherProperties); Collection<ConfigurationModule> parentModules = new ArrayList<ConfigurationModule>(); parentModules.add(parentConfigModule1); parentModules.add(parentConfigModule2); parentModules.add(parentConfigModule3); ServiceModule child = createServiceModule(info, childModules); ServiceModule parent = createServiceModule(parentInfo, parentModules); resolveService(child, parent); List<PropertyInfo> mergedProperties = child.getModuleInfo().getProperties(); assertEquals(4, mergedProperties.size()); Map<String, PropertyInfo> mergedPropertyMap = new HashMap<String, PropertyInfo>(); for (PropertyInfo prop : mergedProperties) { mergedPropertyMap.put(prop.getName(), prop); } assertEquals("childVal1", mergedPropertyMap.get("childName1").getValue()); assertEquals("childVal2", mergedPropertyMap.get("childName2").getValue()); assertEquals("parentVal1", mergedPropertyMap.get("parentName1").getValue()); assertEquals("parentVal3", mergedPropertyMap.get("parentName3").getValue()); Map<String, Map<String, Map<String, String>>> childAttributes = child.getModuleInfo().getConfigTypeAttributes(); Map<String, Map<String, Map<String, String>>> parentAttributes = parent.getModuleInfo().getConfigTypeAttributes(); assertEquals(3, childAttributes.size()); assertAttributes(childAttributes.get("FOO"), Collections.<String, String>emptyMap()); assertAttributes(childAttributes.get("BAR"), attributes); assertAttributes(childAttributes.get("OTHER"), Collections.<String, String>emptyMap()); assertEquals(3, parentAttributes.size()); assertAttributes(parentAttributes.get("FOO"), Collections.<String, String>emptyMap()); assertAttributes(parentAttributes.get("BAR"), Collections.<String, String>emptyMap()); assertAttributes(parentAttributes.get("OTHER"), Collections.<String, String>emptyMap()); }
@Test public void testResolve_Configuration__attributes() throws Exception { ServiceInfo info = new ServiceInfo(); ServiceInfo parentInfo = new ServiceInfo(); Collection<PropertyInfo> childFooProperties = new ArrayList<PropertyInfo>(); PropertyInfo childProp1 = new PropertyInfo(); childProp1.setName("childName1"); childProp1.setValue("childVal1"); childFooProperties.add(childProp1); Map<String, String> childFooAttributes = new HashMap<String, String>(); childFooAttributes.put(ConfigurationInfo.Supports.ADDING_FORBIDDEN.getXmlAttributeName(), "false"); ConfigurationModule childConfigModule1 = createConfigurationModule("FOO", childFooProperties, childFooAttributes); Collection<ConfigurationModule> childModules = new ArrayList<ConfigurationModule>(); childModules.add(childConfigModule1); Collection<PropertyInfo> parentFooProperties = new ArrayList<PropertyInfo>(); PropertyInfo parentProp1 = new PropertyInfo(); parentProp1.setName("parentName1"); parentProp1.setValue("parentVal1"); parentFooProperties.add(parentProp1); Map<String, String> parentFooAttributes = new HashMap<String, String>(); parentFooAttributes.put(ConfigurationInfo.Supports.FINAL.getXmlAttributeName(), "true"); parentFooAttributes.put(ConfigurationInfo.Supports.ADDING_FORBIDDEN.getXmlAttributeName(), "true"); Collection<PropertyInfo> parentBarProperties = new ArrayList<PropertyInfo>(); PropertyInfo parentProp2 = new PropertyInfo(); parentProp2.setName("parentName2"); parentProp2.setValue("parentVal2"); parentBarProperties.add(parentProp2); ConfigurationModule parentConfigModule1 = createConfigurationModule("FOO", parentFooProperties, parentFooAttributes); ConfigurationModule parentConfigModule2 = createConfigurationModule("BAR", parentBarProperties); Collection<ConfigurationModule> parentModules = new ArrayList<ConfigurationModule>(); parentModules.add(parentConfigModule1); parentModules.add(parentConfigModule2); ServiceModule child = createServiceModule(info, childModules); ServiceModule parent = createServiceModule(parentInfo, parentModules); resolveService(child, parent); Map<String, Map<String, Map<String, String>>> childTypeAttributes = child.getModuleInfo().getConfigTypeAttributes(); Map<String, Map<String, Map<String, String>>> parentTypeAttributes = parent.getModuleInfo().getConfigTypeAttributes(); assertTrue(childTypeAttributes.containsKey("FOO")); Map<String, Map<String, String>> mergedChildFooAttributes = childTypeAttributes.get("FOO"); assertTrue(mergedChildFooAttributes.containsKey(ConfigurationInfo.Supports.KEYWORD)); assertEquals("true", mergedChildFooAttributes.get(ConfigurationInfo.Supports.KEYWORD). get(ConfigurationInfo.Supports.valueOf("FINAL").getPropertyName())); assertEquals("false", mergedChildFooAttributes.get(ConfigurationInfo.Supports.KEYWORD). get(ConfigurationInfo.Supports.valueOf("ADDING_FORBIDDEN").getPropertyName())); assertEquals(2, childTypeAttributes.size()); assertEquals(2, parentTypeAttributes.size()); assertAttributes(parentTypeAttributes.get("FOO"), parentFooAttributes); assertAttributes(parentTypeAttributes.get("BAR"), Collections.<String, String>emptyMap()); }
@Test public void testResolve_Configuration__ExcludedTypes() throws Exception { ServiceInfo info = new ServiceInfo(); info.setExcludedConfigTypes(Collections.singleton("BAR")); Collection<PropertyInfo> fooProperties = new ArrayList<PropertyInfo>(); PropertyInfo prop1 = new PropertyInfo(); prop1.setName("name1"); prop1.setValue("val1"); fooProperties.add(prop1); PropertyInfo prop2 = new PropertyInfo(); prop2.setName("name2"); prop2.setValue("val2"); fooProperties.add(prop2); Collection<PropertyInfo> barProperties = new ArrayList<PropertyInfo>(); PropertyInfo prop3 = new PropertyInfo(); prop3.setName("name1"); prop3.setValue("val3"); barProperties.add(prop3); Collection<PropertyInfo> otherProperties = new ArrayList<PropertyInfo>(); PropertyInfo prop4 = new PropertyInfo(); prop4.setName("name1"); prop4.setValue("val4"); otherProperties.add(prop4); ConfigurationModule configModule1 = createConfigurationModule("FOO", fooProperties); ConfigurationModule configModule2 = createConfigurationModule("BAR", barProperties); ConfigurationModule configModule3 = createConfigurationModule("OTHER", otherProperties); Collection<ConfigurationModule> configModules = new ArrayList<ConfigurationModule>(); configModules.add(configModule1); configModules.add(configModule2); configModules.add(configModule3); ServiceModule service = createServiceModule(info, configModules); List<PropertyInfo> properties = service.getModuleInfo().getProperties(); assertEquals(4, properties.size()); Map<String, Map<String, Map<String, String>>> attributes = service.getModuleInfo().getConfigTypeAttributes(); assertEquals(2, attributes.size()); assertTrue(attributes.containsKey("FOO")); assertTrue(attributes.containsKey("OTHER")); }
@Test public void testResolve_Configuration__ExcludedTypes__ParentType() throws Exception { ServiceInfo info = new ServiceInfo(); info.setExcludedConfigTypes(Collections.singleton("BAR")); Collection<PropertyInfo> fooProperties = new ArrayList<PropertyInfo>(); PropertyInfo prop1 = new PropertyInfo(); prop1.setName("name1"); prop1.setValue("val1"); fooProperties.add(prop1); PropertyInfo prop2 = new PropertyInfo(); prop2.setName("name2"); prop2.setValue("val2"); fooProperties.add(prop2); ConfigurationModule childConfigModule = createConfigurationModule("FOO", fooProperties); Collection<ConfigurationModule> childConfigModules = new ArrayList<ConfigurationModule>(); childConfigModules.add(childConfigModule); ServiceInfo parentInfo = new ServiceInfo(); Collection<PropertyInfo> barProperties = new ArrayList<PropertyInfo>(); PropertyInfo prop3 = new PropertyInfo(); prop3.setName("name1"); prop3.setValue("val3"); barProperties.add(prop3); ConfigurationModule parentConfigModule = createConfigurationModule("BAR", barProperties); Collection<ConfigurationModule> parentConfigModules = new ArrayList<ConfigurationModule>(); parentConfigModules.add(parentConfigModule); ServiceModule service = createServiceModule(info, childConfigModules); ServiceModule parentService = createServiceModule(parentInfo, parentConfigModules); resolveService(service, parentService); List<PropertyInfo> properties = service.getModuleInfo().getProperties(); assertEquals(2, properties.size()); Map<String, Map<String, Map<String, String>>> attributes = service.getModuleInfo().getConfigTypeAttributes(); assertEquals(1, attributes.size()); assertTrue(attributes.containsKey("FOO")); Map<String, Map<String, Map<String, String>>> parentAttributes = parentService.getModuleInfo().getConfigTypeAttributes(); assertEquals(1, parentAttributes.size()); assertTrue(parentAttributes.containsKey("BAR")); }
@Test public void testMerge_Configuration__ExcludedTypes() throws Exception { ServiceInfo info = new ServiceInfo(); Set<String> childExcludedConfigTypes = new HashSet<String>(); childExcludedConfigTypes.add("FOO"); info.setExcludedConfigTypes(childExcludedConfigTypes); Collection<PropertyInfo> fooProperties = new ArrayList<PropertyInfo>(); ConfigurationModule childConfigModule = createConfigurationModule("FOO", fooProperties); Collection<ConfigurationModule> childConfigModules = new ArrayList<ConfigurationModule>(); childConfigModules.add(childConfigModule); ServiceInfo parentInfo = new ServiceInfo(); Set<String> parentExcludedConfigTypes = new HashSet<String>(); childExcludedConfigTypes.add("BAR"); info.setExcludedConfigTypes(childExcludedConfigTypes); parentInfo.setExcludedConfigTypes(parentExcludedConfigTypes); Collection<PropertyInfo> barProperties = new ArrayList<PropertyInfo>(); ConfigurationModule parentConfigModule = createConfigurationModule("BAR", barProperties); Collection<ConfigurationModule> parentConfigModules = new ArrayList<ConfigurationModule>(); parentConfigModules.add(parentConfigModule); ServiceModule service = createServiceModule(info, childConfigModules); ServiceModule parentService = createServiceModule(parentInfo, parentConfigModules); resolveService(service, parentService); assertEquals(2, service.getModuleInfo().getExcludedConfigTypes().size()); }
@Test public void testResolve_CredentialStoreInfo() throws Exception { CredentialStoreInfo credentialStoreInfoChild = new CredentialStoreInfo(true , false , true ); CredentialStoreInfo credentialStoreInfoParent = new CredentialStoreInfo(true , true , false ); ServiceInfo childInfo = new ServiceInfo(); ServiceInfo parentInfo = new ServiceInfo(); ServiceModule service; childInfo.setCredentialStoreInfo(credentialStoreInfoChild); parentInfo.setCredentialStoreInfo(null); service = resolveService(childInfo, parentInfo); assertEquals(credentialStoreInfoChild.isSupported(), service.getModuleInfo().isCredentialStoreSupported()); assertEquals(credentialStoreInfoChild.isEnabled(), service.getModuleInfo().isCredentialStoreEnabled()); assertEquals(credentialStoreInfoChild.isRequired(), service.getModuleInfo().isCredentialStoreRequired()); childInfo.setCredentialStoreInfo(null); parentInfo.setCredentialStoreInfo(credentialStoreInfoParent); service = resolveService(childInfo, parentInfo); assertEquals(credentialStoreInfoParent.isSupported(), service.getModuleInfo().isCredentialStoreSupported()); assertEquals(credentialStoreInfoParent.isEnabled(), service.getModuleInfo().isCredentialStoreEnabled()); assertEquals(credentialStoreInfoParent.isRequired(), service.getModuleInfo().isCredentialStoreRequired()); childInfo.setCredentialStoreInfo(credentialStoreInfoChild); parentInfo.setCredentialStoreInfo(credentialStoreInfoParent); service = resolveService(childInfo, parentInfo); assertEquals(credentialStoreInfoChild.isSupported(), service.getModuleInfo().isCredentialStoreSupported()); assertEquals(credentialStoreInfoChild.isEnabled(), service.getModuleInfo().isCredentialStoreEnabled()); assertEquals(credentialStoreInfoChild.isRequired(), service.getModuleInfo().isCredentialStoreRequired()); }
@Test public void testMergeServicePropertiesInheritFromParent() throws Exception { ServiceInfo serviceInfo = new ServiceInfo(); ServiceInfo parentServiceInfo = new ServiceInfo(); ServicePropertyInfo p1 = new ServicePropertyInfo(); p1.setName("P1"); p1.setValue("V1"); ServicePropertyInfo p2 = new ServicePropertyInfo(); p2.setName("P2"); p2.setValue("V2"); List<ServicePropertyInfo> parentServicePropertyList = Lists.newArrayList(p1, p2); parentServiceInfo.setServicePropertyList(parentServicePropertyList); ServiceModule serviceModule = resolveService(serviceInfo, parentServiceInfo); Map<String, String> parentServiceProperties = ImmutableMap.<String, String>builder() .put("P1", "V1") .put("P2", "V2") .put(ServiceInfo.DEFAULT_SERVICE_INSTALLABLE_PROPERTY) .put(ServiceInfo.DEFAULT_SERVICE_MANAGED_PROPERTY) .put(ServiceInfo.DEFAULT_SERVICE_MONITORED_PROPERTY) .build(); assertEquals(parentServicePropertyList, serviceModule.getModuleInfo().getServicePropertyList()); assertEquals(parentServiceProperties, serviceModule.getModuleInfo().getServiceProperties()); }
@Test public void testMergeServicePropertiesInheritFromEmptyParent() throws Exception { ServiceInfo serviceInfo = new ServiceInfo(); ServiceInfo parentServiceInfo = new ServiceInfo(); ServicePropertyInfo p1 = new ServicePropertyInfo(); p1.setName("P1"); p1.setValue("V1"); ServicePropertyInfo p2 = new ServicePropertyInfo(); p2.setName("P2"); p2.setValue("V2"); List<ServicePropertyInfo> servicePropertyList = Lists.newArrayList(p1, p2); serviceInfo.setServicePropertyList(servicePropertyList); ServiceModule serviceModule = resolveService(serviceInfo, parentServiceInfo); Map<String, String> serviceProperties = ImmutableMap.<String, String>builder() .put("P1", "V1") .put("P2", "V2") .put(ServiceInfo.DEFAULT_SERVICE_INSTALLABLE_PROPERTY) .put(ServiceInfo.DEFAULT_SERVICE_MANAGED_PROPERTY) .put(ServiceInfo.DEFAULT_SERVICE_MONITORED_PROPERTY) .build(); assertEquals(servicePropertyList, serviceModule.getModuleInfo().getServicePropertyList()); assertEquals(serviceProperties, serviceModule.getModuleInfo().getServiceProperties()); }