You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2016/11/08 20:58:37 UTC

[1/5] brooklyn-server git commit: Add more DSL tests

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 <al...@gmail.com>
Authored: Tue Nov 8 15:32:06 2016 +0000
Committer: Aled Sage <al...@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++) {


[5/5] brooklyn-server git commit: This closes #416

Posted by al...@apache.org.
This closes #416


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

Branch: refs/heads/master
Commit: 63cb4c54bbe63608a24578830861e03777322c4f
Parents: e56de02 bebd180
Author: Aled Sage <al...@gmail.com>
Authored: Tue Nov 8 20:58:22 2016 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Nov 8 20:58:22 2016 +0000

----------------------------------------------------------------------
 .../camp/brooklyn/DslAndRebindYamlTest.java     | 157 +++++++++----------
 .../brooklyn/camp/brooklyn/dsl/DslTest.java     |  31 ++++
 .../core/mgmt/rebind/RebindOptions.java         |  10 ++
 .../core/mgmt/rebind/RebindTestFixture.java     |   5 +-
 .../test/framework/TestHttpCallTest.java        |  39 +++--
 .../test/framework/yaml/TestCaseYamlTest.java   |   2 +
 .../framework/yaml/TestHttpCallYamlTest.java    |  93 +++++++++++
 7 files changed, 235 insertions(+), 102 deletions(-)
----------------------------------------------------------------------



[3/5] brooklyn-server git commit: Adds TestHttpCallYamlTest

Posted by al...@apache.org.
Adds TestHttpCallYamlTest


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

Branch: refs/heads/master
Commit: 5d21b7b56667bedffb53139218ebe396d59cd639
Parents: 5399a3b
Author: Aled Sage <al...@gmail.com>
Authored: Tue Nov 8 15:33:36 2016 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Nov 8 18:09:21 2016 +0000

----------------------------------------------------------------------
 .../framework/yaml/TestHttpCallYamlTest.java    | 93 ++++++++++++++++++++
 1 file changed, 93 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5d21b7b5/test-framework/src/test/java/org/apache/brooklyn/test/framework/yaml/TestHttpCallYamlTest.java
----------------------------------------------------------------------
diff --git a/test-framework/src/test/java/org/apache/brooklyn/test/framework/yaml/TestHttpCallYamlTest.java b/test-framework/src/test/java/org/apache/brooklyn/test/framework/yaml/TestHttpCallYamlTest.java
new file mode 100644
index 0000000..38a6328
--- /dev/null
+++ b/test-framework/src/test/java/org/apache/brooklyn/test/framework/yaml/TestHttpCallYamlTest.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.test.framework.yaml;
+
+import org.apache.brooklyn.camp.brooklyn.AbstractYamlRebindTest;
+import org.apache.brooklyn.core.test.entity.TestEntity;
+import org.apache.brooklyn.entity.stock.BasicApplication;
+import org.apache.brooklyn.test.Asserts;
+import org.apache.brooklyn.test.framework.TestHttpCall;
+import org.apache.brooklyn.test.http.TestHttpRequestHandler;
+import org.apache.brooklyn.test.http.TestHttpServer;
+import org.apache.brooklyn.util.net.Urls;
+import org.apache.brooklyn.util.text.Identifiers;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+//Checks that the test cases work in YAML
+@Test
+public class TestHttpCallYamlTest extends AbstractYamlRebindTest {
+
+    // TODO See comments in TestCaseYamlTest
+
+    @SuppressWarnings("unused")
+    private static final Logger log = LoggerFactory.getLogger(TestHttpCallYamlTest.class);
+
+    private TestHttpServer server;
+    private String testId;
+
+    @BeforeMethod(alwaysRun = true)
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        testId = Identifiers.makeRandomId(8);
+        server = new TestHttpServer()
+                .handler("/201", new TestHttpRequestHandler()
+                        .response("Created - " + testId)
+                        .code(201))
+                .handler("/204", new TestHttpRequestHandler().code(204))
+                .handler("/index.html", new TestHttpRequestHandler()
+                        .response("<html><body><h1>Im a H1 tag!</h1></body></html>")
+                        .code(200))
+                .handler("/body.json", new TestHttpRequestHandler()
+                        .response("{\"a\":\"b\",\"c\":\"d\",\"e\":123,\"g\":false}")
+                        .code(200 + Identifiers.randomInt(99)))
+                .start();
+    }
+
+    @AfterMethod(alwaysRun=true)
+    @Override
+    public void tearDown() throws Exception {
+        try {
+            super.tearDown();
+        } finally {
+            if (server != null) server.stop();
+        }
+    }
+    
+    @Test
+    public void testSimpleGet() throws Exception {
+        origApp = (BasicApplication) createStartWaitAndLogApplication(
+                "services:",
+                "- type: " + TestEntity.class.getName(),
+                "  id: target-app",
+                "- type: " + TestHttpCall.class.getName(),
+                "  brooklyn.config:",
+                "    targetId: target-app",
+                "    timeout: " + Asserts.DEFAULT_LONG_TIMEOUT,
+                "    url: " + Urls.mergePaths(server.getUrl(), "index.html"),
+                "    applyAssertionTo: status",
+                "    assert:",
+                "      equals: 200"
+                );
+    }
+}


