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

    https://github.com/apache/incubator-brooklyn/pull/141#discussion_r17052735
  
    --- Diff: core/src/test/java/brooklyn/util/text/TemplateProcessorTest.java 
---
    @@ -58,36 +85,48 @@ public void testEntityGetterMethod() {
         }
         
         @Test
    -    public void testEntityConfig() {
    -        TestEntity entity = 
app.createAndManageChild(EntitySpec.create(TestEntity.class)
    -                .configure(TestEntity.CONF_NAME, "myval"));
    -        String templateContents = 
"${config['"+TestEntity.CONF_NAME.getName()+"']}";
    -        String result = 
TemplateProcessor.processTemplateContents(templateContents, entity, 
ImmutableMap.<String,Object>of());
    -        assertEquals(result, "myval");
    -    }
    -    
    -    // TODO Should this be under a sub-map (e.g. globalConfig or some 
such)?
    -    @Test
         public void testManagementContextConfig() {
             mgmt.getBrooklynProperties().put("globalmykey", "myval");
    -        String templateContents = "${globalmykey}";
    +        String templateContents = "${mgmt.globalmykey}";
             String result = 
TemplateProcessor.processTemplateContents(templateContents, app, 
ImmutableMap.<String,Object>of());
             assertEquals(result, "myval");
         }
         
    -    // FIXME Fails because tries to get global, and then call getMyKey() 
    -    @Test(groups="WIP")
    +    @Test
         public void testManagementContextConfigWithDot() {
             mgmt.getBrooklynProperties().put("global.mykey", "myval");
    -        String templateContents = "${global.mykey}";
    +        String templateContents = "${mgmt['global.mykey']}";
             String result = 
TemplateProcessor.processTemplateContents(templateContents, app, 
ImmutableMap.<String,Object>of());
             assertEquals(result, "myval");
         }
         
    -    // FIXME Fails because does not respect attributeWhenReady; just 
returns its toString
    -    // to fix this, we need to intercept lookups in the template processor 
    -    // should be possible by passing a custom TemplateHashModel in to the 
template processor instead of our substitution map
    -    @Test(groups="WIP")
    +    @Test
    +    public void testManagementContextDefaultValue() {
    +        String templateContents = "${(missing)!\"defval\"}";
    +        Object result = 
TemplateProcessor.processTemplateContents(templateContents, app, 
ImmutableMap.<String,Object>of());
    +        assertEquals(result, "defval");
    +    }
    +    
    +    @Test
    +    public void testManagementContextDefaultValueInDotMissingValue() {
    +        String templateContents = 
"${(mgmt.missing.more_missing)!\"defval\"}";
    +        Object result = 
TemplateProcessor.processTemplateContents(templateContents, app, 
ImmutableMap.<String,Object>of());
    +        assertEquals(result, "defval");
    +    }
    +    
    +    @Test
    +    public void testManagementContextErrors() {
    +        try {
    +            // NB: dot has special meaning so this should fail
    +            mgmt.getBrooklynProperties().put("global.mykey", "myval");
    +            String templateContents = "${mgmt.global.mykey}";
    +            TemplateProcessor.processTemplateContents(templateContents, 
app, ImmutableMap.<String,Object>of());
    +            Assert.fail("Should not have found value with intermediate 
dot");
    +        } catch (Exception e) {
    +            Assert.assertTrue(e.toString().contains("global"), "Should 
have mentioned missing key 'global' in error");
    +        }
    +    }
    +    
         public void testApplyTemplatedConfigWithAttributeWhenReady() {
    --- End diff --
    
    This test doesn't have an `@Test` annotation.


---
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