brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [1/2] brooklyn-library git commit: Delete use of deprecated ApplicationBuilder (in tests)
Date Tue, 20 Jun 2017 08:46:00 GMT
Repository: brooklyn-library
Updated Branches:
  refs/heads/master 32a97ca79 -> 4d231bf3a


Delete use of deprecated ApplicationBuilder (in tests)

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

Branch: refs/heads/master
Commit: 4fbe6f01db6bb59e7a0f74ec6b59a93ee87e6cd7
Parents: f7268b7
Author: Aled Sage <aled.sage@gmail.com>
Authored: Mon Jun 19 13:13:24 2017 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Mon Jun 19 13:13:24 2017 +0100

----------------------------------------------------------------------
 .../crate/CrateNodeIntegrationTest.java         | 20 +++---
 .../mariadb/MariaDbIntegrationTest.java         | 31 +++-------
 .../mariadb/MariaDbLiveRackspaceTest.java       |  8 ++-
 .../rubyrep/RubyRepIntegrationTest.java         | 44 ++++----------
 .../rubyrep/RubyRepRackspaceLiveTest.java       | 10 +--
 .../activemq/ActiveMQIntegrationTest.java       | 20 +++---
 .../messaging/kafka/KafkaIntegrationTest.java   | 24 +++-----
 .../messaging/qpid/QpidIntegrationTest.java     | 20 +++---
 .../messaging/rabbit/RabbitIntegrationTest.java | 23 +++----
 .../nosql/couchdb/AbstractCouchDBNodeTest.java  | 53 ----------------
 .../nosql/couchdb/CouchDBClusterLiveTest.java   | 17 ++----
 .../couchdb/CouchDBNodeIntegrationTest.java     | 15 ++++-
 .../nosql/couchdb/CouchDBNodeLiveTest.java      |  8 ++-
 .../nosql/mongodb/MongoDBIntegrationTest.java   | 20 +++---
 .../nosql/mongodb/MongoDBWinEc2LiveTest.java    |  3 +-
 .../MongoDBConfigServerIntegrationTest.java     | 18 +++---
 .../redis/RedisClusterIntegrationTest.java      | 23 +++----
 .../brooklyn/entity/proxy/UrlMappingTest.java   | 62 +++++++------------
 .../proxy/nginx/NginxWebClusterEc2LiveTest.java | 29 ++++-----
 .../AbstractWebAppFixtureIntegrationTest.java   |  4 +-
 ...namicWebAppClusterRebindIntegrationTest.java | 64 +++++++-------------
 ...namicWebAppClusterRebindIntegrationTest.java | 58 ++++++------------
 22 files changed, 192 insertions(+), 382 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4fbe6f01/software/database/src/test/java/org/apache/brooklyn/entity/database/crate/CrateNodeIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/crate/CrateNodeIntegrationTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/crate/CrateNodeIntegrationTest.java
index 535be1a..501a686 100644
--- a/software/database/src/test/java/org/apache/brooklyn/entity/database/crate/CrateNodeIntegrationTest.java
+++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/crate/CrateNodeIntegrationTest.java
@@ -21,12 +21,9 @@ package org.apache.brooklyn.entity.database.crate;
 import static org.testng.Assert.assertFalse;
 
 import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityAsserts;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
 import org.apache.brooklyn.core.entity.trait.Startable;
-import org.apache.brooklyn.core.test.entity.TestApplication;
-import org.testng.annotations.AfterMethod;
+import org.apache.brooklyn.core.test.BrooklynAppLiveTestSupport;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
@@ -34,20 +31,17 @@ import com.google.common.collect.ImmutableList;
 
 import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
 
