brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [1/5] brooklyn-server git commit: CompositeEffector: improve test coverage
Date Fri, 28 Apr 2017 16:32:30 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master f4999be95 -> 259d88e6f


CompositeEffector: improve test coverage

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

Branch: refs/heads/master
Commit: e33140ecbe7482332d6b70998782a4c444a8a5b3
Parents: 3ac709b
Author: Aled Sage <aled.sage@gmail.com>
Authored: Thu Apr 27 13:45:41 2017 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Thu Apr 27 13:46:43 2017 +0100

----------------------------------------------------------------------
 .../CompositeEffectorYamlRebindTest.java        | 26 +++++++++++++-------
 .../brooklyn/core/test/entity/TestEntity.java   |  2 ++
 .../core/test/entity/TestEntityImpl.java        |  5 ++++
 3 files changed, 24 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e33140ec/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CompositeEffectorYamlRebindTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CompositeEffectorYamlRebindTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CompositeEffectorYamlRebindTest.java
index 1f33c78..16e2052 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CompositeEffectorYamlRebindTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CompositeEffectorYamlRebindTest.java
@@ -21,8 +21,6 @@ package org.apache.brooklyn.camp.brooklyn;
 import static org.apache.brooklyn.test.Asserts.assertFalse;
 import static org.testng.Assert.assertEquals;
 
-import java.util.List;
-
 import org.apache.brooklyn.api.effector.Effector;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.core.effector.CompositeEffector;
@@ -32,12 +30,14 @@ import org.apache.brooklyn.core.entity.EntityPredicates;
 import org.apache.brooklyn.core.entity.StartableApplication;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.test.http.TestHttpServer;
+import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.guava.Maybe;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterables;
 
@@ -59,7 +59,7 @@ public class CompositeEffectorYamlRebindTest extends AbstractYamlRebindTest
{
            "    brooklyn.initializers:",
            "    - type: " + HttpCommandEffector.class.getName(),
            "      brooklyn.config:",
-           "        name: myEffector",
+           "        name: httpEffector",
            "        description: myDescription",
            "        uri: ${serverUrl}/get?id=myId",
            "        httpVerb: GET",
@@ -70,6 +70,7 @@ public class CompositeEffectorYamlRebindTest extends AbstractYamlRebindTest
{
            "        name: start",
            "        override: true",
            "        effectors:",
+           "        - httpEffector",
            "        - myEffector"
    );
 
@@ -103,16 +104,23 @@ public class CompositeEffectorYamlRebindTest extends AbstractYamlRebindTest
{
       String appYaml = Joiner.on("\n").join(
               "services: ",
               "- type: " + appId);
-      createStartWaitAndLogApplication(appYaml);
-
+      Entity app = createStartWaitAndLogApplication(appYaml);
+      TestEntity entity = (TestEntity) Iterables.find(app.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity"));
+      
+      // start was overridden, so java method not called; but composite will have called
"testEntity.myEffector"
+      assertEquals(entity.getCallHistory(), ImmutableList.of("myEffector"));
+      entity.clearCallHistory();
+      
       // Rebind
       StartableApplication newApp = rebind();
-      TestEntity testEntity = (TestEntity) Iterables.find(newApp.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity"));
-      Effector effector = assertHasInitializers(testEntity, "start");
+      TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity"));
+      Effector<?> effector = assertHasInitializers(newEntity, "start");
 
       // Confirm HttpCommandEffector still functions
-      Object results = testEntity.invoke(effector, ImmutableMap.<String, Object>of()).get();
-      assertEquals(((List<Object>)results).get(0), "myId");
+      Object results = newEntity.invoke(effector, ImmutableMap.<String, Object>of()).get();
+      assertEquals(results, MutableList.of("myId", null));
+      
+      assertEquals(newEntity.getCallHistory(), ImmutableList.of("myEffector"));
    }
 
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e33140ec/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntity.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntity.java b/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntity.java
index 7a29c1a..85cc9e2 100644
--- a/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntity.java
+++ b/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntity.java
@@ -124,6 +124,8 @@ public interface TestEntity extends Entity, Startable, EntityLocal, EntityIntern
     
     public List<String> getCallHistory();
     
+    public void clearCallHistory();
+
     public String getMyField();
     
     public String getMyField2();

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e33140ec/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntityImpl.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntityImpl.java b/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntityImpl.java
index 7a2c813..b31caf2 100644
--- a/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntityImpl.java
+++ b/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntityImpl.java
@@ -206,6 +206,11 @@ public class TestEntityImpl extends AbstractEntity implements TestEntity
{
         return callHistory;
     }
     
+    @Override
+    public void clearCallHistory() {
+        callHistory.clear();;
+    }
+    
     public static class TestEntityWithoutEnrichers extends TestEntityImpl {
         @Override
         protected void initEnrichers() {}


Mime
View raw message