TestEffector: handle non-string return types Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/90d2781f Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/90d2781f Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/90d2781f
Branch: refs/heads/master Commit: 90d2781f2b58c65f6db8023c93e75b625bfd3144 Parents: 04a561c Author: Aled Sage <aled.s...@gmail.com> Authored: Tue Jul 26 13:54:34 2016 +0100 Committer: Aled Sage <aled.s...@gmail.com> Committed: Wed Aug 3 20:56:01 2016 +0100 ---------------------------------------------------------------------- .../test/framework/TestEffectorImpl.java | 20 +++++++------------- .../test/framework/TestEffectorTest.java | 19 +++++++++++++++++++ .../test/framework/entity/TestEntity.java | 3 +++ .../test/framework/entity/TestEntityImpl.java | 5 +++++ 4 files changed, 34 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/90d2781f/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestEffectorImpl.java ---------------------------------------------------------------------- diff --git a/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestEffectorImpl.java b/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestEffectorImpl.java index fc62aa3..2ff0337 100644 --- a/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestEffectorImpl.java +++ b/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestEffectorImpl.java @@ -24,13 +24,6 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; - import org.apache.brooklyn.api.effector.Effector; import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.location.Location; @@ -42,6 +35,12 @@ import org.apache.brooklyn.core.mgmt.internal.EffectorUtils; import org.apache.brooklyn.util.exceptions.Exceptions; import org.apache.brooklyn.util.guava.Maybe; import org.apache.brooklyn.util.time.Duration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; public class TestEffectorImpl extends TargetableTestComponentImpl implements TestEffector { private static final Logger LOG = LoggerFactory.getLogger(TestEffectorImpl.class); @@ -75,12 +74,7 @@ public class TestEffectorImpl extends TargetableTestComponentImpl implements Tes final List<Map<String, Object>> assertions = getAssertions(this, ASSERTIONS); if(assertions != null && !assertions.isEmpty()){ - TestFrameworkAssertions.checkAssertions(ImmutableMap.of("timeout", timeout), assertions, effectorName, new Supplier<String>() { - @Override - public String get() { - return (String)effectorResult; - } - }); + TestFrameworkAssertions.checkAssertions(ImmutableMap.of("timeout", timeout), assertions, effectorName, Suppliers.ofInstance(effectorResult)); } //Add result of effector to sensor http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/90d2781f/test-framework/src/test/java/org/apache/brooklyn/test/framework/TestEffectorTest.java ---------------------------------------------------------------------- diff --git a/test-framework/src/test/java/org/apache/brooklyn/test/framework/TestEffectorTest.java b/test-framework/src/test/java/org/apache/brooklyn/test/framework/TestEffectorTest.java index b7a341b..fab67e9 100644 --- a/test-framework/src/test/java/org/apache/brooklyn/test/framework/TestEffectorTest.java +++ b/test-framework/src/test/java/org/apache/brooklyn/test/framework/TestEffectorTest.java @@ -79,6 +79,25 @@ public class TestEffectorTest extends BrooklynAppUnitTestSupport { } @Test + public void testEffectorReturnsInt() throws Exception { + int intToReturn = 123; + + List<Map<String, Object>> assertions = ImmutableList.<Map<String, Object>>of( + ImmutableMap.<String, Object>of(TestFrameworkAssertions.EQUAL_TO, intToReturn)); + + final TestEffector testEffector = testCase.addChild(EntitySpec.create(TestEffector.class) + .configure(TestEffector.TARGET_ENTITY, testEntity) + .configure(TestEffector.EFFECTOR_NAME, "effectorReturnsInt") + .configure(TestEffector.EFFECTOR_PARAMS, ImmutableMap.of("intToReturn", intToReturn)) + .configure(TestEffector.ASSERTIONS, assertions)); + + app.start(locs); + + assertThat(testEffector.sensors().get(TestEffector.EFFECTOR_RESULT)).isEqualTo(123); + assertThat(testEffector.sensors().get(SERVICE_UP)).isTrue(); + } + + @Test public void testEffectorPositiveAssertions() throws Exception { String stringToReturn = "Hello World!"; http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/90d2781f/test-framework/src/test/java/org/apache/brooklyn/test/framework/entity/TestEntity.java ---------------------------------------------------------------------- diff --git a/test-framework/src/test/java/org/apache/brooklyn/test/framework/entity/TestEntity.java b/test-framework/src/test/java/org/apache/brooklyn/test/framework/entity/TestEntity.java index 939f452..569a42e 100644 --- a/test-framework/src/test/java/org/apache/brooklyn/test/framework/entity/TestEntity.java +++ b/test-framework/src/test/java/org/apache/brooklyn/test/framework/entity/TestEntity.java @@ -47,6 +47,9 @@ public interface TestEntity extends Entity, Startable { @Effector String effectorReturnsString(@EffectorParam(name = "stringToReturn") final String stringToReturn); + @Effector + Integer effectorReturnsInt(@EffectorParam(name = "intToReturn") Integer intToReturn); + class TestPojo { private final String stringValue; private final Boolean booleanValue; http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/90d2781f/test-framework/src/test/java/org/apache/brooklyn/test/framework/entity/TestEntityImpl.java ---------------------------------------------------------------------- diff --git a/test-framework/src/test/java/org/apache/brooklyn/test/framework/entity/TestEntityImpl.java b/test-framework/src/test/java/org/apache/brooklyn/test/framework/entity/TestEntityImpl.java index 8cb59cf..5181687 100644 --- a/test-framework/src/test/java/org/apache/brooklyn/test/framework/entity/TestEntityImpl.java +++ b/test-framework/src/test/java/org/apache/brooklyn/test/framework/entity/TestEntityImpl.java @@ -56,4 +56,9 @@ public class TestEntityImpl extends AbstractEntity implements TestEntity { public String effectorReturnsString(String stringToReturn) { return stringToReturn; } + + @Override + public Integer effectorReturnsInt(Integer intToReturn) { + return intToReturn; + } }