-public class CrateNodeIntegrationTest {
+// TODO Does it really need to be a live test? When converting from ApplicationBuilder, preserved
+// existing behaviour of using the live BrooklynProperties.
+public class CrateNodeIntegrationTest extends BrooklynAppLiveTestSupport {
 
-    private TestApplication app;
     private LocalhostMachineProvisioningLocation localhostProvisioningLocation;
 
     @BeforeMethod(alwaysRun = true)
+    @Override
     public void setUp() throws Exception {
-        localhostProvisioningLocation = new LocalhostMachineProvisioningLocation();
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-    }
-
-    @AfterMethod(alwaysRun = true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
+        super.setUp();
+        localhostProvisioningLocation = app.newLocalhostProvisioningLocation();
     }
 
     @Test(groups = "Integration")

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4fbe6f01/software/database/src/test/java/org/apache/brooklyn/entity/database/mariadb/MariaDbIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/mariadb/MariaDbIntegrationTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/mariadb/MariaDbIntegrationTest.java
index 061ec02..45a82de 100644
--- a/software/database/src/test/java/org/apache/brooklyn/entity/database/mariadb/MariaDbIntegrationTest.java
+++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/mariadb/MariaDbIntegrationTest.java
@@ -22,18 +22,12 @@ import java.io.File;
 import java.net.InetAddress;
 
 import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
-import org.apache.brooklyn.core.internal.BrooklynProperties;
-import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
-import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.core.test.BrooklynAppLiveTestSupport;
 import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.text.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 import org.apache.brooklyn.entity.database.DatastoreMixins.DatastoreCommon;
@@ -47,28 +41,21 @@ import com.google.common.collect.ImmutableList;
  * from
  * http://www.vogella.de/articles/MySQLJava/article.html
  */
-public class MariaDbIntegrationTest {
+// TODO Does it really need to be a live test? When converting from ApplicationBuilder, preserved
+// existing behaviour of using the live BrooklynProperties. However, this is extended by
+// MariaDBLiveRackspaceTest, so that does need it.
+public class MariaDbIntegrationTest extends BrooklynAppLiveTestSupport {
 
     public static final Logger log = LoggerFactory.getLogger(MariaDbIntegrationTest.class);
     
-    protected BrooklynProperties brooklynProperties;
-    protected ManagementContext managementContext;
-    protected TestApplication tapp;
     protected String hostname;
     
     @BeforeMethod(alwaysRun = true)
+    @Override
     public void setUp() throws Exception {
+        super.setUp();
         // can start in AWS by running this -- or use brooklyn CLI/REST for most clouds, or programmatic/config for set of fixed IP machines
         hostname = InetAddress.getLocalHost().getHostName();
-
-        brooklynProperties = BrooklynProperties.Factory.newDefault();
-        managementContext = new LocalManagementContext(brooklynProperties);
-        tapp = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext);
-    }
-
-    @AfterMethod(alwaysRun=true)
-    public void ensureShutDown() throws Exception {
-        Entities.destroyAllCatching(managementContext);
     }
 
     //from http://www.vogella.de/articles/MySQLJava/article.html
@@ -100,13 +87,13 @@ public class MariaDbIntegrationTest {
     @Test(groups = "Integration")
     public void test_localhost() throws Exception {
         String dataDir = "/tmp/mariadb-data-" + Strings.makeRandomId(8);
-        MariaDbNode mariadb = tapp.createAndManageChild(EntitySpec.create(MariaDbNode.class)
+        MariaDbNode mariadb = app.createAndManageChild(EntitySpec.create(MariaDbNode.class)
                 .configure(MariaDbNode.MARIADB_SERVER_CONF, MutableMap.<String, Object>of("skip-name-resolve",""))
                 .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, CREATION_SCRIPT)
                 .configure(MariaDbNode.DATA_DIR, dataDir));
         LocalhostMachineProvisioningLocation location = new LocalhostMachineProvisioningLocation();
 
-        tapp.start(ImmutableList.of(location));
+        app.start(ImmutableList.of(location));
         log.info("MariaDB started");
 
         new VogellaExampleAccess("com.mysql.jdbc.Driver", mariadb.getAttribute(DatastoreCommon.DATASTORE_URL)).readModifyAndRevertDataBase();

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4fbe6f01/software/database/src/test/java/org/apache/brooklyn/entity/database/mariadb/MariaDbLiveRackspaceTest.java
----------------------------------------------------------------------
diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/mariadb/MariaDbLiveRackspaceTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/mariadb/MariaDbLiveRackspaceTest.java
index 6881273..5ee6986 100644
--- a/software/database/src/test/java/org/apache/brooklyn/entity/database/mariadb/MariaDbLiveRackspaceTest.java
+++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/mariadb/MariaDbLiveRackspaceTest.java
@@ -21,6 +21,7 @@ package org.apache.brooklyn.entity.database.mariadb;
 import java.util.Arrays;
 
 import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.core.internal.BrooklynProperties;
 import org.testng.annotations.Test;
 import org.apache.brooklyn.entity.database.DatastoreMixins.DatastoreCommon;
 import org.apache.brooklyn.entity.database.VogellaExampleAccess;
@@ -85,16 +86,17 @@ public class MariaDbLiveRackspaceTest extends MariaDbIntegrationTest {
     }
 
     public void test(String osRegex) throws Exception {
-        MariaDbNode mariadb = tapp.createAndManageChild(EntitySpec.create(MariaDbNode.class)
+        MariaDbNode mariadb = app.createAndManageChild(EntitySpec.create(MariaDbNode.class)
                 .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, CREATION_SCRIPT));
 
+        BrooklynProperties brooklynProperties = mgmt.getBrooklynProperties();
         brooklynProperties.put("brooklyn.location.jclouds.rackspace-cloudservers-uk.imageNameRegex", osRegex);
         brooklynProperties.remove("brooklyn.location.jclouds.rackspace-cloudservers-uk.image-id");
         brooklynProperties.remove("brooklyn.location.jclouds.rackspace-cloudservers-uk.imageId");
         brooklynProperties.put("brooklyn.location.jclouds.rackspace-cloudservers-uk.inboundPorts", Arrays.asList(22, 3306));
-        JcloudsLocation jcloudsLocation = (JcloudsLocation) managementContext.getLocationRegistry().getLocationManaged("jclouds:rackspace-cloudservers-uk");
+        JcloudsLocation jcloudsLocation = (JcloudsLocation) mgmt.getLocationRegistry().getLocationManaged("jclouds:rackspace-cloudservers-uk");
 
-        tapp.start(ImmutableList.of(jcloudsLocation));
+        app.start(ImmutableList.of(jcloudsLocation));
 
         SshMachineLocation l = (SshMachineLocation) mariadb.getLocations().iterator().next();
         l.execCommands("add iptables rule", ImmutableList.of(IptablesCommands.insertIptablesRule(Chain.INPUT, Protocol.TCP, 3306, Policy.ACCEPT)));

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4fbe6f01/software/database/src/test/java/org/apache/brooklyn/entity/database/rubyrep/RubyRepIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/rubyrep/RubyRepIntegrationTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/rubyrep/RubyRepIntegrationTest.java
index 7127334..08dc2e8 100644
--- a/software/database/src/test/java/org/apache/brooklyn/entity/database/rubyrep/RubyRepIntegrationTest.java
+++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/rubyrep/RubyRepIntegrationTest.java
@@ -25,17 +25,11 @@ import java.util.List;
 
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
-import org.apache.brooklyn.core.internal.BrooklynProperties;
 import org.apache.brooklyn.core.location.PortRanges;
-import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
+import org.apache.brooklyn.core.test.BrooklynAppLiveTestSupport;
 import org.apache.brooklyn.core.test.entity.TestApplication;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 import org.apache.brooklyn.entity.database.DatastoreMixins.DatastoreCommon;
 import org.apache.brooklyn.entity.database.VogellaExampleAccess;
@@ -45,25 +39,13 @@ import org.apache.brooklyn.entity.database.postgresql.PostgreSqlIntegrationTest;
 import org.apache.brooklyn.entity.database.postgresql.PostgreSqlNode;
 import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
 
-public class RubyRepIntegrationTest {
+// TODO Does it really need to be a live test? When converting from ApplicationBuilder, preserved
+// existing behaviour of using the live BrooklynProperties. However, this is extended by
+// RubyRepLiveRackspaceTest, so that does need it.
+public class RubyRepIntegrationTest extends BrooklynAppLiveTestSupport {
 
     public static final Logger log = LoggerFactory.getLogger(RubyRepIntegrationTest.class);
-    protected BrooklynProperties brooklynProperties;
-    protected ManagementContext managementContext;
-    protected TestApplication tapp;
     
-    @BeforeMethod(alwaysRun = true)
-    public void setUp() {
-        brooklynProperties = BrooklynProperties.Factory.newDefault();
-        managementContext = new LocalManagementContext(brooklynProperties);
-        tapp = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext);
-    }
-
-    @AfterMethod(alwaysRun = true)
-    public void tearDown() {
-        Entities.destroyAllCatching(managementContext);
-    }
-
     /*
         Exception org.apache.brooklyn.util.exceptions.PropagatedRuntimeException
         
@@ -208,18 +190,18 @@ public class RubyRepIntegrationTest {
      */
     @Test(groups = {"Integration","Broken"})
     public void test_localhost_mysql() throws Exception {
-        MySqlNode db1 = tapp.createAndManageChild(EntitySpec.create(MySqlNode.class)
+        MySqlNode db1 = app.createAndManageChild(EntitySpec.create(MySqlNode.class)
                 .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, MySqlIntegrationTest.CREATION_SCRIPT)
                 .configure("test.table.name", "COMMENTS")
                 .configure(MySqlNode.MYSQL_PORT, PortRanges.fromInteger(9111)));
 
-        MySqlNode db2 = tapp.createAndManageChild(EntitySpec.create(MySqlNode.class)
+        MySqlNode db2 = app.createAndManageChild(EntitySpec.create(MySqlNode.class)
                 .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, MySqlIntegrationTest.CREATION_SCRIPT)
                 .configure("test.table.name", "COMMENTS")
                 .configure(MySqlNode.MYSQL_PORT, PortRanges.fromInteger(9112)));
 
 
-        startInLocation(tapp, db1, db2, new LocalhostMachineProvisioningLocation());
+        startInLocation(app, db1, db2, new LocalhostMachineProvisioningLocation());
         testReplication(db1, db2);
     }
 
@@ -370,29 +352,29 @@ public class RubyRepIntegrationTest {
         String createTwoDbsScript = PostgreSqlIntegrationTest.CREATION_SCRIPT +
                 PostgreSqlIntegrationTest.CREATION_SCRIPT.replaceAll("CREATE USER.*", "").replaceAll(" feedback", " feedback1");
 
-        PostgreSqlNode db1 = tapp.createAndManageChild(EntitySpec.create(PostgreSqlNode.class)
+        PostgreSqlNode db1 = app.createAndManageChild(EntitySpec.create(PostgreSqlNode.class)
                 .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, createTwoDbsScript)
                 .configure(PostgreSqlNode.POSTGRESQL_PORT, PortRanges.fromInteger(9113))
                 .configure(PostgreSqlNode.MAX_CONNECTIONS, 10)
                 .configure(PostgreSqlNode.SHARED_MEMORY, "512kB")); // Very low so kernel configuration not needed
 
-        startInLocation(tapp, db1, "feedback", db1, "feedback1", new LocalhostMachineProvisioningLocation());
+        startInLocation(app, db1, "feedback", db1, "feedback1", new LocalhostMachineProvisioningLocation());
         testReplication(db1, "feedback", db1, "feedback1");
     }
 
     @Test(enabled = false, groups = "Integration") // TODO this doesn't appear to be supported by RubyRep
     public void test_localhost_postgres_mysql() throws Exception {
-        PostgreSqlNode db1 = tapp.createAndManageChild(EntitySpec.create(PostgreSqlNode.class)
+        PostgreSqlNode db1 = app.createAndManageChild(EntitySpec.create(PostgreSqlNode.class)
                 .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, PostgreSqlIntegrationTest.CREATION_SCRIPT)
                 .configure(PostgreSqlNode.POSTGRESQL_PORT, PortRanges.fromInteger(9115))
                 .configure(PostgreSqlNode.MAX_CONNECTIONS, 10)
                 .configure(PostgreSqlNode.SHARED_MEMORY, "512kB")); // Very low so kernel configuration not needed
 
-        MySqlNode db2 = tapp.createAndManageChild(EntitySpec.create(MySqlNode.class)
+        MySqlNode db2 = app.createAndManageChild(EntitySpec.create(MySqlNode.class)
                 .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, MySqlIntegrationTest.CREATION_SCRIPT)
                 .configure(MySqlNode.MYSQL_PORT, PortRanges.fromInteger(9116)));
 
-        startInLocation(tapp, db1, db2, new LocalhostMachineProvisioningLocation());
+        startInLocation(app, db1, db2, new LocalhostMachineProvisioningLocation());
         testReplication(db1, db2);
     }
 

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4fbe6f01/software/database/src/test/java/org/apache/brooklyn/entity/database/rubyrep/RubyRepRackspaceLiveTest.java
----------------------------------------------------------------------
diff --git a/software/database/src/test/java/org/apache/brooklyn/entity/database/rubyrep/RubyRepRackspaceLiveTest.java b/software/database/src/test/java/org/apache/brooklyn/entity/database/rubyrep/RubyRepRackspaceLiveTest.java
index 93e5cc3..3efb39f 100644
--- a/software/database/src/test/java/org/apache/brooklyn/entity/database/rubyrep/RubyRepRackspaceLiveTest.java
+++ b/software/database/src/test/java/org/apache/brooklyn/entity/database/rubyrep/RubyRepRackspaceLiveTest.java
@@ -22,6 +22,7 @@ import java.util.Arrays;
 
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.core.internal.BrooklynProperties;
 import org.apache.brooklyn.core.location.PortRanges;
 import org.testng.annotations.Test;
 import org.apache.brooklyn.entity.database.DatastoreMixins.DatastoreCommon;
@@ -83,20 +84,21 @@ public class RubyRepRackspaceLiveTest extends RubyRepIntegrationTest {
     }
 
     public void test(String osRegex) throws Exception {
-        PostgreSqlNode db1 = tapp.createAndManageChild(EntitySpec.create(PostgreSqlNode.class)
+        PostgreSqlNode db1 = app.createAndManageChild(EntitySpec.create(PostgreSqlNode.class)
                 .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, PostgreSqlIntegrationTest.CREATION_SCRIPT)
                 .configure(PostgreSqlNode.POSTGRESQL_PORT, PortRanges.fromInteger(9111)));
-        PostgreSqlNode db2 = tapp.createAndManageChild(EntitySpec.create(PostgreSqlNode.class)
+        PostgreSqlNode db2 = app.createAndManageChild(EntitySpec.create(PostgreSqlNode.class)
                 .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, PostgreSqlIntegrationTest.CREATION_SCRIPT)
                 .configure(PostgreSqlNode.POSTGRESQL_PORT, PortRanges.fromInteger(9111)));
 
+        BrooklynProperties brooklynProperties = mgmt.getBrooklynProperties();
         brooklynProperties.put("brooklyn.location.jclouds.rackspace-cloudservers-uk.imageNameRegex", osRegex);
         brooklynProperties.remove("brooklyn.location.jclouds.rackspace-cloudservers-uk.image-id");
         brooklynProperties.remove("brooklyn.location.jclouds.rackspace-cloudservers-uk.imageId");
         brooklynProperties.put("brooklyn.location.jclouds.rackspace-cloudservers-uk.inboundPorts", Arrays.asList(22, 9111));
-        Location loc = managementContext.getLocationRegistry().getLocationManaged("jclouds:rackspace-cloudservers-uk");
+        Location loc = mgmt.getLocationRegistry().getLocationManaged("jclouds:rackspace-cloudservers-uk");
         
-        startInLocation(tapp, db1, db2, loc);
+        startInLocation(app, db1, db2, loc);
 
         //hack to get the port for mysql open; is the inbounds property not respected on rackspace??
         for (DatastoreCommon node : ImmutableSet.of(db1, db2)) {

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4fbe6f01/software/messaging/src/test/java/org/apache/brooklyn/entity/messaging/activemq/ActiveMQIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/messaging/src/test/java/org/apache/brooklyn/entity/messaging/activemq/ActiveMQIntegrationTest.java b/software/messaging/src/test/java/org/apache/brooklyn/entity/messaging/activemq/ActiveMQIntegrationTest.java
index dec2b4f..3030800 100644
--- a/software/messaging/src/test/java/org/apache/brooklyn/entity/messaging/activemq/ActiveMQIntegrationTest.java
+++ b/software/messaging/src/test/java/org/apache/brooklyn/entity/messaging/activemq/ActiveMQIntegrationTest.java
@@ -33,17 +33,14 @@ import javax.jms.TextMessage;
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityAsserts;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
 import org.apache.brooklyn.core.entity.trait.Startable;
-import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.core.test.BrooklynAppLiveTestSupport;
 import org.apache.brooklyn.entity.java.UsesJmx;
 import org.apache.brooklyn.entity.java.UsesJmx.JmxAgentModes;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
@@ -53,24 +50,21 @@ import com.google.common.collect.ImmutableMap;
 /**
  * Test the operation of the {@link ActiveMQBroker} class.
  */
-public class ActiveMQIntegrationTest {
+// TODO Does it really need to be a live test? When converting from ApplicationBuilder, preserved
+// existing behaviour of using the live BrooklynProperties.
+public class ActiveMQIntegrationTest extends BrooklynAppLiveTestSupport {
     private static final Logger log = LoggerFactory.getLogger(ActiveMQIntegrationTest.class);
 
-    private TestApplication app;
     private Location testLocation;
     private ActiveMQBroker activeMQ;
 
     @BeforeMethod(alwaysRun = true)
-    public void setup() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         testLocation = app.newLocalhostProvisioningLocation();
     }
 
-    @AfterMethod(alwaysRun = true)
-    public void shutdown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-
     /**
      * Test that the broker starts up and sets SERVICE_UP correctly.
      */

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4fbe6f01/software/messaging/src/test/java/org/apache/brooklyn/entity/messaging/kafka/KafkaIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/messaging/src/test/java/org/apache/brooklyn/entity/messaging/kafka/KafkaIntegrationTest.java b/software/messaging/src/test/java/org/apache/brooklyn/entity/messaging/kafka/KafkaIntegrationTest.java
index 51d814e..d503832 100644
--- a/software/messaging/src/test/java/org/apache/brooklyn/entity/messaging/kafka/KafkaIntegrationTest.java
+++ b/software/messaging/src/test/java/org/apache/brooklyn/entity/messaging/kafka/KafkaIntegrationTest.java
@@ -26,20 +26,16 @@ import java.util.concurrent.Callable;
 
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityAsserts;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
 import org.apache.brooklyn.core.entity.trait.Startable;
-import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.core.test.BrooklynAppLiveTestSupport;
 import org.apache.brooklyn.test.Asserts;
 import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.time.Duration;
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 import org.apache.brooklyn.entity.messaging.activemq.ActiveMQBroker;
-import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
@@ -49,21 +45,17 @@ import com.google.common.collect.ImmutableMap;
  *
  * TODO test that sensors update.
  */
-public class KafkaIntegrationTest {
+//TODO Does it really need to be a live test? When converting from ApplicationBuilder, preserved
+//existing behaviour of using the live BrooklynProperties.
+public class KafkaIntegrationTest extends BrooklynAppLiveTestSupport {
 
-    private TestApplication app;
     private Location testLocation;
 
     @BeforeMethod(alwaysRun = true)
-    public void setup() {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-        LocationSpec<LocalhostMachineProvisioningLocation> locationSpec = LocationSpec.create(LocalhostMachineProvisioningLocation.class);
-        testLocation = app.getManagementContext().getLocationManager().createLocation(locationSpec);
-    }
-
-    @AfterMethod(alwaysRun = true)
-    public void shutdown() {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        testLocation = app.newLocalhostProvisioningLocation();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4fbe6f01/software/messaging/src/test/java/org/apache/brooklyn/entity/messaging/qpid/QpidIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/messaging/src/test/java/org/apache/brooklyn/entity/messaging/qpid/QpidIntegrationTest.java b/software/messaging/src/test/java/org/apache/brooklyn/entity/messaging/qpid/QpidIntegrationTest.java
index 56d22e2..b2f7a49 100644
--- a/software/messaging/src/test/java/org/apache/brooklyn/entity/messaging/qpid/QpidIntegrationTest.java
+++ b/software/messaging/src/test/java/org/apache/brooklyn/entity/messaging/qpid/QpidIntegrationTest.java
@@ -36,11 +36,9 @@ import javax.jms.TextMessage;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.Location;
 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.factory.ApplicationBuilder;
 import org.apache.brooklyn.core.entity.trait.Startable;
-import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.core.test.BrooklynAppLiveTestSupport;
 import org.apache.brooklyn.entity.software.base.SoftwareProcess;
 import org.apache.brooklyn.test.Asserts;
 import org.apache.brooklyn.test.HttpTestUtils;
@@ -50,7 +48,6 @@ import org.apache.qpid.client.AMQConnectionFactory;
 import org.apache.qpid.configuration.ClientProperties;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
@@ -59,26 +56,23 @@ import com.google.common.collect.ImmutableList;
 /**
  * Test the operation of the {@link QpidBroker} class.
  */
-public class QpidIntegrationTest {
+// TODO Does it really need to be a live test? When converting from ApplicationBuilder, preserved
+// existing behaviour of using the live BrooklynProperties.
+public class QpidIntegrationTest extends BrooklynAppLiveTestSupport {
     private static final Logger log = LoggerFactory.getLogger(QpidIntegrationTest.class);
 
-    private TestApplication app;
     private Location testLocation;
     private QpidBroker qpid;
 
     @BeforeMethod(groups = "Integration")
-    public void setup() {
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         String workingDir = System.getProperty("user.dir");
         log.info("Qpid working dir: {}", workingDir);
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
         testLocation = app.newLocalhostProvisioningLocation();
     }
 
-    @AfterMethod(alwaysRun=true)
-    public void shutdown() {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-
     /**
      * Test that the broker starts up with JMX and RMI ports configured, and sets SERVICE_UP correctly.
      */

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4fbe6f01/software/messaging/src/test/java/org/apache/brooklyn/entity/messaging/rabbit/RabbitIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/messaging/src/test/java/org/apache/brooklyn/entity/messaging/rabbit/RabbitIntegrationTest.java b/software/messaging/src/test/java/org/apache/brooklyn/entity/messaging/rabbit/RabbitIntegrationTest.java
index bba1f18..c800f7a 100644
--- a/software/messaging/src/test/java/org/apache/brooklyn/entity/messaging/rabbit/RabbitIntegrationTest.java
+++ b/software/messaging/src/test/java/org/apache/brooklyn/entity/messaging/rabbit/RabbitIntegrationTest.java
@@ -25,19 +25,15 @@ import java.io.IOException;
 
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityAsserts;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
 import org.apache.brooklyn.core.entity.trait.Startable;
-import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.core.test.BrooklynAppLiveTestSupport;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 import org.apache.brooklyn.entity.messaging.MessageBroker;
 import org.apache.brooklyn.entity.messaging.amqp.AmqpExchange;
-import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
 
 import com.google.common.base.Charsets;
 import com.google.common.collect.ImmutableList;
@@ -62,22 +58,19 @@ import com.rabbitmq.client.QueueingConsumer;
  *      ERROR: epmd error for host "Aleds-MacBook-Pro": timeout (timed out establishing tcp connection)
  *    I got around that with disabling my wifi and running when not connected to the internet.
  */
-public class RabbitIntegrationTest {
+// TODO Does it really need to be a live test? When converting from ApplicationBuilder, preserved
+// existing behaviour of using the live BrooklynProperties.
+public class RabbitIntegrationTest extends BrooklynAppLiveTestSupport {
     private static final Logger log = LoggerFactory.getLogger(RabbitIntegrationTest.class);
 
-    private TestApplication app;
     private Location testLocation;
     private RabbitBroker rabbit;
 
     @BeforeMethod(groups = "Integration")
-    public void setup() {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-        testLocation = new LocalhostMachineProvisioningLocation();
-    }
-
-    @AfterMethod(alwaysRun = true)
-    public void shutdown() {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        testLocation = app.newLocalhostProvisioningLocation();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4fbe6f01/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/couchdb/AbstractCouchDBNodeTest.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/couchdb/AbstractCouchDBNodeTest.java b/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/couchdb/AbstractCouchDBNodeTest.java
deleted file mode 100644
index 22d4bc6..0000000
--- a/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/couchdb/AbstractCouchDBNodeTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.entity.nosql.couchdb;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
-import org.apache.brooklyn.core.test.entity.TestApplication;
-import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
-
-/**
- * CouchDB test framework for integration and live tests.
- */
-public class AbstractCouchDBNodeTest {
-
-    private static final Logger log = LoggerFactory.getLogger(AbstractCouchDBNodeTest.class);
-
-    protected TestApplication app;
-    protected Location testLocation;
-    protected CouchDBNode couchdb;
-
-    @BeforeMethod(alwaysRun = true)
-    public void setup() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-        testLocation = new LocalhostMachineProvisioningLocation();
-        // testLocation = app.managementContext.locationRegistry.resolve("named:test");
-    }
-
-    @AfterMethod(alwaysRun = true)
-    public void shutdown() {
-        Entities.destroyAll(app.getManagementContext());
-    }
-}

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4fbe6f01/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBClusterLiveTest.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBClusterLiveTest.java b/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBClusterLiveTest.java
index 49e06e2..713a32c 100644
--- a/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBClusterLiveTest.java
+++ b/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBClusterLiveTest.java
@@ -24,10 +24,8 @@ import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityAsserts;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
 import org.apache.brooklyn.core.entity.trait.Startable;
-import org.apache.brooklyn.core.test.entity.TestApplication;
-import org.testng.annotations.AfterMethod;
+import org.apache.brooklyn.core.test.BrooklynAppLiveTestSupport;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
@@ -40,26 +38,21 @@ import com.google.common.collect.Iterables;
  * Tests that a two node cluster can be started on Amazon EC2 and data written on one {@link CouchDBNode}
  * can be read from another, using the Astyanax API.
  */
-public class CouchDBClusterLiveTest {
+public class CouchDBClusterLiveTest extends BrooklynAppLiveTestSupport {
 
     // private String provider = "rackspace-cloudservers-uk";
     private String provider = "aws-ec2:eu-west-1";
 
-    protected TestApplication app;
     protected Location testLocation;
     protected CouchDBCluster cluster;
 
     @BeforeMethod(alwaysRun = true)
-    public void setup() {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         testLocation = app.getManagementContext().getLocationRegistry().getLocationManaged(provider);
     }
 
-    @AfterMethod(alwaysRun = true)
-    public void shutdown() {
-        Entities.destroyAll(app.getManagementContext());
-    }
-
     /**
      * Test that a two node cluster starts up and allows access via the Astyanax API through both nodes.
      */

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4fbe6f01/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBNodeIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBNodeIntegrationTest.java b/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBNodeIntegrationTest.java
index 1872d94..6b74fe1 100644
--- a/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBNodeIntegrationTest.java
+++ b/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBNodeIntegrationTest.java
@@ -19,8 +19,10 @@
 package org.apache.brooklyn.entity.nosql.couchdb;
 
 import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.core.entity.EntityAsserts;
 import org.apache.brooklyn.core.entity.trait.Startable;
+import org.apache.brooklyn.core.test.BrooklynAppLiveTestSupport;
 import org.testng.annotations.Test;
 
 import com.google.common.collect.ImmutableList;
@@ -30,8 +32,19 @@ import com.google.common.collect.ImmutableList;
  *
  * Test the operation of the {@link CouchDBNode} class.
  */
-public class CouchDBNodeIntegrationTest extends AbstractCouchDBNodeTest {
+// TODO Does it really need to be a live test? When converting from ApplicationBuilder, preserved
+// existing behaviour of using the live BrooklynProperties.
+public class CouchDBNodeIntegrationTest extends BrooklynAppLiveTestSupport {
 
+    Location testLocation;
+    CouchDBNode couchdb;
+    
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        testLocation = app.newLocalhostProvisioningLocation();
+    }
+    
     /**
      * Test that a node starts and sets SERVICE_UP correctly.
      */

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4fbe6f01/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBNodeLiveTest.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBNodeLiveTest.java b/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBNodeLiveTest.java
index 7d0d50e..002612d 100644
--- a/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBNodeLiveTest.java
+++ b/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBNodeLiveTest.java
@@ -21,8 +21,10 @@ package org.apache.brooklyn.entity.nosql.couchdb;
 import java.util.Map;
 
 import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.core.entity.EntityAsserts;
 import org.apache.brooklyn.core.entity.trait.Startable;
+import org.apache.brooklyn.core.test.BrooklynAppLiveTestSupport;
 import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.text.Strings;
 import org.slf4j.Logger;
@@ -40,7 +42,7 @@ import com.google.common.collect.ImmutableList;
  * to exercise the node, and will need to have {@code brooklyn.jclouds.provider.identity} and {@code .credential}
  * set, usually in the {@code .brooklyn/brooklyn.properties} file.
  */
-public class CouchDBNodeLiveTest extends AbstractCouchDBNodeTest {
+public class CouchDBNodeLiveTest extends BrooklynAppLiveTestSupport {
 
     private static final Logger log = LoggerFactory.getLogger(CouchDBNodeLiveTest.class);
 
@@ -58,10 +60,10 @@ public class CouchDBNodeLiveTest extends AbstractCouchDBNodeTest {
         log.info("Testing CouchDB on {}{} using {} ({})", new Object[] { provider, Strings.isNonEmpty(region) ? ":" + region : "", description, imageId });
 
         Map<String, String> properties = MutableMap.of("imageId", imageId);
-        testLocation = app.getManagementContext().getLocationRegistry()
+        Location testLocation = app.getManagementContext().getLocationRegistry()
                 .getLocationManaged(provider + (Strings.isNonEmpty(region) ? ":" + region : ""), properties);
 
-        couchdb = app.createAndManageChild(EntitySpec.create(CouchDBNode.class)
+        CouchDBNode couchdb = app.createAndManageChild(EntitySpec.create(CouchDBNode.class)
                 .configure("httpPort", "12345+")
                 .configure("clusterName", "TestCluster"));
         app.start(ImmutableList.of(testLocation));

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4fbe6f01/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/mongodb/MongoDBIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/mongodb/MongoDBIntegrationTest.java b/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/mongodb/MongoDBIntegrationTest.java
index 60b2a76..1d5c61a 100644
--- a/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/mongodb/MongoDBIntegrationTest.java
+++ b/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/mongodb/MongoDBIntegrationTest.java
@@ -22,12 +22,9 @@ import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 
 import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityAsserts;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
 import org.apache.brooklyn.core.entity.trait.Startable;
-import org.apache.brooklyn.core.test.entity.TestApplication;
-import org.testng.annotations.AfterMethod;
+import org.apache.brooklyn.core.test.BrooklynAppLiveTestSupport;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
@@ -35,20 +32,17 @@ import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocati
 import com.google.common.collect.ImmutableList;
 import com.mongodb.DBObject;
 
-public class MongoDBIntegrationTest {
+// TODO Does it really need to be a live test? When converting from ApplicationBuilder, preserved
+// existing behaviour of using the live BrooklynProperties.
+public class MongoDBIntegrationTest extends BrooklynAppLiveTestSupport {
 
-    private TestApplication app;
     private LocalhostMachineProvisioningLocation localhostProvisioningLocation;
 
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
-        localhostProvisioningLocation = new LocalhostMachineProvisioningLocation();
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-    }
-
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
+        super.setUp();
+        localhostProvisioningLocation = app.newLocalhostProvisioningLocation();
     }
 
     @Test(groups = "Integration")

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4fbe6f01/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/mongodb/MongoDBWinEc2LiveTest.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/mongodb/MongoDBWinEc2LiveTest.java b/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/mongodb/MongoDBWinEc2LiveTest.java
index fc5e9f2..801db9c 100644
--- a/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/mongodb/MongoDBWinEc2LiveTest.java
+++ b/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/mongodb/MongoDBWinEc2LiveTest.java
@@ -24,7 +24,6 @@ import org.apache.brooklyn.core.entity.Attributes;
 import org.apache.brooklyn.core.entity.BrooklynConfigKeys;
 import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityAsserts;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
 import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
 import org.apache.brooklyn.core.internal.BrooklynProperties;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
@@ -81,7 +80,7 @@ public class MongoDBWinEc2LiveTest {
     public void setUp() throws Exception {
         EntitySpec<TestApplication> appSpec = EntitySpec.create(TestApplication.class)
                 .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true);
-        app = ApplicationBuilder.newManagedApp(appSpec, mgmt);
+        app = mgmt.getEntityManager().createEntity(appSpec);
     }
 
     @AfterMethod(alwaysRun = true)

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4fbe6f01/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/mongodb/sharding/MongoDBConfigServerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/mongodb/sharding/MongoDBConfigServerIntegrationTest.java b/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/mongodb/sharding/MongoDBConfigServerIntegrationTest.java
index 9a36280..1fbb66f 100644
--- a/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/mongodb/sharding/MongoDBConfigServerIntegrationTest.java
+++ b/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/mongodb/sharding/MongoDBConfigServerIntegrationTest.java
@@ -21,36 +21,32 @@ package org.apache.brooklyn.entity.nosql.mongodb.sharding;
 import static org.testng.Assert.assertFalse;
 
 import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityAsserts;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
 import org.apache.brooklyn.core.entity.trait.Startable;
+import org.apache.brooklyn.core.test.BrooklynAppLiveTestSupport;
 import org.apache.brooklyn.core.test.entity.TestApplication;
 import org.apache.brooklyn.entity.nosql.mongodb.MongoDBServer;
 import org.apache.brooklyn.entity.nosql.mongodb.MongoDBTestHelper;
 import org.apache.brooklyn.test.Asserts;
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
 
 import com.google.common.collect.ImmutableList;
 
-public class MongoDBConfigServerIntegrationTest {
+// TODO Does it really need to be a live test? When converting from ApplicationBuilder, preserved
+// existing behaviour of using the live BrooklynProperties.
+public class MongoDBConfigServerIntegrationTest extends BrooklynAppLiveTestSupport {
     private TestApplication app;
     private LocalhostMachineProvisioningLocation localhostProvisioningLocation;
 
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
-        localhostProvisioningLocation = new LocalhostMachineProvisioningLocation();
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+        super.setUp();
+        localhostProvisioningLocation = app.newLocalhostProvisioningLocation();
     }
 
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-    
     @Test(groups = "Integration")
     public void testCanStartAndStop() throws Exception {
         MongoDBConfigServer entity = app.createAndManageChild(EntitySpec.create(MongoDBConfigServer.class)

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4fbe6f01/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/redis/RedisClusterIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/redis/RedisClusterIntegrationTest.java b/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/redis/RedisClusterIntegrationTest.java
index ca5fbc0..a42d5e3 100644
--- a/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/redis/RedisClusterIntegrationTest.java
+++ b/software/nosql/src/test/java/org/apache/brooklyn/entity/nosql/redis/RedisClusterIntegrationTest.java
@@ -26,35 +26,28 @@ import java.util.concurrent.Callable;
 
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityAsserts;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
 import org.apache.brooklyn.core.entity.trait.Startable;
-import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.core.test.BrooklynAppLiveTestSupport;
 import org.apache.brooklyn.entity.group.DynamicCluster;
 import org.apache.brooklyn.test.Asserts;
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
-import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
 
 import com.google.common.collect.ImmutableList;
 
-public class RedisClusterIntegrationTest {
+//TODO Does it really need to be a live test? When converting from ApplicationBuilder, preserved
+//existing behaviour of using the live BrooklynProperties.
+public class RedisClusterIntegrationTest extends BrooklynAppLiveTestSupport {
 
-    private TestApplication app;
     private Location loc;
     private RedisCluster cluster;
 
     @BeforeMethod(alwaysRun=true)
-    public void setup() {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-        loc = new LocalhostMachineProvisioningLocation();
-    }
-
-    @AfterMethod(alwaysRun=true)
-    public void shutdown() {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        loc = app.newLocalhostProvisioningLocation();
     }
 
     @Test(groups = { "Integration" })

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4fbe6f01/software/webapp/src/test/java/org/apache/brooklyn/entity/proxy/UrlMappingTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/org/apache/brooklyn/entity/proxy/UrlMappingTest.java b/software/webapp/src/test/java/org/apache/brooklyn/entity/proxy/UrlMappingTest.java
index d450f71..022d465 100644
--- a/software/webapp/src/test/java/org/apache/brooklyn/entity/proxy/UrlMappingTest.java
+++ b/software/webapp/src/test/java/org/apache/brooklyn/entity/proxy/UrlMappingTest.java
@@ -20,7 +20,6 @@ package org.apache.brooklyn.entity.proxy;
 
 import static org.testng.Assert.assertEquals;
 
-import java.io.File;
 import java.util.HashSet;
 
 import javax.annotation.Nullable;
@@ -30,10 +29,8 @@ import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.core.entity.Attributes;
 import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.entity.EntityInternal;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
-import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
-import org.apache.brooklyn.core.mgmt.rebind.RebindTestUtils;
+import org.apache.brooklyn.core.mgmt.rebind.RebindOptions;
+import org.apache.brooklyn.core.mgmt.rebind.RebindTestFixtureWithApp;
 import org.apache.brooklyn.core.test.entity.TestApplication;
 import org.apache.brooklyn.entity.group.DynamicCluster;
 import org.apache.brooklyn.entity.proxy.nginx.UrlMapping;
@@ -43,7 +40,6 @@ import org.apache.brooklyn.util.time.Duration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
@@ -54,50 +50,36 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Sets;
-import com.google.common.io.Files;
 
-public class UrlMappingTest {
+public class UrlMappingTest extends RebindTestFixtureWithApp {
     
     private static final Logger log = LoggerFactory.getLogger(UrlMappingTest.class);
     
     private final int initialClusterSize = 2;
     
-    private ClassLoader classLoader = getClass().getClassLoader();
-    private LocalManagementContext managementContext;
-    private File mementoDir;
-    
-    private TestApplication app;
     private DynamicCluster cluster;
     private UrlMapping urlMapping;
     
     @BeforeMethod(alwaysRun=true)
-    public void setup() {
-        mementoDir = Files.createTempDir();
-        managementContext = RebindTestUtils.newPersistingManagementContext(mementoDir, classLoader);
-
-        app = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext);
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         
         EntitySpec<StubAppServer> serverSpec = EntitySpec.create(StubAppServer.class);
-        cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
+        cluster = app().createAndManageChild(EntitySpec.create(DynamicCluster.class)
                 .configure(DynamicCluster.INITIAL_SIZE, initialClusterSize)
                 .configure(DynamicCluster.MEMBER_SPEC, serverSpec));
 
-        urlMapping = app.createAndManageChild(EntitySpec.create(UrlMapping.class)
+        urlMapping = app().createAndManageChild(EntitySpec.create(UrlMapping.class)
                 .configure("domain", "localhost")
                 .configure("target", cluster));
 
-        app.start( ImmutableList.of(
-                managementContext.getLocationManager().createLocation(
+        app().start( ImmutableList.of(
+                mgmt().getLocationManager().createLocation(
                         LocationSpec.create(LocalhostMachineProvisioningLocation.class))
                 ));
-        log.info("app's location managed: "+managementContext.getLocationManager().isManaged(Iterables.getOnlyElement(app.getLocations())));
-        log.info("clusters's location managed: "+managementContext.getLocationManager().isManaged(Iterables.getOnlyElement(cluster.getLocations())));
-    }
-
-    @AfterMethod(alwaysRun=true)
-    public void shutdown() {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-        if (mementoDir != null) RebindTestUtils.deleteMementoDir(mementoDir);
+        log.info("app's location managed: "+mgmt().getLocationManager().isManaged(Iterables.getOnlyElement(app().getLocations())));
+        log.info("clusters's location managed: "+mgmt().getLocationManager().isManaged(Iterables.getOnlyElement(cluster.getLocations())));
     }
 
     @Test(groups = "Integration")
@@ -150,9 +132,9 @@ public class UrlMappingTest {
         Iterable<StubAppServer> members = Iterables.filter(cluster.getChildren(), StubAppServer.class);
         assertExpectedTargetsEventually(members);
         
-        Assert.assertTrue(managementContext.getLocationManager().isManaged(Iterables.getOnlyElement(cluster.getLocations())));
+        Assert.assertTrue(mgmt().getLocationManager().isManaged(Iterables.getOnlyElement(cluster.getLocations())));
         rebind();
-        Assert.assertTrue(managementContext.getLocationManager().isManaged(Iterables.getOnlyElement(cluster.getLocations())),
+        Assert.assertTrue(mgmt().getLocationManager().isManaged(Iterables.getOnlyElement(cluster.getLocations())),
                 "location not managed after rebind");
         
         Iterable<StubAppServer> members2 = Iterables.filter(cluster.getChildren(), StubAppServer.class);
@@ -165,7 +147,7 @@ public class UrlMappingTest {
         // Add a new member; expect member to be added
         log.info("resizing "+cluster+" - "+cluster.getChildren());
         Integer result = cluster.resize(3);
-        Assert.assertTrue(managementContext.getLocationManager().isManaged(Iterables.getOnlyElement(cluster.getLocations())));
+        Assert.assertTrue(mgmt().getLocationManager().isManaged(Iterables.getOnlyElement(cluster.getLocations())));
         log.info("resized "+cluster+" ("+result+") - "+cluster.getChildren());
         HashSet<StubAppServer> newEntities = Sets.newHashSet(Iterables.filter(cluster.getChildren(), StubAppServer.class));
         newEntities.remove(target1);
@@ -200,15 +182,13 @@ public class UrlMappingTest {
             }});
     }
     
-    private void rebind() throws Exception {
-        RebindTestUtils.waitForPersisted(app);
+    @Override
+    protected TestApplication rebind(RebindOptions options) throws Exception {
+        TestApplication result = super.rebind(options);
         
-        // Stop the old management context, so original nginx won't interfere
-        managementContext.terminate();
+        cluster = (DynamicCluster) Iterables.find(app().getChildren(), Predicates.instanceOf(DynamicCluster.class));
+        urlMapping = (UrlMapping) Iterables.find(app().getChildren(), Predicates.instanceOf(UrlMapping.class));
         
-        app = (TestApplication) RebindTestUtils.rebind(mementoDir, getClass().getClassLoader());
-        managementContext = (LocalManagementContext) ((EntityInternal)app).getManagementContext();
-        cluster = (DynamicCluster) Iterables.find(app.getChildren(), Predicates.instanceOf(DynamicCluster.class));
-        urlMapping = (UrlMapping) Iterables.find(app.getChildren(), Predicates.instanceOf(UrlMapping.class));
+        return result;
     }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4fbe6f01/software/webapp/src/test/java/org/apache/brooklyn/entity/proxy/nginx/NginxWebClusterEc2LiveTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/org/apache/brooklyn/entity/proxy/nginx/NginxWebClusterEc2LiveTest.java b/software/webapp/src/test/java/org/apache/brooklyn/entity/proxy/nginx/NginxWebClusterEc2LiveTest.java
index b70f290..253f691 100644
--- a/software/webapp/src/test/java/org/apache/brooklyn/entity/proxy/nginx/NginxWebClusterEc2LiveTest.java
+++ b/software/webapp/src/test/java/org/apache/brooklyn/entity/proxy/nginx/NginxWebClusterEc2LiveTest.java
@@ -26,11 +26,9 @@ import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.location.MachineLocation;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
+import org.apache.brooklyn.core.internal.BrooklynProperties;
 import org.apache.brooklyn.core.location.Machines;
-import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.core.test.BrooklynAppLiveTestSupport;
 import org.apache.brooklyn.entity.group.DynamicCluster;
 import org.apache.brooklyn.entity.proxy.nginx.NginxController;
 import org.apache.brooklyn.entity.webapp.JavaWebAppService;
@@ -41,12 +39,10 @@ import org.apache.brooklyn.test.HttpTestUtils;
 import org.apache.brooklyn.test.support.TestResourceUnavailableException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
 
 /**
  * Test Nginx proxying a cluster of JBoss7Server entities on AWS for ENGR-1689.
@@ -54,26 +50,27 @@ import com.google.common.collect.ImmutableMap;
  * This test is a proof-of-concept for the Brooklyn demo application, with each
  * service running on a separate Amazon EC2 instance.
  */
-public class NginxWebClusterEc2LiveTest {
+public class NginxWebClusterEc2LiveTest extends BrooklynAppLiveTestSupport {
+    @SuppressWarnings("unused")
     private static final Logger LOG = LoggerFactory.getLogger(NginxWebClusterEc2LiveTest.class);
     
-    private TestApplication app;
     private NginxController nginx;
     private DynamicCluster cluster;
     private Location loc;
 
     @BeforeMethod(alwaysRun = true)
-    public void setUp() {
-        ManagementContext managementContext = Entities.newManagementContext(
-                ImmutableMap.of("brooklyn.location.jclouds.aws-ec2.image-id", "us-east-1/ami-2342a94a"));
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         
-        loc = managementContext.getLocationRegistry().getLocationManaged("aws-ec2:us-east-1");
-        app = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext);
+        loc = mgmt.getLocationRegistry().getLocationManaged("aws-ec2:us-east-1");
     }
 
-    @AfterMethod(alwaysRun = true)
-    public void shutdown() {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
+    @Override
+    protected BrooklynProperties getBrooklynProperties() {
+        BrooklynProperties result = BrooklynProperties.Factory.newDefault();
+        result.put("brooklyn.location.jclouds.aws-ec2.image-id", "us-east-1/ami-2342a94a");
+        return result;
     }
 
     @Test(groups = "Live")

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4fbe6f01/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/AbstractWebAppFixtureIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/AbstractWebAppFixtureIntegrationTest.java b/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/AbstractWebAppFixtureIntegrationTest.java
index a488eb9..c5fef08 100644
--- a/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/AbstractWebAppFixtureIntegrationTest.java
+++ b/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/AbstractWebAppFixtureIntegrationTest.java
@@ -39,6 +39,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.brooklyn.api.entity.Application;
 import org.apache.brooklyn.api.entity.Entity;
+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.api.mgmt.SubscriptionHandle;
@@ -48,7 +49,6 @@ import org.apache.brooklyn.api.sensor.SensorEvent;
 import org.apache.brooklyn.api.sensor.SensorEventListener;
 import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityAsserts;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
 import org.apache.brooklyn.core.entity.trait.Startable;
 import org.apache.brooklyn.core.internal.BrooklynProperties;
 import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
@@ -175,7 +175,7 @@ public abstract class AbstractWebAppFixtureIntegrationTest {
      * @return
      */
     protected TestApplication newTestApplication() {
-        TestApplication ta = ApplicationBuilder.newManagedApp(TestApplication.class, getMgmt());
+        TestApplication ta = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class));
         applications.add(ta);
         return ta;
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4fbe6f01/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/jboss/ControlledDynamicWebAppClusterRebindIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/jboss/ControlledDynamicWebAppClusterRebindIntegrationTest.java b/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/jboss/ControlledDynamicWebAppClusterRebindIntegrationTest.java
index eb55120..beb9058 100644
--- a/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/jboss/ControlledDynamicWebAppClusterRebindIntegrationTest.java
+++ b/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/jboss/ControlledDynamicWebAppClusterRebindIntegrationTest.java
@@ -22,7 +22,6 @@ import static org.apache.brooklyn.test.HttpTestUtils.assertHttpStatusCodeEquals;
 import static org.apache.brooklyn.test.HttpTestUtils.assertHttpStatusCodeEventuallyEquals;
 import static org.testng.Assert.assertEquals;
 
-import java.io.File;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.ExecutorService;
@@ -30,12 +29,8 @@ import java.util.concurrent.Executors;
 
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityAsserts;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
-import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
-import org.apache.brooklyn.core.mgmt.rebind.RebindTestUtils;
-import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.core.mgmt.rebind.RebindTestFixtureWithApp;
 import org.apache.brooklyn.entity.proxy.nginx.NginxController;
 import org.apache.brooklyn.entity.software.base.SoftwareProcess;
 import org.apache.brooklyn.entity.webapp.ControlledDynamicWebAppCluster;
@@ -51,42 +46,33 @@ import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocati
 import com.google.common.base.Predicates;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
-import com.google.common.io.Files;
 
-public class ControlledDynamicWebAppClusterRebindIntegrationTest {
+public class ControlledDynamicWebAppClusterRebindIntegrationTest extends RebindTestFixtureWithApp {
     private static final Logger LOG = LoggerFactory.getLogger(ControlledDynamicWebAppClusterRebindIntegrationTest.class);
     
     private LocalhostMachineProvisioningLocation localhostProvisioningLocation;
-    private TestApplication origApp;
-    private TestApplication newApp;
     private List<WebAppMonitor> webAppMonitors = new CopyOnWriteArrayList<WebAppMonitor>();
     private ExecutorService executor;
     
-    private ClassLoader classLoader = getClass().getClassLoader();
-    private LocalManagementContext origManagementContext;
-    private File mementoDir;
-    
     @BeforeMethod(alwaysRun=true)
-    public void setUp() {
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         executor = Executors.newCachedThreadPool();
-
-        mementoDir = Files.createTempDir();
-        LOG.info("Test persisting to "+mementoDir);
-        origManagementContext = RebindTestUtils.newPersistingManagementContext(mementoDir, classLoader);
-
-        localhostProvisioningLocation = new LocalhostMachineProvisioningLocation();
-        origApp = ApplicationBuilder.newManagedApp(TestApplication.class, origManagementContext);
+        localhostProvisioningLocation = app().newLocalhostProvisioningLocation();
     }
 
     @AfterMethod(alwaysRun=true)
+    @Override
     public void tearDown() throws Exception {
-        for (WebAppMonitor monitor : webAppMonitors) {
-            monitor.terminate();
+        try {
+            for (WebAppMonitor monitor : webAppMonitors) {
+                monitor.terminate();
+            }
+            if (executor != null) executor.shutdownNow();
+        } finally {
+            super.tearDown();
         }
-        if (executor != null) executor.shutdownNow();
-        if (newApp != null) Entities.destroyAll(newApp.getManagementContext());
-        if (origApp != null) Entities.destroyAll(origApp.getManagementContext());
-        if (mementoDir != null) RebindTestUtils.deleteMementoDir(mementoDir);
     }
 
     public String getTestWar() {
@@ -94,15 +80,6 @@ public class ControlledDynamicWebAppClusterRebindIntegrationTest {
         return "classpath://hello-world.war";
     }
 
-    private TestApplication rebind() throws Exception {
-        RebindTestUtils.waitForPersisted(origApp);
-        
-        // Stop the old management context, so original nginx won't interfere
-        origManagementContext.terminate();
-        
-        return (TestApplication) RebindTestUtils.rebind(mementoDir, getClass().getClassLoader());
-    }
-
     private WebAppMonitor newWebAppMonitor(String url) {
         WebAppMonitor monitor = new WebAppMonitor(url)
 //                .delayMillis(0)
@@ -153,23 +130,24 @@ public class ControlledDynamicWebAppClusterRebindIntegrationTest {
      */
     @Test(groups = {"Integration","Broken"})
     public void testRebindsToRunningCluster() throws Exception {
-        NginxController origNginx = origApp.createAndManageChild(EntitySpec.create(NginxController.class).configure("domain", "localhost"));
+        NginxController origNginx = app().createAndManageChild(EntitySpec.create(NginxController.class).configure("domain", "localhost"));
 
-        origApp.createAndManageChild(EntitySpec.create(ControlledDynamicWebAppCluster.class)
+        app().createAndManageChild(EntitySpec.create(ControlledDynamicWebAppCluster.class)
                 .configure("memberSpec", EntitySpec.create(JBoss7Server.class).configure("war", getTestWar()))
                 .configure("initialSize", 1)
                 .configure("controller", origNginx));
         
-        origApp.start(ImmutableList.of(localhostProvisioningLocation));
+        app().start(ImmutableList.of(localhostProvisioningLocation));
         String rootUrl = origNginx.getAttribute(JBoss7Server.ROOT_URL);
         
         assertHttpStatusCodeEventuallyEquals(rootUrl, 200);
         WebAppMonitor monitor = newWebAppMonitor(rootUrl);
         
         // Rebind
-        newApp = rebind();
-        NginxController newNginx = (NginxController) Iterables.find(newApp.getChildren(), Predicates.instanceOf(NginxController.class));
-        ControlledDynamicWebAppCluster newCluster = (ControlledDynamicWebAppCluster) Iterables.find(newApp.getChildren(), Predicates.instanceOf(ControlledDynamicWebAppCluster.class));
+        rebind();
+        
+        NginxController newNginx = (NginxController) Iterables.find(app().getChildren(), Predicates.instanceOf(NginxController.class));
+        ControlledDynamicWebAppCluster newCluster = (ControlledDynamicWebAppCluster) Iterables.find(app().getChildren(), Predicates.instanceOf(ControlledDynamicWebAppCluster.class));
 
         EntityAsserts.assertAttributeEqualsEventually(newNginx, SoftwareProcess.SERVICE_UP, true);
         assertHttpStatusCodeEquals(rootUrl, 200);

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/4fbe6f01/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/jboss/DynamicWebAppClusterRebindIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/jboss/DynamicWebAppClusterRebindIntegrationTest.java b/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/jboss/DynamicWebAppClusterRebindIntegrationTest.java
index 89a14fa..3a8042c 100644
--- a/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/jboss/DynamicWebAppClusterRebindIntegrationTest.java
+++ b/software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/jboss/DynamicWebAppClusterRebindIntegrationTest.java
@@ -23,7 +23,6 @@ import static org.apache.brooklyn.test.HttpTestUtils.assertHttpStatusCodeEventua
 import static org.apache.brooklyn.test.HttpTestUtils.assertUrlUnreachableEventually;
 import static org.testng.Assert.assertEquals;
 
-import java.io.File;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.ExecutorService;
@@ -31,11 +30,7 @@ import java.util.concurrent.Executors;
 
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
-import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
-import org.apache.brooklyn.core.mgmt.rebind.RebindTestUtils;
-import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.core.mgmt.rebind.RebindTestFixtureWithApp;
 import org.apache.brooklyn.entity.webapp.DynamicWebAppCluster;
 import org.apache.brooklyn.test.WebAppMonitor;
 import org.apache.brooklyn.test.support.TestResourceUnavailableException;
@@ -49,41 +44,33 @@ import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocati
 import com.google.common.base.Predicates;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
-import com.google.common.io.Files;
 
-public class DynamicWebAppClusterRebindIntegrationTest {
+public class DynamicWebAppClusterRebindIntegrationTest extends RebindTestFixtureWithApp {
     private static final Logger LOG = LoggerFactory.getLogger(DynamicWebAppClusterRebindIntegrationTest.class);
     
     private LocalhostMachineProvisioningLocation localhostProvisioningLocation;
-    private TestApplication origApp;
-    private TestApplication newApp;
     private List<WebAppMonitor> webAppMonitors = new CopyOnWriteArrayList<WebAppMonitor>();
     private ExecutorService executor;
     
-    private ClassLoader classLoader = getClass().getClassLoader();
-    private LocalManagementContext origManagementContext;
-    private File mementoDir;
-    
     @BeforeMethod(groups = "Integration")
-    public void setUp() {
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         executor = Executors.newCachedThreadPool();
-
-        mementoDir = Files.createTempDir();
-        origManagementContext = RebindTestUtils.newPersistingManagementContext(mementoDir, classLoader);
-
-        localhostProvisioningLocation = new LocalhostMachineProvisioningLocation();
-        origApp = ApplicationBuilder.newManagedApp(TestApplication.class, origManagementContext);
+        localhostProvisioningLocation = app().newLocalhostProvisioningLocation();
     }
 
     @AfterMethod(groups = "Integration", alwaysRun=true)
+    @Override
     public void tearDown() throws Exception {
-        for (WebAppMonitor monitor : webAppMonitors) {
-            monitor.terminate();
+        try {
+            for (WebAppMonitor monitor : webAppMonitors) {
+                monitor.terminate();
+            }
+            if (executor != null) executor.shutdownNow();
+        } finally {
+            super.tearDown();
         }
-        if (executor != null) executor.shutdownNow();
-        if (newApp != null) Entities.destroyAll(newApp.getManagementContext());
-        if (origApp != null) Entities.destroyAll(origApp.getManagementContext());
-        if (mementoDir != null) RebindTestUtils.deleteMementoDir(mementoDir);
     }
 
     public String getTestWar() {
@@ -91,15 +78,6 @@ public class DynamicWebAppClusterRebindIntegrationTest {
         return "classpath://hello-world.war";
     }
 
-    private TestApplication rebind() throws Exception {
-        RebindTestUtils.waitForPersisted(origApp);
-        
-        // Stop the old management context, so original nginx won't interfere
-        origManagementContext.terminate();
-        
-        return (TestApplication) RebindTestUtils.rebind(mementoDir, getClass().getClassLoader());
-    }
-
     private WebAppMonitor newWebAppMonitor(String url) {
         WebAppMonitor monitor = new WebAppMonitor(url)
 //                .delayMillis(0)
@@ -150,11 +128,11 @@ public class DynamicWebAppClusterRebindIntegrationTest {
      */
     @Test(groups = {"Integration","Broken"})
     public void testRebindsToRunningCluster() throws Exception {
-        DynamicWebAppCluster origCluster = origApp.createAndManageChild(EntitySpec.create(DynamicWebAppCluster.class)
+        DynamicWebAppCluster origCluster = app().createAndManageChild(EntitySpec.create(DynamicWebAppCluster.class)
                 .configure("memberSpec", EntitySpec.create(JBoss7Server.class).configure("war", getTestWar()))
                 .configure("initialSize", 1));
         
-        origApp.start(ImmutableList.of(localhostProvisioningLocation));
+        app().start(ImmutableList.of(localhostProvisioningLocation));
         JBoss7Server origJboss = (JBoss7Server) Iterables.find(origCluster.getChildren(), Predicates.instanceOf(JBoss7Server.class));
         String jbossUrl = origJboss.getAttribute(JBoss7Server.ROOT_URL);
         
@@ -162,8 +140,8 @@ public class DynamicWebAppClusterRebindIntegrationTest {
         WebAppMonitor monitor = newWebAppMonitor(jbossUrl);
         
         // Rebind
-        newApp = rebind();
-        DynamicWebAppCluster newCluster = (DynamicWebAppCluster) Iterables.find(newApp.getChildren(), Predicates.instanceOf(DynamicWebAppCluster.class));
+        rebind();
+        DynamicWebAppCluster newCluster = (DynamicWebAppCluster) Iterables.find(app().getChildren(), Predicates.instanceOf(DynamicWebAppCluster.class));
 
         assertHttpStatusCodeEquals(jbossUrl, 200);
 


Mime
View raw message