brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aledsage <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #855: [BROOKLYN-542] add test for freemarker bu...
Date Fri, 06 Oct 2017 13:16:51 GMT
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/855#discussion_r143186317
  
    --- Diff: core/src/test/java/org/apache/brooklyn/util/core/text/TemplateProcessorTest.java
---
    @@ -247,4 +251,40 @@ public void testDotSeparatedKeyCollisionFailure() {
             }
         }
     
    +    @Test
    +    public void testBuiltInsForLists() {
    +        AttributeSensor<List> sensor1 = Sensors.newSensor(List.class, "list");
    +        TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
    +        entity.sensors().set(sensor1, ImmutableList.of("first", "second"));
    +        String templateContents = Joiner.on("\n").join(
    +                "<#list attribute['list'] as l>", 
    +                "${l}", 
    +                "</#list>");
    +        String result = TemplateProcessor.processTemplateContents(templateContents, entity,
ImmutableMap.<String,Object>of());
    +        assertEquals(result.trim(), "first\nsecond");
    +    }
    +
    +    /** 
    +     * Based on http://freemarker.org/docs/ref_builtins_hash.html
    +     */
    +    @Test
    +    public void testBuiltInsForHashes() {
    +        AttributeSensor<Map> sensor1 = Sensors.newSensor(Map.class, "map");
    +        TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
    +        entity.sensors().set(sensor1, ImmutableMap.of("name", "mouse", "price", 50));
    +        String keys = Joiner.on("\n").join(
    +                "<#list attribute['map']?keys as k>",
    +                "${k}",
    +                "</#list>");
    +        String resultForKeys = TemplateProcessor.processTemplateContents(keys, entity,
ImmutableMap.of());
    +        assertEquals(resultForKeys.trim(), "name\nprice");
    +
    +        String values = Joiner.on("\n").join(
    +                "<#list attribute['map']?keys as k>",
    --- End diff --
    
    I think this should say `?values...`


---

Mime
View raw message