|
22 | 22 | import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry.RegisteredTypeKind; |
23 | 23 | import org.apache.brooklyn.api.typereg.RegisteredType; |
24 | 24 | import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest; |
| 25 | +import org.apache.brooklyn.camp.yoml.types.YomlInitializers; |
25 | 26 | import org.apache.brooklyn.core.config.ConfigKeys; |
| 27 | +import org.apache.brooklyn.core.entity.EntityAsserts; |
| 28 | +import org.apache.brooklyn.core.entity.EntityInternal; |
26 | 29 | import org.apache.brooklyn.core.sensor.Sensors; |
27 | 30 | import org.apache.brooklyn.core.typereg.BasicBrooklynTypeRegistry; |
| 31 | +import org.apache.brooklyn.test.Asserts; |
| 32 | +import org.apache.brooklyn.util.guava.Maybe; |
| 33 | +import org.apache.brooklyn.util.time.Duration; |
| 34 | +import org.apache.brooklyn.util.time.Time; |
28 | 35 | import org.apache.brooklyn.util.yoml.annotations.YomlAllFieldsTopLevel; |
29 | 36 | import org.slf4j.Logger; |
30 | 37 | import org.slf4j.LoggerFactory; |
31 | 38 | import org.testng.Assert; |
32 | 39 | import org.testng.annotations.Test; |
33 | 40 |
|
34 | 41 | import com.google.api.client.repackaged.com.google.common.base.Joiner; |
| 42 | +import com.google.common.base.Supplier; |
35 | 43 | import com.google.common.collect.Iterables; |
36 | 44 |
|
37 | 45 | public class BrooklynDslInYomlStringPlanTest extends AbstractYamlTest { |
@@ -73,14 +81,43 @@ public void testYomlParserRespectsDsl() throws Exception { |
73 | 81 | "- type: org.apache.brooklyn.core.test.entity.TestEntity", |
74 | 82 | " brooklyn.config:", |
75 | 83 | " test.obj:", |
| 84 | + // with this, the yoml is resolved at retrieval time |
76 | 85 | " $brooklyn:object-yoml: item-w-dsl"); |
77 | 86 |
|
78 | 87 | Entity app = createStartWaitAndLogApplication(yaml); |
79 | 88 | Entity entity = Iterables.getOnlyElement( app.getChildren() ); |
80 | 89 |
|
81 | 90 | entity.sensors().set(Sensors.newStringSensor("test.sensor"), "bob"); |
| 91 | + Maybe<Object> raw = ((EntityInternal)entity).config().getRaw(ConfigKeys.newConfigKey(Object.class, "test.obj")); |
| 92 | + Asserts.assertPresent(raw); |
| 93 | + Asserts.assertInstanceOf(raw.get(), Supplier.class); |
82 | 94 | Object obj = entity.config().get(ConfigKeys.newConfigKey(Object.class, "test.obj")); |
83 | 95 | Assert.assertEquals(((ItemA)obj).name, "bob"); |
84 | 96 | } |
85 | 97 |
|
| 98 | + @Test |
| 99 | + public void testYomlDefersDslEvaluationForConfig() throws Exception { |
| 100 | + add(SAMPLE_TYPE_BASE); |
| 101 | + add(SAMPLE_TYPE_TEST); |
| 102 | + YomlInitializers.install(mgmt()); |
| 103 | + |
| 104 | + String yaml = Joiner.on("\n").join( |
| 105 | + "services:", |
| 106 | + "- type: org.apache.brooklyn.core.test.entity.TestEntity", |
| 107 | + " brooklyn.initializers:", |
| 108 | + " a-sensor:", |
| 109 | + " type: static-sensor", |
| 110 | + " value: '$brooklyn:self().attributeWhenReady(\"test.sensor\")'", |
| 111 | + " period: 100ms"); |
| 112 | + |
| 113 | + Entity app = createStartWaitAndLogApplication(yaml); |
| 114 | + Entity entity = Iterables.getOnlyElement( app.getChildren() ); |
| 115 | + |
| 116 | + entity.sensors().set(Sensors.newStringSensor("test.sensor"), "bob"); |
| 117 | +// EntityAsserts.assertAttributeEqualsEventually(entity, attribute, expected); |
| 118 | + System.out.println(entity.getAttribute(Sensors.newStringSensor("a-sensor"))); |
| 119 | + Time.sleep(Duration.ONE_SECOND); |
| 120 | + System.out.println(entity.getAttribute(Sensors.newStringSensor("a-sensor"))); |
| 121 | + } |
| 122 | + |
86 | 123 | } |
0 commit comments