Пример #1
0
 /**
  * Merge excluded configs types with parent. Child values override parent values.
  *
  * @param parent parent service module
  */
 private void mergeExcludedConfigTypes(ServiceInfo parent) {
   if (serviceInfo.getExcludedConfigTypes() == null) {
     serviceInfo.setExcludedConfigTypes(parent.getExcludedConfigTypes());
   } else if (parent.getExcludedConfigTypes() != null) {
     Set<String> resultExcludedConfigTypes = serviceInfo.getExcludedConfigTypes();
     for (String excludedType : parent.getExcludedConfigTypes()) {
       if (!resultExcludedConfigTypes.contains(excludedType)) {
         resultExcludedConfigTypes.add(excludedType);
       }
     }
     serviceInfo.setExcludedConfigTypes(resultExcludedConfigTypes);
   }
 }
Пример #2
0
  @Test
  public void testResolve_Configuration__ExcludedTypes__ParentType() throws Exception {
    // child
    ServiceInfo info = new ServiceInfo();
    info.setExcludedConfigTypes(Collections.singleton("BAR"));

    // FOO
    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);

    // parent
    ServiceInfo parentInfo = new ServiceInfo();

    // BAR
    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);

    // create service modules
    ServiceModule service = createServiceModule(info, childConfigModules);
    ServiceModule parentService = createServiceModule(parentInfo, parentConfigModules);
    // resolve child with parent
    resolveService(service, parentService);
    // assertions
    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"));
  }
Пример #3
0
  @Test
  public void testMerge_Configuration__ExcludedTypes() throws Exception {
    // child
    ServiceInfo info = new ServiceInfo();
    Set<String> childExcludedConfigTypes = new HashSet<String>();
    childExcludedConfigTypes.add("FOO");
    info.setExcludedConfigTypes(childExcludedConfigTypes);

    // FOO
    Collection<PropertyInfo> fooProperties = new ArrayList<PropertyInfo>();

    ConfigurationModule childConfigModule = createConfigurationModule("FOO", fooProperties);
    Collection<ConfigurationModule> childConfigModules = new ArrayList<ConfigurationModule>();
    childConfigModules.add(childConfigModule);

    // parent
    ServiceInfo parentInfo = new ServiceInfo();
    Set<String> parentExcludedConfigTypes = new HashSet<String>();
    childExcludedConfigTypes.add("BAR");
    info.setExcludedConfigTypes(childExcludedConfigTypes);
    parentInfo.setExcludedConfigTypes(parentExcludedConfigTypes);
    // BAR
    Collection<PropertyInfo> barProperties = new ArrayList<PropertyInfo>();

    ConfigurationModule parentConfigModule = createConfigurationModule("BAR", barProperties);
    Collection<ConfigurationModule> parentConfigModules = new ArrayList<ConfigurationModule>();
    parentConfigModules.add(parentConfigModule);

    // create service modules
    ServiceModule service = createServiceModule(info, childConfigModules);
    ServiceModule parentService = createServiceModule(parentInfo, parentConfigModules);
    // resolve child with parent

    resolveService(service, parentService);

    // resolveService(service, parentService);
    assertEquals(2, service.getModuleInfo().getExcludedConfigTypes().size());
  }
Пример #4
0
  @Test
  public void testResolve_Configuration__ExcludedTypes() throws Exception {
    ServiceInfo info = new ServiceInfo();
    info.setExcludedConfigTypes(Collections.singleton("BAR"));

    // FOO
    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);

    // BAR
    Collection<PropertyInfo> barProperties = new ArrayList<PropertyInfo>();
    PropertyInfo prop3 = new PropertyInfo();
    prop3.setName("name1");
    prop3.setValue("val3");
    barProperties.add(prop3);

    // OTHER
    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"));
  }