[4/5] brooklyn-server git commit: TestCaseYamlTest: increase assertion timeout

Posted by al...@apache.org.
TestCaseYamlTest: increase assertion timeout

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

Branch: refs/heads/master
Commit: bebd180be5be073cb1ba479e344c778c3706ec6d
Parents: 5d21b7b
Author: Aled Sage <al...@gmail.com>
Authored: Tue Nov 8 18:08:32 2016 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Nov 8 18:09:22 2016 +0000

----------------------------------------------------------------------
 .../org/apache/brooklyn/test/framework/yaml/TestCaseYamlTest.java  | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/bebd180b/test-framework/src/test/java/org/apache/brooklyn/test/framework/yaml/TestCaseYamlTest.java
----------------------------------------------------------------------
diff --git a/test-framework/src/test/java/org/apache/brooklyn/test/framework/yaml/TestCaseYamlTest.java b/test-framework/src/test/java/org/apache/brooklyn/test/framework/yaml/TestCaseYamlTest.java
index 53f6e87..d5a1929 100644
--- a/test-framework/src/test/java/org/apache/brooklyn/test/framework/yaml/TestCaseYamlTest.java
+++ b/test-framework/src/test/java/org/apache/brooklyn/test/framework/yaml/TestCaseYamlTest.java
@@ -22,6 +22,7 @@ import org.apache.brooklyn.camp.brooklyn.AbstractYamlRebindTest;
 import org.apache.brooklyn.core.entity.BrooklynConfigKeys;
 import org.apache.brooklyn.entity.machine.MachineEntity;
 import org.apache.brooklyn.entity.stock.BasicApplication;
+import org.apache.brooklyn.test.Asserts;
 import org.apache.brooklyn.test.framework.TestCase;
 import org.apache.brooklyn.test.framework.TestEffector;
 import org.apache.brooklyn.test.framework.TestSensor;
