brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [1/5] brooklyn-server git commit: Add more DSL tests
Date Tue, 08 Nov 2016 20:58:37 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master e56de02d2 -> 63cb4c54b


Add more DSL tests

Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/5399a3b8
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/5399a3b8
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/5399a3b8

Branch: refs/heads/master
Commit: 5399a3b86005a76e6d5702a5dc02abca0202930f
Parents: a5b34a7
Author: Aled Sage <aled.sage@gmail.com>
Authored: Tue Nov 8 15:32:06 2016 +0000
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Tue Nov 8 15:35:08 2016 +0000

----------------------------------------------------------------------
 .../camp/brooklyn/DslAndRebindYamlTest.java     | 15 ++++++++++
 .../brooklyn/camp/brooklyn/dsl/DslTest.java     | 31 ++++++++++++++++++++
 2 files changed, 46 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5399a3b8/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/DslAndRebindYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/DslAndRebindYamlTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/DslAndRebindYamlTest.java
index 64362d2..16ff411 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/DslAndRebindYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/DslAndRebindYamlTest.java
@@ -417,6 +417,21 @@ public class DslAndRebindYamlTest extends AbstractYamlRebindTest {
                 "    test.confName: $brooklyn:formatString(\"hello %s\", \"world\")");
     }
 
+    @Test
+    public void testDslFormatStringWithDeferredSupplier() throws Exception {
+        Entity testEntity = setupAndCheckTestEntityInBasicYamlWith(
+                "  brooklyn.config:",
+                "    test.confObject: world",
+                "    test.confName:",
+                "      $brooklyn:formatString:",
+                "      - \"hello %s\"",
+                "      - $brooklyn:config(\"test.confObject\")");
+        Assert.assertEquals(getConfigInTask(testEntity, TestEntity.CONF_NAME), "hello world");
+        
+        Entity e2 = rebind(testEntity);
+        Assert.assertEquals(getConfigInTask(e2, TestEntity.CONF_NAME), "hello world");
+    }
+
     /*
         - type: org.apache.brooklyn.enricher.stock.Transformer
           brooklyn.config:

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5399a3b8/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/dsl/DslTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/dsl/DslTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/dsl/DslTest.java
index b4ff405..1d9c4ae 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/dsl/DslTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/dsl/DslTest.java
@@ -21,6 +21,7 @@ import static org.testng.Assert.assertTrue;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.NoSuchElementException;
 import java.util.Random;
 import java.util.concurrent.Callable;
 import java.util.concurrent.Executors;
@@ -30,6 +31,7 @@ import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.mgmt.Task;
 import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.camp.brooklyn.BrooklynCampConstants;
 import org.apache.brooklyn.camp.brooklyn.spi.dsl.BrooklynDslDeferredSupplier;
 import org.apache.brooklyn.camp.brooklyn.spi.dsl.methods.BrooklynDslCommon;
 import org.apache.brooklyn.config.ConfigKey;
@@ -58,6 +60,13 @@ import com.google.common.util.concurrent.ListenableScheduledFuture;
 import com.google.common.util.concurrent.ListeningScheduledExecutorService;
 import com.google.common.util.concurrent.MoreExecutors;
 
+/**
+ * Also see org.apache.brooklyn.camp.brooklyn.DslAndRebindYamlTest for pure-yaml tests.
+ * 
+ * The purpose of this class is to test at the java-api level, giving more control for
+ * repeated assertions etc (e.g. concurrent calls, looping round to create entities
+ * repeatedly, etc).
+ */
 public class DslTest extends BrooklynAppUnitTestSupport {
 
     private static final int MAX_PARALLEL_RESOLVERS = 50;
@@ -238,6 +247,28 @@ public class DslTest extends BrooklynAppUnitTestSupport {
         });
     }
 
+    @Test
+    public void testEntity() throws Exception {
+        TestEntity entity = app.addChild(EntitySpec.create(TestEntity.class).configure(BrooklynCampConstants.PLAN_ID,
"myId"));
+        BrooklynDslDeferredSupplier<?> dsl = BrooklynDslCommon.entity("myId");
+        Maybe<?> actualValue = execDslImmediately(dsl, Entity.class, app, true);
+        assertEquals(actualValue.get(), entity);
+    }
+
+    @Test
+    public void testEntityNotFound() throws Exception {
+        BrooklynDslDeferredSupplier<?> dsl = BrooklynDslCommon.entity("myIdDoesNotExist");
+        try {
+            Maybe<?> actualValue = execDslImmediately(dsl, Entity.class, app, true);
+            Asserts.shouldHaveFailedPreviously("actual="+actualValue);
+        } catch (Exception e) {
+            NoSuchElementException nsee = Exceptions.getFirstThrowableOfType(e, NoSuchElementException.class);
+            if (nsee == null) {
+                throw e;
+            }
+        }
+    }
+
     protected void runConcurrentWorker(Supplier<Runnable> taskSupplier) {
         Collection<Task<?>> results = new ArrayList<>();
         for (int i = 0; i < MAX_PARALLEL_RESOLVERS; i++) {


Mime
View raw message