Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/173#discussion_r65532271
  
    --- Diff: 
camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigInheritanceYamlTest.java
 ---
    @@ -300,14 +338,212 @@ public void testOverridesParentConfig() throws 
Exception {
                     ImmutableMap.of("mykey2", "myval2", "templateOptions", 
ImmutableMap.of("myOptionsKey2", "myOptionsVal2")));
         }
         
    +    @Test
    +    public void testEntityTypeInheritanceOptions() throws Exception {
    +        addCatalogItems(
    +                "brooklyn.catalog:",
    +                "  itemType: entity",
    +                "  items:",
    +                "  - id: entity-with-keys",
    +                "    item:",
    +                "      type: 
org.apache.brooklyn.core.test.entity.TestEntity",
    +                "      brooklyn.parameters:",
    +                "      - name: map.type-merged",
    +                "        type: java.util.Map",
    +                "        inheritance.type: merge",
    +                "        default: {myDefaultKey: myDefaultVal}",
    +                "      - name: map.type-always",
    +                "        type: java.util.Map",
    +                "        inheritance.type: always",
    +                "        default: {myDefaultKey: myDefaultVal}",
    +                "      - name: map.type-never",
    +                "        type: java.util.Map",
    +                "        inheritance.type: none",
    +                "        default: {myDefaultKey: myDefaultVal}",
    +                "  - id: entity-with-conf",
    +                "    item:",
    +                "      type: entity-with-keys",
    +                "      brooklyn.config:",
    +                "        map.type-merged:",
    +                "          mykey: myval",
    +                "        map.type-always:",
    +                "          mykey: myval",
    +                "        map.type-never:",
    +                "          mykey: myval");
    +        
    +        // Test retrieval of defaults
    +        {
    +            String yaml = Joiner.on("\n").join(
    +                    "services:",
    +                    "- type: entity-with-keys");
    +            
    +            Entity app = createStartWaitAndLogApplication(new 
StringReader(yaml));
    +            TestEntity entity = (TestEntity) 
Iterables.getOnlyElement(app.getChildren());
    +    
    +            
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-merged")),
 ImmutableMap.of("myDefaultKey", "myDefaultVal"));
    +            
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-always")),
 ImmutableMap.of("myDefaultKey", "myDefaultVal"));
    +            
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-never")),
 ImmutableMap.of("myDefaultKey", "myDefaultVal"));
    +        }
    +
    +        // Test override defaults
    +        {
    +            String yaml = Joiner.on("\n").join(
    +                    "services:",
    +                    "- type: entity-with-keys",
    +                    "  brooklyn.config:",
    +                    "    map.type-merged:",
    +                    "      mykey2: myval2",
    +                    "    map.type-always:",
    +                    "      mykey2: myval2",
    +                    "    map.type-never:",
    +                    "      mykey2: myval2");
    +            
    +            Entity app = createStartWaitAndLogApplication(new 
StringReader(yaml));
    +            TestEntity entity = (TestEntity) 
Iterables.getOnlyElement(app.getChildren());
    +    
    +            
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-merged")),
 ImmutableMap.of("mykey2", "myval2"));
    +            
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-always")),
 ImmutableMap.of("mykey2", "myval2"));
    +            
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-never")),
 ImmutableMap.of("mykey2", "myval2"));
    +        }
    +
    +        // Test retrieval of explicit config
    +        // TODO what should "never" mean here? Should we get the default 