@@ -78,6 +79,7 @@ public class TestCaseYamlTest extends AbstractYamlRebindTest {
                 "- type: " + TestCase.class.getName(),
                 "  brooklyn.config:",
                 "    targetId: target-app",
+                "    timeout: " + Asserts.DEFAULT_LONG_TIMEOUT,
                 "  brooklyn.children:",
                 "  - type: " + TestSensor.class.getName(),
                 "    brooklyn.config:",


[2/5] brooklyn-server git commit: Code tidy for tests

Posted by al...@apache.org.
Code tidy for 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/a5b34a72
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/a5b34a72
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/a5b34a72

Branch: refs/heads/master
Commit: a5b34a722aa40bd74e0c5dbdf0c078689a2cd853
Parents: e56de02
Author: Aled Sage <al...@gmail.com>
Authored: Tue Nov 8 15:29:28 2016 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Nov 8 15:35:08 2016 +0000

----------------------------------------------------------------------
 .../camp/brooklyn/DslAndRebindYamlTest.java     | 144 ++++++++-----------
 .../core/mgmt/rebind/RebindOptions.java         |  10 ++
 .../core/mgmt/rebind/RebindTestFixture.java     |   5 +-
 .../test/framework/TestHttpCallTest.java        |  39 ++---
 4 files changed, 95 insertions(+), 103 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/a5b34a72/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 a1147db..64362d2 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
@@ -18,9 +18,9 @@
  */
 package org.apache.brooklyn.camp.brooklyn;
 
-import java.io.File;
+import static org.testng.Assert.assertNotNull;
+
 import java.util.List;
-import java.util.Set;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -29,9 +29,7 @@ import java.util.concurrent.TimeUnit;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.brooklyn.api.entity.Application;
 import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.mgmt.ha.MementoCopyMode;
 import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMementoRawData;
 import org.apache.brooklyn.api.sensor.AttributeSensor;
@@ -43,13 +41,10 @@ import org.apache.brooklyn.core.entity.Attributes;
 import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityAsserts;
 import org.apache.brooklyn.core.entity.EntityInternal;
-import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
 import org.apache.brooklyn.core.mgmt.persist.BrooklynPersistenceUtils;
-import org.apache.brooklyn.core.mgmt.rebind.RebindTestUtils;
 import org.apache.brooklyn.core.sensor.Sensors;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.entity.group.DynamicCluster;
-import org.apache.brooklyn.util.collections.MutableSet;
 import org.apache.brooklyn.util.core.task.Tasks;
 import org.apache.brooklyn.util.guava.Maybe;
 import org.slf4j.Logger;
@@ -61,43 +56,26 @@ import org.testng.annotations.Test;
 
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
-import com.google.common.io.Files;
 
 @Test
-public class DslAndRebindYamlTest extends AbstractYamlTest {
+public class DslAndRebindYamlTest extends AbstractYamlRebindTest {
 
     private static final Logger log = LoggerFactory.getLogger(DslAndRebindYamlTest.class);
 
-    protected ClassLoader classLoader = getClass().getClassLoader();
-    protected File mementoDir;
-    protected Set<ManagementContext> mgmtContexts = MutableSet.of();
     protected ExecutorService executor;
 
-    @Override
-    protected LocalManagementContext newTestManagementContext() {
-        if (mementoDir != null) throw new IllegalStateException("already created mgmt context");
-        mementoDir = Files.createTempDir();
-        mementoDir.deleteOnExit();
-        LocalManagementContext mgmt = RebindTestUtils.newPersistingManagementContext(mementoDir, classLoader, 1);
-        mgmtContexts.add(mgmt);
-        return mgmt;
-    }
-
     @BeforeMethod(alwaysRun = true)
     @Override
     public void setUp() throws Exception {
-    	super.setUp();
+        super.setUp();
         executor = Executors.newSingleThreadExecutor();
     }
     
     @AfterMethod(alwaysRun = true)
     @Override
     public void tearDown() throws Exception {
-    	if (executor != null) executor.shutdownNow();
-        for (ManagementContext mgmt : mgmtContexts) Entities.destroyAll(mgmt);
+        if (executor != null) executor.shutdownNow();
         super.tearDown();
-        mementoDir = null;
-        mgmtContexts.clear();
     }
 
     @Override
@@ -105,14 +83,14 @@ public class DslAndRebindYamlTest extends AbstractYamlTest {
         return log;
     }
 
-    protected Application rebind(Application app) throws Exception {
-        RebindTestUtils.stopPersistence(app);
-        Application result = RebindTestUtils.rebind(mementoDir, getClass().getClassLoader());
-        mgmtContexts.add(result.getManagementContext());
-        return result;
+    @SuppressWarnings("unchecked")
+    protected <T extends Entity> T rebind(T entity) throws Exception {
+        rebind();
+        Entity result = mgmt().getEntityManager().getEntity(entity.getId());
+        assertNotNull(result, "no entity found after rebind with id " + entity.getId());
+        return (T) result;
     }
 
-
     protected Entity setupAndCheckTestEntityInBasicYamlWith(String... extras) throws Exception {
         Entity app = createAndStartApplication(loadYaml("test-entity-basic-template.yaml", extras));
         waitForApplicationTasks(app);
@@ -139,16 +117,16 @@ public class DslAndRebindYamlTest extends AbstractYamlTest {
     }
 
     protected <T> Future<T> getConfigInTaskAsync(final Entity entity, final ConfigKey<T> key) {
-	    // Wait for the attribute to be ready in a new Task
-	    Callable<T> configGetter = new Callable<T>() {
-	        @Override
-	        public T call() throws Exception {
-	            T s = getConfigInTask(entity, key);
-	            getLogger().info("getConfig {}={}", key, s);
-	            return s;
-	        }
-	    };
-	    return executor.submit(configGetter);
+        // Wait for the attribute to be ready in a new Task
+        Callable<T> configGetter = new Callable<T>() {
+            @Override
+            public T call() throws Exception {
+                T s = getConfigInTask(entity, key);
+                getLogger().info("getConfig {}={}", key, s);
+                return s;
+            }
+        };
+        return executor.submit(configGetter);
     }
 
     @Test
@@ -163,8 +141,7 @@ public class DslAndRebindYamlTest extends AbstractYamlTest {
         Entity testEntity = entityWithAttributeWhenReady();
         ((EntityInternal) testEntity).sensors().set(Sensors.newStringSensor("foo"), "bar");
         
-        Application app2 = rebind(testEntity.getApplication());
-        Entity e2 = Iterables.getOnlyElement(app2.getChildren());
+        Entity e2 = rebind(testEntity);
 
         Assert.assertEquals(getConfigInTask(e2, TestEntity.CONF_NAME), "bar");
     }
@@ -173,8 +150,7 @@ public class DslAndRebindYamlTest extends AbstractYamlTest {
     public void testDslAttributeWhenReadyWhenNotYetResolved() throws Exception {
         Entity testEntity = entityWithAttributeWhenReady();
         
-        Application app2 = rebind(testEntity.getApplication());
-        Entity e2 = Iterables.getOnlyElement(app2.getChildren());
+        Entity e2 = rebind(testEntity);
 
         // Wait for the attribute to be ready in a new Task
         Future<String> stringFuture = getConfigInTaskAsync(e2, TestEntity.CONF_NAME);
@@ -190,25 +166,24 @@ public class DslAndRebindYamlTest extends AbstractYamlTest {
 
     @Test
     public void testDslAttributeWhenReadyPersistedAsDeferredSupplier() throws Exception {
-    	doDslAttributeWhenReadyPersistedAsDeferredSupplier(false);
+        doDslAttributeWhenReadyPersistedAsDeferredSupplier(false);
     }
     
     @Test
     public void testDslAttributeWhenReadyPersistedWithoutLeakingResolvedValue() throws Exception {
-    	doDslAttributeWhenReadyPersistedAsDeferredSupplier(true);
+        doDslAttributeWhenReadyPersistedAsDeferredSupplier(true);
     }
     
     protected void doDslAttributeWhenReadyPersistedAsDeferredSupplier(boolean resolvedBeforeRebind) throws Exception {
         Entity testEntity = entityWithAttributeWhenReady();
         
         if (resolvedBeforeRebind) {
-        	testEntity.sensors().set(Sensors.newStringSensor("foo"), "bar");
-        	Assert.assertEquals(getConfigInTask(testEntity, TestEntity.CONF_NAME), "bar");
+            testEntity.sensors().set(Sensors.newStringSensor("foo"), "bar");
+            Assert.assertEquals(getConfigInTask(testEntity, TestEntity.CONF_NAME), "bar");
         }
         
         // Persist and rebind
-        Application app2 = rebind(testEntity.getApplication());
-        Entity e2 = Iterables.getOnlyElement(app2.getChildren());
+        Entity e2 = rebind(testEntity);
 
         Maybe<Object> maybe = ((EntityInternal) e2).config().getLocalRaw(TestEntity.CONF_NAME);
         Assert.assertTrue(maybe.isPresentAndNonNull());
@@ -217,7 +192,7 @@ public class DslAndRebindYamlTest extends AbstractYamlTest {
         Assert.assertEquals(deferredSupplier.toString(), "$brooklyn:entity(\"x\").attributeWhenReady(\"foo\")");
 
         // Assert the persisted state itself is as expected, and not too big
-        BrooklynMementoRawData raw = BrooklynPersistenceUtils.newStateMemento(app2.getManagementContext(), MementoCopyMode.LOCAL);
+        BrooklynMementoRawData raw = BrooklynPersistenceUtils.newStateMemento(mgmt(), MementoCopyMode.LOCAL);
         String persistedStateForE2 = raw.getEntities().get(e2.getId());
         Matcher matcher = Pattern.compile(".*\\<test.confName\\>(.*)\\<\\/test.confName\\>.*", Pattern.DOTALL)
                 .matcher(persistedStateForE2);
@@ -244,12 +219,12 @@ public class DslAndRebindYamlTest extends AbstractYamlTest {
 
     @Test
     public void testDslAttributeWhenReadyInEntitySpecWhenNotYetResolved() throws Exception {
-    	doDslAttributeWhenReadyInEntitySpec(false);
+        doDslAttributeWhenReadyInEntitySpec(false);
     }
     
     @Test
     public void testDslAttributeWhenReadyInEntitySpecWhenAlreadyResolved() throws Exception {
-    	doDslAttributeWhenReadyInEntitySpec(true);
+        doDslAttributeWhenReadyInEntitySpec(true);
     }
     
     protected void doDslAttributeWhenReadyInEntitySpec(boolean resolvedBeforeRebind) throws Exception {
@@ -275,11 +250,10 @@ public class DslAndRebindYamlTest extends AbstractYamlTest {
         }
 
         // Persist and rebind
-        Application app2 = rebind(cluster.getApplication());
-        DynamicCluster cluster2 = (DynamicCluster) Iterables.getOnlyElement(app2.getApplication().getChildren());
+        DynamicCluster cluster2 = rebind(cluster);
 
         // Assert the persisted state itself is as expected, and not too big
-        BrooklynMementoRawData raw = BrooklynPersistenceUtils.newStateMemento(app2.getManagementContext(), MementoCopyMode.LOCAL);
+        BrooklynMementoRawData raw = BrooklynPersistenceUtils.newStateMemento(mgmt(), MementoCopyMode.LOCAL);
         String persistedStateForE2 = raw.getEntities().get(cluster2.getId());
         String expectedTag = "org.apache.brooklyn.camp.brooklyn.spi.dsl.methods.DslComponent_-AttributeWhenReady";
         Matcher matcher = Pattern.compile(".*\\<"+expectedTag+"\\>(.*)\\<\\/"+expectedTag+"\\>.*", Pattern.DOTALL)
@@ -294,38 +268,38 @@ public class DslAndRebindYamlTest extends AbstractYamlTest {
         
         // Both the existing and the new member should have the DeferredSupplier config
         for (Entity member : Iterables.filter(cluster2.getChildren(), TestEntity.class)) {
-	        Maybe<Object> maybe = ((EntityInternal)member).config().getLocalRaw(TestEntity.CONF_NAME);
-	        Assert.assertTrue(maybe.isPresentAndNonNull());
-	        BrooklynDslDeferredSupplier<?> deferredSupplier = (BrooklynDslDeferredSupplier<?>) maybe.get();
-	        Assert.assertEquals(deferredSupplier.toString(), "$brooklyn:entity(\"test-cluster\").attributeWhenReady(\"sensor\")");
+            Maybe<Object> maybe = ((EntityInternal)member).config().getLocalRaw(TestEntity.CONF_NAME);
+            Assert.assertTrue(maybe.isPresentAndNonNull());
+            BrooklynDslDeferredSupplier<?> deferredSupplier = (BrooklynDslDeferredSupplier<?>) maybe.get();
+            Assert.assertEquals(deferredSupplier.toString(), "$brooklyn:entity(\"test-cluster\").attributeWhenReady(\"sensor\")");
         }
         
         if (resolvedBeforeRebind) {
             // All members should resolve their config
             for (Entity member : Iterables.filter(cluster2.getChildren(), TestEntity.class)) {
-		        String val = getConfigInTask(member, TestEntity.CONF_NAME);
-		        Assert.assertEquals(val, "bar");
+                String val = getConfigInTask(member, TestEntity.CONF_NAME);
+                Assert.assertEquals(val, "bar");
             }
         } else {
-        	List<Future<String>> futures = Lists.newArrayList();
-        	
+            List<Future<String>> futures = Lists.newArrayList();
+            
             // All members should have unresolved values
             for (Entity member : Iterables.filter(cluster2.getChildren(), TestEntity.class)) {
-		        // Wait for the attribute to be ready in a new Task
-		        Future<String> stringFuture = getConfigInTaskAsync(member, TestEntity.CONF_NAME);
-		        futures.add(stringFuture);
-		        
-		        // Check that the Task is still waiting for attribute to be ready
-		        Thread.sleep(100);
-		        Assert.assertFalse(stringFuture.isDone());
+                // Wait for the attribute to be ready in a new Task
+                Future<String> stringFuture = getConfigInTaskAsync(member, TestEntity.CONF_NAME);
+                futures.add(stringFuture);
+                
+                // Check that the Task is still waiting for attribute to be ready
+                Thread.sleep(100);
+                Assert.assertFalse(stringFuture.isDone());
             }
             
             // After setting the sensor, all those values should now resolve
-	        cluster2.sensors().set(Sensors.newStringSensor("sensor"), "bar");
-	        
-	        for (Future<String> future : futures) {
-		        String s = future.get(10, TimeUnit.SECONDS); // Timeout just for sanity
-		        Assert.assertEquals(s, "bar");
+            cluster2.sensors().set(Sensors.newStringSensor("sensor"), "bar");
+            
+            for (Future<String> future : futures) {
+                String s = future.get(10, TimeUnit.SECONDS); // Timeout just for sanity
+                Assert.assertEquals(s, "bar");
             }
         }
     }
@@ -347,8 +321,7 @@ public class DslAndRebindYamlTest extends AbstractYamlTest {
         Sensor<?> s;
         s = inTask ? getConfigInTask(testEntity, configKey) : testEntity.getConfig(configKey);
         Assert.assertEquals(s, expectedSensor);
-        Application app2 = rebind(testEntity.getApplication());
-        Entity te2 = Iterables.getOnlyElement(app2.getChildren());
+        Entity te2 = rebind(testEntity);
         s = inTask ? getConfigInTask(te2, configKey) : te2.getConfig(configKey);
         Assert.assertEquals(s, expectedSensor);
     }
@@ -356,6 +329,8 @@ public class DslAndRebindYamlTest extends AbstractYamlTest {
     @Test
     public void testDslSensorFromClass() throws Exception {
         doTestOnEntityWithSensor(entityWithSensorFromClass(), Attributes.SERVICE_UP);
+        switchOriginalToNewManagementContext();
+        
         // without context it can still find it
         doTestOnEntityWithSensor(entityWithSensorFromClass(), Attributes.SERVICE_UP, false);
     }
@@ -406,8 +381,7 @@ public class DslAndRebindYamlTest extends AbstractYamlTest {
     @Test
     public void testDslConfigFromRootRebind() throws Exception {
         Entity testEntity = entityWithConfigFromRoot();
-        Application app2 = rebind(testEntity.getApplication());
-        Entity e2 = Iterables.getOnlyElement(app2.getChildren());
+        Entity e2 = rebind(testEntity);
 
         Assert.assertEquals(getConfigInTask(e2, TestEntity.CONF_NAME), "bar");
     }
@@ -431,8 +405,7 @@ public class DslAndRebindYamlTest extends AbstractYamlTest {
     @Test
     public void testDslFormatStringRebind() throws Exception {
         Entity testEntity = entityWithFormatString();
-        Application app2 = rebind(testEntity.getApplication());
-        Entity e2 = Iterables.getOnlyElement(app2.getChildren());
+        Entity e2 = rebind(testEntity);
 
         Assert.assertEquals(getConfigInTask(e2, TestEntity.CONF_NAME), "hello world");
     }
@@ -444,7 +417,6 @@ public class DslAndRebindYamlTest extends AbstractYamlTest {
                 "    test.confName: $brooklyn:formatString(\"hello %s\", \"world\")");
     }
 
-
     /*
         - type: org.apache.brooklyn.enricher.stock.Transformer
           brooklyn.config:

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/a5b34a72/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java
index e3c32db..bfa65d4 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java
@@ -30,6 +30,8 @@ import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMementoPersister;
 import org.apache.brooklyn.core.mgmt.persist.PersistenceObjectStore;
 
 import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
 
 /**
  * See {@link RebindTestFixture#rebind(RebindOptions)} and {@link RebindTestUtils#rebind(RebindOptions)}.
@@ -117,6 +119,14 @@ public class RebindOptions {
         this.applicationChooserOnRebind = val;
         return this;
     }
+    public RebindOptions applicationChooserOnRebind(final Predicate<? super Application> val) {
+        Function<Collection<Application>, Application> funcVal = new Function<Collection<Application>, Application>() {
+            @Override public Application apply(Collection<Application> input) {
+                return Iterables.find(input, val);
+            }
+        };
+        return applicationChooserOnRebind(funcVal);
+    }
     public RebindOptions additionalProperties(Map<?, ?> additionalProperties) {
         this.additionalProperties = additionalProperties;
         return this;

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/a5b34a72/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
index 0e2c9fb..ec8aae9 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
@@ -29,6 +29,7 @@ import java.util.concurrent.Callable;
 import org.apache.brooklyn.api.catalog.BrooklynCatalog;
 import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.entity.Application;
+import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.mgmt.Task;
 import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
@@ -38,6 +39,7 @@ import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMementoManifest;
 import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
 import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityFunctions;
+import org.apache.brooklyn.core.entity.EntityPredicates;
 import org.apache.brooklyn.core.entity.StartableApplication;
 import org.apache.brooklyn.core.entity.trait.Startable;
 import org.apache.brooklyn.core.internal.BrooklynProperties;
@@ -293,8 +295,9 @@ public abstract class RebindTestFixture<T extends StartableApplication> {
         if (options.mementoDir == null) options.mementoDir(mementoDir);
         if (options.origManagementContext == null) options.origManagementContext(origManagementContext);
         if (options.newManagementContext == null) options.newManagementContext(createNewManagementContext(options.mementoDir, options.additionalProperties));
+        if (options.applicationChooserOnRebind == null && origApp != null) options.applicationChooserOnRebind(EntityPredicates.idEqualTo(origApp.getId()));
         
-        RebindTestUtils.stopPersistence(origApp);
+        RebindTestUtils.stopPersistence(options.origManagementContext);
         
         newManagementContext = options.newManagementContext;
         newApp = (T) RebindTestUtils.rebind(options);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/a5b34a72/test-framework/src/test/java/org/apache/brooklyn/test/framework/TestHttpCallTest.java
----------------------------------------------------------------------
diff --git a/test-framework/src/test/java/org/apache/brooklyn/test/framework/TestHttpCallTest.java b/test-framework/src/test/java/org/apache/brooklyn/test/framework/TestHttpCallTest.java
index 975e65a..cb824ce 100644
--- a/test-framework/src/test/java/org/apache/brooklyn/test/framework/TestHttpCallTest.java
+++ b/test-framework/src/test/java/org/apache/brooklyn/test/framework/TestHttpCallTest.java
@@ -18,37 +18,37 @@
  */
 package org.apache.brooklyn.test.framework;
 
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.LocationSpec;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
 import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
 import org.apache.brooklyn.test.http.TestHttpRequestHandler;
 import org.apache.brooklyn.test.http.TestHttpServer;
 import org.apache.brooklyn.util.text.Identifiers;
 import org.apache.brooklyn.util.time.Duration;
 import org.apache.http.HttpStatus;
+import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
-public class TestHttpCallTest {
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 
+public class TestHttpCallTest extends BrooklynAppUnitTestSupport {
 
     private TestHttpServer server;
-    private TestApplication app;
-    private ManagementContext managementContext;
     private LocalhostMachineProvisioningLocation loc;
     private String testId;
 
     @BeforeMethod(alwaysRun = true)
-    public void setup() {
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         testId = Identifiers.makeRandomId(8);
         server = new TestHttpServer()
                 .handler("/201", new TestHttpRequestHandler()
@@ -62,12 +62,19 @@ public class TestHttpCallTest {
                         .response("{\"a\":\"b\",\"c\":\"d\",\"e\":123,\"g\":false}")
                         .code(200 + Identifiers.randomInt(99)))
                 .start();
-        app = TestApplication.Factory.newManagedInstanceForTests();
-        managementContext = app.getManagementContext();
-        loc = managementContext.getLocationManager().createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class)
+        loc = mgmt.getLocationManager().createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class)
                 .configure("name", testId));
     }
 
+    @AfterMethod(alwaysRun=true)
+    @Override
+    public void tearDown() throws Exception {
+        try {
+            super.tearDown();
+        } finally {
+            if (server != null) server.stop();
+        }
+    }
 
     @Test(groups = "Integration")
     public void testHttpBodyAssertions() {