value?
    +        {
    +            String yaml = Joiner.on("\n").join(
    +                    "services:",
    +                    "- type: entity-with-conf");
    +            
    +            Entity app = createStartWaitAndLogApplication(new 
StringReader(yaml));
    +            TestEntity entity = (TestEntity) 
Iterables.getOnlyElement(app.getChildren());
    +    
    +            
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-merged")),
 ImmutableMap.of("mykey", "myval"));
    +            
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-always")),
 ImmutableMap.of("mykey", "myval"));
    +            
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-never")),
 ImmutableMap.of("myDefaultKey", "myDefaultVal"));
    +        }
    +        
    +        // Test merging/overriding of explicit config
    +        {
    +            String yaml = Joiner.on("\n").join(
    +                    "services:",
    +                    "- type: entity-with-conf",
    +                    "  brooklyn.config:",
    +                    "    map.type-merged:",
    +                    "      mykey2: myval2",
    +                    "    map.type-always:",
    +                    "      mykey2: myval2",
    +                    "    map.type-never:",
    +                    "      mykey2: myval2");
    +            
    +            Entity app = createStartWaitAndLogApplication(new 
StringReader(yaml));
    +            TestEntity entity = (TestEntity) 
Iterables.getOnlyElement(app.getChildren());
    +    
    +            
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-merged")),
 ImmutableMap.of("mykey", "myval", "mykey2", "myval2"));
    +            
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-always")),
 ImmutableMap.of("mykey2", "myval2"));
    +            
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-never")),
 ImmutableMap.of("mykey2", "myval2"));
    +        }
    +    }
    +    
    +    @Test
    +    public void testParentInheritanceOptions() throws Exception {
    +        addCatalogItems(
    +                "brooklyn.catalog:",
    +                "  itemType: entity",
    +                "  items:",
    +                "  - id: entity-with-keys",
    +                "    item:",
    +                "      type: 
org.apache.brooklyn.core.test.entity.TestEntity",
    +                "      brooklyn.parameters:",
    +                "      - name: map.type-merged",
    +                "        type: java.util.Map",
    +                "        inheritance.parent: merge",
    +                "        default: {myDefaultKey: myDefaultVal}",
    +                "      - name: map.type-always",
    +                "        type: java.util.Map",
    +                "        inheritance.parent: always",
    +                "        default: {myDefaultKey: myDefaultVal}",
    +                "      - name: map.type-never",
    +                "        type: java.util.Map",
    +                "        inheritance.parent: none",
    +                "        default: {myDefaultKey: myDefaultVal}");
    +        
    +        // Test retrieval of defaults
    +        {
    +            String yaml = Joiner.on("\n").join(
    +                    "services:",
    +                    "- type: 
org.apache.brooklyn.entity.stock.BasicApplication",
    +                    "  brooklyn.children:",
    +                    "  - type: entity-with-keys");
    +            
    +            Entity app = createStartWaitAndLogApplication(new 
StringReader(yaml));
    +            TestEntity entity = (TestEntity) 
Iterables.getOnlyElement(app.getChildren());
    +    
    +            
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-merged")),
 ImmutableMap.of("myDefaultKey", "myDefaultVal"));
    +            
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-always")),
 ImmutableMap.of("myDefaultKey", "myDefaultVal"));
    +            
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-never")),
 ImmutableMap.of("myDefaultKey", "myDefaultVal"));
    +        }
    +
    +        // Test override defaults in parent entity
    +        {
    +            String yaml = Joiner.on("\n").join(
    +                    "services:",
    +                    "- type: 
org.apache.brooklyn.entity.stock.BasicApplication",
    +                    "  brooklyn.config:",
    +                    "    map.type-merged:",
    +                    "      mykey: myval",
    +                    "    map.type-always:",
    +                    "      mykey: myval",
    +                    "    map.type-never:",
    +                    "      mykey: myval",
    +                    "  brooklyn.children:",
    +                    "  - type: entity-with-keys");
    +            
    +            Entity app = createStartWaitAndLogApplication(new 
StringReader(yaml));
    +            TestEntity entity = (TestEntity) 
Iterables.getOnlyElement(app.getChildren());
    +    
    +            
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-merged")),
 ImmutableMap.of("mykey", "myval"));
    +            
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-always")),
 ImmutableMap.of("mykey", "myval"));
    +            
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-never")),
 ImmutableMap.of("myDefaultKey", "myDefaultVal"));
    +        }
    +
    +        // Test merging/overriding of explicit config
    +        {
    +            String yaml = Joiner.on("\n").join(
    +                    "services:",
    +                    "- type: 
org.apache.brooklyn.entity.stock.BasicApplication",
    +                    "  brooklyn.config:",
    +                    "    map.type-merged:",
    +                    "      mykey: myval",
    +                    "    map.type-always:",
    +                    "      mykey: myval",
    +                    "    map.type-never:",
    +                    "      mykey: myval",
    +                    "  brooklyn.children:",
    +                    "  - type: entity-with-keys",
    +                    "    brooklyn.config:",
    +                    "      map.type-merged:",
    +                    "        mykey2: myval2",
    +                    "      map.type-always:",
    +                    "        mykey2: myval2",
    +                    "      map.type-never:",
    +                    "        mykey2: myval2");
    --- End diff --
    
    How would inheritance work if there are three levels involved? What if they 
don't have `brooklyn.parameters` declared at each level?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to