brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [3/4] git commit: Extend BrooklynAppUnitTestSupport in core tests
Date Tue, 01 Jul 2014 14:32:10 GMT
Extend BrooklynAppUnitTestSupport in core tests


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

Branch: refs/heads/master
Commit: 1207bc13d9dc24bc1f41262ed77ec42477be6708
Parents: f4a4c7b
Author: Aled Sage <aled.sage@gmail.com>
Authored: Fri Jun 20 12:19:39 2014 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Tue Jul 1 15:22:40 2014 +0100

----------------------------------------------------------------------
 .../enricher/CustomAggregatingEnricherTest.java | 19 +++----
 .../java/brooklyn/enricher/EnrichersTest.java   | 17 ++-----
 ...SensorPropagatingEnricherDeprecatedTest.java | 16 ++----
 .../enricher/SensorPropagatingEnricherTest.java | 16 ++----
 .../enricher/TransformingEnricherTest.java      | 20 +++-----
 .../brooklyn/entity/EffectorMetadataTest.java   | 17 ++-----
 .../java/brooklyn/entity/EffectorSayHiTest.java | 29 +++--------
 .../basic/AbstractApplicationLegacyTest.java    | 19 ++-----
 .../entity/basic/BrooklynShutdownHooksTest.java | 27 ++++------
 .../brooklyn/entity/basic/ConfigMapTest.java    | 53 +++++++++++---------
 .../basic/DependentConfigurationTest.java       | 16 ++----
 .../brooklyn/entity/basic/EntitiesTest.java     | 14 ++----
 .../basic/EntityConfigMapUsageLegacyTest.java   | 18 +------
 .../entity/basic/EntityConfigMapUsageTest.java  | 18 +++----
 .../entity/basic/EntityFunctionsTest.java       | 16 ++----
 .../entity/basic/EntityLocationsTest.java       | 18 +------
 .../entity/basic/EntityPredicatesTest.java      | 16 ++----
 .../entity/basic/EntityRegistrationTest.java    | 16 ++----
 .../brooklyn/entity/basic/EntitySpecTest.java   | 18 ++-----
 .../brooklyn/entity/basic/EntityTypeTest.java   | 16 ++----
 .../basic/MapConfigKeyAndFriendsMoreTest.java   | 16 ++----
 .../entity/basic/PolicyRegistrationTest.java    | 16 ++----
 .../downloads/DownloadSubstitutersTest.java     | 16 ++----
 .../entity/effector/EffectorBasicTest.java      | 17 ++-----
 .../entity/effector/EffectorTaskTest.java       | 19 +------
 .../entity/group/DynamicClusterTest.java        | 19 +++----
 ...DynamicClusterWithAvailabilityZonesTest.java | 15 +++---
 .../entity/group/DynamicFabricTest.java         | 15 ++----
 .../entity/group/DynamicRegionsFabricTest.java  | 16 ++----
 .../entity/group/GroupPickUpEntitiesTest.java   | 17 ++-----
 .../group/MembershipTrackingPolicyTest.java     | 17 ++-----
 .../entity/group/QuarantineGroupTest.java       | 17 ++-----
 .../BalancingNodePlacementStrategyTest.java     | 26 +++-------
 .../ProportionalZoneFailureDetectorTest.java    | 24 +++------
 .../entity/hello/LocalEntitiesTest.java         | 19 +++----
 .../entity/proxying/EntityManagerTest.java      | 17 ++-----
 .../entity/proxying/EntityProxyTest.java        | 23 +++------
 .../entity/trait/StartableMethodsTest.java      | 17 ++-----
 .../java/brooklyn/event/feed/PollerTest.java    | 13 +++--
 .../event/feed/function/FunctionFeedTest.java   | 13 +++--
 .../feed/http/HttpFeedIntegrationTest.java      | 13 +++--
 .../brooklyn/event/feed/http/HttpFeedTest.java  | 12 ++---
 .../feed/shell/ShellFeedIntegrationTest.java    | 13 +++--
 .../event/feed/ssh/SshFeedIntegrationTest.java  | 13 +++--
 .../location/basic/LocationManagementTest.java  | 25 +++------
 .../internal/LocalSubscriptionManagerTest.java  | 17 ++-----
 .../policy/basic/EnricherConfigTest.java        | 20 +-------
 .../policy/basic/PolicyConfigMapUsageTest.java  | 20 +-------
 .../test/java/brooklyn/util/task/TasksTest.java | 15 ++----
 49 files changed, 268 insertions(+), 631 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/enricher/CustomAggregatingEnricherTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/enricher/CustomAggregatingEnricherTest.java b/core/src/test/java/brooklyn/enricher/CustomAggregatingEnricherTest.java
index 4a7303a..7413cfa 100644
--- a/core/src/test/java/brooklyn/enricher/CustomAggregatingEnricherTest.java
+++ b/core/src/test/java/brooklyn/enricher/CustomAggregatingEnricherTest.java
@@ -4,12 +4,11 @@ import java.util.Collection;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.Entity;
-import brooklyn.entity.basic.ApplicationBuilder;
 import brooklyn.entity.basic.BasicGroup;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.proxying.EntitySpec;
@@ -18,7 +17,6 @@ import brooklyn.event.basic.BasicAttributeSensor;
 import brooklyn.location.LocationSpec;
 import brooklyn.location.basic.SimulatedLocation;
 import brooklyn.test.EntityTestUtils;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableMap;
 
@@ -27,14 +25,13 @@ import com.google.common.base.Predicates;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 
-public class CustomAggregatingEnricherTest {
+public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport {
 
     public static final Logger log = LoggerFactory.getLogger(CustomAggregatingEnricherTest.class);
             
     private static final long TIMEOUT_MS = 10*1000;
     private static final long SHORT_WAIT_MS = 250;
     
-    TestApplication app;
     TestEntity entity;
     SimulatedLocation loc;
     
@@ -43,21 +40,17 @@ public class CustomAggregatingEnricherTest {
     AttributeSensor<Integer> target;
 
     @BeforeMethod(alwaysRun=true)
-    public void setUp() {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         intSensor = new BasicAttributeSensor<Integer>(Integer.class, "int sensor");
         doubleSensor = new BasicAttributeSensor<Double>(Double.class, "double sensor");
         target = new BasicAttributeSensor<Integer>(Integer.class, "target sensor");
-        loc = app.getManagementContext().getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
+        loc = mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
         app.start(ImmutableList.of(loc));
     }
     
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() {
-        if (app!=null) Entities.destroyAll(app.getManagementContext());
-    }
-    
     @Test
     public void testSummingEnricherWithNoProducersDefaultsToNull() {
         entity.addEnricher(Enrichers.builder()

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/enricher/EnrichersTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/enricher/EnrichersTest.java b/core/src/test/java/brooklyn/enricher/EnrichersTest.java
index 8924607..9ad2c59 100644
--- a/core/src/test/java/brooklyn/enricher/EnrichersTest.java
+++ b/core/src/test/java/brooklyn/enricher/EnrichersTest.java
@@ -3,11 +3,10 @@ package brooklyn.enricher;
 import java.util.Collection;
 import java.util.Set;
 
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-import brooklyn.entity.basic.ApplicationBuilder;
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.basic.BasicGroup;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.proxying.EntitySpec;
@@ -15,7 +14,6 @@ import brooklyn.event.AttributeSensor;
 import brooklyn.event.SensorEvent;
 import brooklyn.event.basic.Sensors;
 import brooklyn.test.EntityTestUtils;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableSet;
 import brooklyn.util.guava.TypeTokens;
@@ -29,7 +27,7 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.reflect.TypeToken;
 
-public class EnrichersTest {
+public class EnrichersTest extends BrooklynAppUnitTestSupport {
 
     public static final AttributeSensor<Integer> NUM1 = Sensors.newIntegerSensor("test.num1");
     public static final AttributeSensor<Integer> NUM2 = Sensors.newIntegerSensor("test.num2");
@@ -39,24 +37,19 @@ public class EnrichersTest {
     public static final AttributeSensor<Set<Object>> SET1 = Sensors.newSensor(new TypeToken<Set<Object>>() {}, "test.set1", "set1 descr");
     public static final AttributeSensor<Long> LONG1 = Sensors.newLongSensor("test.long1");
     
-    private TestApplication app;
     private TestEntity entity;
     private TestEntity entity2;
     private BasicGroup group;
     
     @BeforeMethod(alwaysRun=true)
-    public void setUp() {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         entity2 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         group = app.createAndManageChild(EntitySpec.create(BasicGroup.class));
     }
     
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-
     @Test
     public void testAdding() {
         entity.addEnricher(Enrichers.builder()

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/enricher/SensorPropagatingEnricherDeprecatedTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/enricher/SensorPropagatingEnricherDeprecatedTest.java b/core/src/test/java/brooklyn/enricher/SensorPropagatingEnricherDeprecatedTest.java
index da9c083..45eee06 100644
--- a/core/src/test/java/brooklyn/enricher/SensorPropagatingEnricherDeprecatedTest.java
+++ b/core/src/test/java/brooklyn/enricher/SensorPropagatingEnricherDeprecatedTest.java
@@ -2,13 +2,11 @@ package brooklyn.enricher;
 
 import java.util.concurrent.atomic.AtomicReference;
 
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import brooklyn.enricher.basic.SensorPropagatingEnricher;
-import brooklyn.entity.basic.ApplicationBuilder;
-import brooklyn.entity.basic.Entities;
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.event.AttributeSensor;
 import brooklyn.event.SensorEvent;
@@ -16,7 +14,6 @@ import brooklyn.event.SensorEventListener;
 import brooklyn.event.basic.Sensors;
 import brooklyn.test.Asserts;
 import brooklyn.test.EntityTestUtils;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.javalang.AtomicReferences;
@@ -24,22 +21,17 @@ import brooklyn.util.javalang.AtomicReferences;
 import com.google.common.base.Predicates;
 import com.google.common.collect.ImmutableMap;
 
-public class SensorPropagatingEnricherDeprecatedTest {
+public class SensorPropagatingEnricherDeprecatedTest extends BrooklynAppUnitTestSupport {
 
-    private TestApplication app;
     private TestEntity entity;
 
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+        super.setUp();
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
     }
     
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-    
     @Test
     public void testPropagatesSpecificSensor() {
         app.addEnricher(SensorPropagatingEnricher.newInstanceListeningTo(entity, TestEntity.NAME));

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/enricher/SensorPropagatingEnricherTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/enricher/SensorPropagatingEnricherTest.java b/core/src/test/java/brooklyn/enricher/SensorPropagatingEnricherTest.java
index b97363a..423c3c7 100644
--- a/core/src/test/java/brooklyn/enricher/SensorPropagatingEnricherTest.java
+++ b/core/src/test/java/brooklyn/enricher/SensorPropagatingEnricherTest.java
@@ -2,13 +2,11 @@ package brooklyn.enricher;
 
 import java.util.concurrent.atomic.AtomicReference;
 
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import brooklyn.enricher.basic.Propagator;
-import brooklyn.entity.basic.ApplicationBuilder;
-import brooklyn.entity.basic.Entities;
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.event.AttributeSensor;
 import brooklyn.event.SensorEvent;
@@ -18,7 +16,6 @@ import brooklyn.event.basic.Sensors;
 import brooklyn.policy.EnricherSpec;
 import brooklyn.test.Asserts;
 import brooklyn.test.EntityTestUtils;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.exceptions.Exceptions;
@@ -28,22 +25,17 @@ import com.google.common.base.Predicates;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 
-public class SensorPropagatingEnricherTest {
+public class SensorPropagatingEnricherTest extends BrooklynAppUnitTestSupport {
 
-    private TestApplication app;
     private TestEntity entity;
 
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+        super.setUp();
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
     }
     
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-    
     @Test
     public void testPropagatesSpecificSensor() {
         app.addEnricher(Enrichers.builder()

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/enricher/TransformingEnricherTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/enricher/TransformingEnricherTest.java b/core/src/test/java/brooklyn/enricher/TransformingEnricherTest.java
index 3078edf..53ed264 100644
--- a/core/src/test/java/brooklyn/enricher/TransformingEnricherTest.java
+++ b/core/src/test/java/brooklyn/enricher/TransformingEnricherTest.java
@@ -2,36 +2,33 @@ package brooklyn.enricher;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-import brooklyn.entity.basic.ApplicationBuilder;
-import brooklyn.entity.basic.Entities;
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.event.AttributeSensor;
 import brooklyn.event.basic.BasicAttributeSensor;
 import brooklyn.location.basic.SimulatedLocation;
 import brooklyn.test.EntityTestUtils;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.math.MathFunctions;
 
 import com.google.common.base.Function;
 import com.google.common.collect.ImmutableList;
 
-public class TransformingEnricherTest {
+public class TransformingEnricherTest extends BrooklynAppUnitTestSupport {
 
     public static final Logger log = LoggerFactory.getLogger(TransformingEnricherTest.class);
             
-    TestApplication app;
     TestEntity producer;
     AttributeSensor<Integer> intSensorA;
     AttributeSensor<Long> target;
 
-    @BeforeMethod()
-    public void before() {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+    @BeforeMethod(alwaysRun=true)
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         producer = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         intSensorA = new BasicAttributeSensor<Integer>(Integer.class, "int.sensor.a");
         target = new BasicAttributeSensor<Long>(Long.class, "long.sensor.target");
@@ -39,11 +36,6 @@ public class TransformingEnricherTest {
         app.start(ImmutableList.of(new SimulatedLocation()));
     }
     
-    @AfterMethod(alwaysRun=true)
-    public void after() {
-        if (app!=null) Entities.destroyAll(app.getManagementContext());
-    }
-    
     @Test
     public void testTransformingEnricher() throws Exception {
         //ensure previous values get picked up

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/EffectorMetadataTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/EffectorMetadataTest.java b/core/src/test/java/brooklyn/entity/EffectorMetadataTest.java
index 2a5f480..5228621 100644
--- a/core/src/test/java/brooklyn/entity/EffectorMetadataTest.java
+++ b/core/src/test/java/brooklyn/entity/EffectorMetadataTest.java
@@ -6,15 +6,12 @@ import java.util.Collection;
 import java.util.List;
 
 import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import brooklyn.entity.annotation.EffectorParam;
 import brooklyn.entity.basic.AbstractEntity;
-import brooklyn.entity.basic.ApplicationBuilder;
 import brooklyn.entity.basic.BasicParameterType;
-import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.MethodEffector;
 import brooklyn.entity.effector.Effectors;
 import brooklyn.entity.proxying.EntitySpec;
@@ -22,7 +19,6 @@ import brooklyn.entity.proxying.ImplementedBy;
 import brooklyn.entity.trait.Startable;
 import brooklyn.location.Location;
 import brooklyn.management.internal.EffectorUtils;
-import brooklyn.test.entity.TestApplication;
 
 import com.google.common.collect.ImmutableList;
 
@@ -31,24 +27,19 @@ import com.google.common.collect.ImmutableList;
  *
  * TODO clarify test purpose
  */
-public class EffectorMetadataTest {
+public class EffectorMetadataTest extends BrooklynAppUnitTestSupport {
     
-    private TestApplication app;
     private MyAnnotatedEntity e1;
     private MyOverridingEntity e2;
 
     @BeforeMethod(alwaysRun=true)
-    public void setUp() {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         e1 = app.createAndManageChild(EntitySpec.create(MyAnnotatedEntity.class));
         e2 = app.createAndManageChild(EntitySpec.create(MyOverridingEntity.class));
     }
 
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-
     @Test
     public void testEffectorMetaDataFromAnnotationsWithConstant() {
         Effector<?> effector = EffectorUtils.findEffectorDeclared(e1, "effWithNewAnnotation").get();

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/EffectorSayHiTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/EffectorSayHiTest.java b/core/src/test/java/brooklyn/entity/EffectorSayHiTest.java
index e501f7f..fb00d81 100644
--- a/core/src/test/java/brooklyn/entity/EffectorSayHiTest.java
+++ b/core/src/test/java/brooklyn/entity/EffectorSayHiTest.java
@@ -10,25 +10,19 @@ import java.util.Set;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import brooklyn.entity.annotation.EffectorParam;
 import brooklyn.entity.basic.AbstractEntity;
-import brooklyn.entity.basic.ApplicationBuilder;
 import brooklyn.entity.basic.BrooklynTaskTags;
-import brooklyn.entity.basic.Entities;
-import brooklyn.entity.basic.EntityInternal;
 import brooklyn.entity.basic.MethodEffector;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.entity.proxying.ImplementedBy;
 import brooklyn.entity.trait.Startable;
 import brooklyn.management.ExecutionContext;
-import brooklyn.management.ManagementContext;
 import brooklyn.management.Task;
 import brooklyn.management.internal.ManagementContextInternal;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.task.BasicTask;
 
@@ -41,27 +35,20 @@ import com.google.common.collect.Maps;
  *
  * TODO clarify test purpose
  */
-public class EffectorSayHiTest {
+public class EffectorSayHiTest extends BrooklynAppUnitTestSupport {
     
     //TODO test edge/error conditions
     //(missing parameters, wrong number of params, etc)
 
     private static final Logger log = LoggerFactory.getLogger(EffectorSayHiTest.class);
 
-    private TestApplication app;
     private MyEntity e;
-    private ManagementContext managementContext;
 
     @BeforeMethod(alwaysRun=true)
-    public void setUp() {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         e = app.createAndManageChild(EntitySpec.create(MyEntity.class));
-        managementContext = ((EntityInternal)e).getManagementContext();
-    }
-
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
     }
 
     @Test
@@ -94,7 +81,7 @@ public class EffectorSayHiTest {
     public void testCanRetrieveTaskForEffector() {
         e.sayHi1("Bob", "hi");
 
-        Set<Task<?>> tasks = managementContext.getExecutionManager().getTasksWithAllTags(ImmutableList.of(
+        Set<Task<?>> tasks = mgmt.getExecutionManager().getTasksWithAllTags(ImmutableList.of(
                 BrooklynTaskTags.tagForContextEntity(e),ManagementContextInternal.EFFECTOR_TAG));
         assertEquals(tasks.size(), 1);
         assertTrue(tasks.iterator().next().getDescription().contains("sayHi1"));
@@ -104,7 +91,7 @@ public class EffectorSayHiTest {
     public void testDelegatedNestedEffectorNotRepresentedAsTask() {
         e.delegateSayHi1("Bob", "hi");
 
-        Set<Task<?>> tasks = managementContext.getExecutionManager().getTasksWithAllTags(ImmutableList.of(
+        Set<Task<?>> tasks = mgmt.getExecutionManager().getTasksWithAllTags(ImmutableList.of(
                 BrooklynTaskTags.tagForContextEntity(e),ManagementContextInternal.EFFECTOR_TAG));
         assertEquals(tasks.size(), 1);
         assertTrue(tasks.iterator().next().getDescription().contains("delegateSayHi1"));
@@ -113,10 +100,10 @@ public class EffectorSayHiTest {
 
     @Test
     public void testCanExcludeNonEffectorTasks() throws Exception {
-        ExecutionContext executionContext = managementContext.getExecutionContext(e);
+        ExecutionContext executionContext = mgmt.getExecutionContext(e);
         executionContext.submit(new BasicTask<Void>(new Runnable() { public void run() {} }));
 
-        Set<Task<?>> effectTasks = managementContext.getExecutionManager().getTasksWithAllTags(ImmutableList.of(
+        Set<Task<?>> effectTasks = mgmt.getExecutionManager().getTasksWithAllTags(ImmutableList.of(
                 BrooklynTaskTags.tagForContextEntity(e),ManagementContextInternal.EFFECTOR_TAG));
         assertEquals(effectTasks.size(), 0);
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/basic/AbstractApplicationLegacyTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/AbstractApplicationLegacyTest.java b/core/src/test/java/brooklyn/entity/basic/AbstractApplicationLegacyTest.java
index 984b6ce..d47e710 100644
--- a/core/src/test/java/brooklyn/entity/basic/AbstractApplicationLegacyTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/AbstractApplicationLegacyTest.java
@@ -4,13 +4,12 @@ import static org.testng.Assert.assertEquals;
 
 import java.util.List;
 
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.location.basic.SimulatedLocation;
-import brooklyn.management.ManagementContext;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 
@@ -22,30 +21,22 @@ import com.google.common.collect.ImmutableMap;
  * 
  * @author aled
  */
-public class AbstractApplicationLegacyTest {
+public class AbstractApplicationLegacyTest extends BrooklynAppUnitTestSupport {
 
     private List<SimulatedLocation> locs;
-    private TestApplication app;
-    private ManagementContext managementContext;
     
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
+        super.setUp();
         locs = ImmutableList.of(new SimulatedLocation());
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-        managementContext = app.getManagementContext();
-    }
-    
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-        if (managementContext != null) Entities.destroyAll(managementContext);
     }
     
     // App and its children will be implicitly managed on first effector call on app
     @Test
     public void testStartAndStopCallsChildren() throws Exception {
         // deliberately unmanaged
-        TestApplication app2 = managementContext.getEntityManager().createEntity(EntitySpec.create(TestApplication.class));
+        TestApplication app2 = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class));
         TestEntity child = app2.addChild(EntitySpec.create(TestEntity.class));
         
         app2.invoke(AbstractApplication.START, ImmutableMap.of("locations", locs)).get();

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/basic/BrooklynShutdownHooksTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/BrooklynShutdownHooksTest.java b/core/src/test/java/brooklyn/entity/basic/BrooklynShutdownHooksTest.java
index fa37028..bbe2c82 100644
--- a/core/src/test/java/brooklyn/entity/basic/BrooklynShutdownHooksTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/BrooklynShutdownHooksTest.java
@@ -6,36 +6,27 @@ import static org.testng.Assert.assertTrue;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.basic.BrooklynShutdownHooks.BrooklynShutdownHookJob;
 import brooklyn.entity.proxying.EntitySpec;
-import brooklyn.management.ManagementContext;
 import brooklyn.test.entity.BlockingEntity;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.time.Duration;
 
-public class BrooklynShutdownHooksTest {
+public class BrooklynShutdownHooksTest extends BrooklynAppUnitTestSupport {
 
-    private ManagementContext managementContext;
-    private TestApplication app;
     private TestEntity entity;
     
     @BeforeMethod(alwaysRun=true)
-    public void setUp() {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
-        managementContext = app.getManagementContext();
     }
     
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-
     @Test
     public void testInvokeStopEntityOnShutdown() throws Exception {
         BrooklynShutdownHooks.invokeStopOnShutdown(entity);
@@ -62,22 +53,22 @@ public class BrooklynShutdownHooksTest {
     
     @Test
     public void testInvokeTerminateManagementContextOnShutdown() throws Exception {
-        BrooklynShutdownHooks.invokeTerminateOnShutdown(managementContext);
+        BrooklynShutdownHooks.invokeTerminateOnShutdown(mgmt);
         BrooklynShutdownHooks.BrooklynShutdownHookJob job = BrooklynShutdownHookJob.newInstanceForTesting();
         job.run();
         
-        assertFalse(managementContext.isRunning());
+        assertFalse(mgmt.isRunning());
     }
 
     // Should first stop entities, then terminate management contexts
     @Test
     public void testInvokeStopEntityAndTerminateManagementContextOnShutdown() throws Exception {
-        BrooklynShutdownHooks.invokeTerminateOnShutdown(managementContext);
+        BrooklynShutdownHooks.invokeTerminateOnShutdown(mgmt);
         BrooklynShutdownHooks.invokeStopOnShutdown(entity);
         BrooklynShutdownHooks.BrooklynShutdownHookJob job = BrooklynShutdownHookJob.newInstanceForTesting();
         job.run();
         
         assertTrue(entity.getCallHistory().contains("stop"));
-        assertFalse(managementContext.isRunning());
+        assertFalse(mgmt.isRunning());
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/basic/ConfigMapTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/ConfigMapTest.java b/core/src/test/java/brooklyn/entity/basic/ConfigMapTest.java
index 85d3ce8..bb86cd1 100644
--- a/core/src/test/java/brooklyn/entity/basic/ConfigMapTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/ConfigMapTest.java
@@ -1,61 +1,64 @@
 package brooklyn.entity.basic;
 
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import groovy.lang.Closure;
+
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
 import brooklyn.config.ConfigKey;
 import brooklyn.config.ConfigMap;
 import brooklyn.config.ConfigPredicates;
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.Entity;
 import brooklyn.event.basic.BasicAttributeSensorAndConfigKey.IntegerAttributeSensorAndConfigKey;
 import brooklyn.management.ExecutionManager;
 import brooklyn.management.Task;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.task.BasicTask;
 import brooklyn.util.task.DeferredSupplier;
+
 import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.util.concurrent.MoreExecutors;
-import groovy.lang.Closure;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import java.util.Map;
-import java.util.concurrent.Callable;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
 
-public class ConfigMapTest {
+public class ConfigMapTest extends BrooklynAppUnitTestSupport {
 
     private static final int TIMEOUT_MS = 10*1000;
 
-    private TestApplication app;
     private MySubEntity entity;
     private ExecutorService executor;
     private ExecutionManager executionManager;
 
     @BeforeMethod(alwaysRun=true)
-    public void setUp() {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         entity = new MySubEntity(app);
         Entities.manage(entity);
         executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
-        executionManager = app.getManagementContext().getExecutionManager();
+        executionManager = mgmt.getExecutionManager();
     }
 
     @AfterMethod(alwaysRun=true)
+    @Override
     public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
         if (executor != null) executor.shutdownNow();
+        super.tearDown();
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/basic/DependentConfigurationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/DependentConfigurationTest.java b/core/src/test/java/brooklyn/entity/basic/DependentConfigurationTest.java
index 3169926..bf1904e 100644
--- a/core/src/test/java/brooklyn/entity/basic/DependentConfigurationTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/DependentConfigurationTest.java
@@ -12,15 +12,14 @@ import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicReference;
 
 import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.event.basic.DependentConfiguration;
 import brooklyn.management.Task;
 import brooklyn.test.Asserts;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableList;
 import brooklyn.util.task.BasicTask;
@@ -39,27 +38,22 @@ import com.google.common.util.concurrent.Callables;
 /** Tests the standalone routines in dependent configuration.
  * See e.g. LocalEntitiesTest for tests of attributeWhenReady etc.
  */
-public class DependentConfigurationTest {
+public class DependentConfigurationTest extends BrooklynAppUnitTestSupport {
 
     public static final int SHORT_WAIT_MS = 100;
     public static final int TIMEOUT_MS = 30*1000;
     
-    private TestApplication app;
     private TestEntity entity;
     private TestEntity entity2;
 
     @BeforeMethod(alwaysRun=true)
-    public void setUp() {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         entity2 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
     }
     
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-    
     @Test
     public void testTransform() throws Exception {
         Task<Integer> t = DependentConfiguration.transform(

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/basic/EntitiesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/EntitiesTest.java b/core/src/test/java/brooklyn/entity/basic/EntitiesTest.java
index 1b08185..132ff5b 100644
--- a/core/src/test/java/brooklyn/entity/basic/EntitiesTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/EntitiesTest.java
@@ -8,42 +8,36 @@ import java.util.concurrent.atomic.AtomicReference;
 
 import junit.framework.Assert;
 
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.location.LocationSpec;
 import brooklyn.location.basic.SimulatedLocation;
 import brooklyn.test.Asserts;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableSet;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 
-public class EntitiesTest {
+public class EntitiesTest extends BrooklynAppUnitTestSupport {
 
     private static final int TIMEOUT_MS = 10*1000;
     
     private SimulatedLocation loc;
-    private TestApplication app;
     private TestEntity entity;
     
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+        super.setUp();
         loc = app.getManagementContext().getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         app.start(ImmutableList.of(loc));
     }
     
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-    
     @Test
     public void testDescendants() throws Exception {
         Assert.assertEquals(Iterables.size(Entities.descendants(app)), 2);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/basic/EntityConfigMapUsageLegacyTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/EntityConfigMapUsageLegacyTest.java b/core/src/test/java/brooklyn/entity/basic/EntityConfigMapUsageLegacyTest.java
index d7a114d..b892d6b 100644
--- a/core/src/test/java/brooklyn/entity/basic/EntityConfigMapUsageLegacyTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/EntityConfigMapUsageLegacyTest.java
@@ -7,14 +7,12 @@ import static org.testng.Assert.fail;
 import java.util.concurrent.Callable;
 import java.util.concurrent.CountDownLatch;
 
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import brooklyn.config.ConfigKey;
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.event.basic.DependentConfiguration;
 import brooklyn.location.basic.SimulatedLocation;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.test.entity.TestEntityImpl;
 import brooklyn.util.collections.MutableMap;
@@ -30,24 +28,12 @@ import com.google.common.util.concurrent.Callables;
  * 
  * Uses legacy mechanism of calling entity constructors.
  */
-public class EntityConfigMapUsageLegacyTest {
+public class EntityConfigMapUsageLegacyTest extends BrooklynAppUnitTestSupport {
     private ConfigKey<Integer> intKey = ConfigKeys.newIntegerConfigKey("bkey", "b key");
     private ConfigKey<String> strKey = ConfigKeys.newStringConfigKey("akey", "a key");
     private ConfigKey<Integer> intKeyWithDefault = ConfigKeys.newIntegerConfigKey("ckey", "c key", 1);
     private ConfigKey<String> strKeyWithDefault = ConfigKeys.newStringConfigKey("strKey", "str key", "str key default");
     
-    private TestApplication app;
-    
-    @BeforeMethod
-    public void setUp() {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-    }
-
-    @AfterMethod(alwaysRun = true)
-    public void tearDown(){
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-    
     @Test
     public void testConfigPassedInAtConstructorIsAvailable() throws Exception {
         TestEntity entity = new TestEntityImpl(MutableMap.of("config", MutableMap.of(strKey, "aval", intKey, 2)), app);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/basic/EntityConfigMapUsageTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/EntityConfigMapUsageTest.java b/core/src/test/java/brooklyn/entity/basic/EntityConfigMapUsageTest.java
index af7a044..94666c5 100644
--- a/core/src/test/java/brooklyn/entity/basic/EntityConfigMapUsageTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/EntityConfigMapUsageTest.java
@@ -8,16 +8,15 @@ import java.util.List;
 import java.util.concurrent.Callable;
 import java.util.concurrent.CountDownLatch;
 
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import brooklyn.config.ConfigKey;
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.event.basic.BasicConfigKey;
 import brooklyn.event.basic.DependentConfiguration;
 import brooklyn.location.basic.SimulatedLocation;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.exceptions.Exceptions;
 
@@ -29,7 +28,7 @@ import com.google.common.util.concurrent.Callables;
 /**
  * Test that configuration properties are usable and inherited correctly.
  */
-public class EntityConfigMapUsageTest {
+public class EntityConfigMapUsageTest extends BrooklynAppUnitTestSupport {
     private static final int EARLY_RETURN_GRACE = 10;
     
     private BasicConfigKey<Integer> intKey = new BasicConfigKey<Integer>(Integer.class, "bkey", "b key");
@@ -37,20 +36,15 @@ public class EntityConfigMapUsageTest {
     private ConfigKey<Integer> intKeyWithDefault = new BasicConfigKey<Integer>(Integer.class, "ckey", "c key", 1);
     private ConfigKey<String> strKeyWithDefault = new BasicConfigKey<String>(String.class, "strKey", "str key", "str key default");
     
-    private TestApplication app;
     private List<SimulatedLocation> locs;
     
-    @BeforeMethod
-    public void setUp() {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+    @BeforeMethod(alwaysRun=true)
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         locs = ImmutableList.of(new SimulatedLocation());
     }
 
-    @AfterMethod(alwaysRun = true)
-    public void tearDown(){
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-
     @Test
     public void testConfigPassedInAtConstructionIsAvailable() throws Exception {
         TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/basic/EntityFunctionsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/EntityFunctionsTest.java b/core/src/test/java/brooklyn/entity/basic/EntityFunctionsTest.java
index f202fc3..cc21708 100644
--- a/core/src/test/java/brooklyn/entity/basic/EntityFunctionsTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/EntityFunctionsTest.java
@@ -3,30 +3,24 @@ package brooklyn.entity.basic;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNull;
 
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.proxying.EntitySpec;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 
-public class EntityFunctionsTest {
+public class EntityFunctionsTest extends BrooklynAppUnitTestSupport {
 
-    private TestApplication app;
     private TestEntity entity;
     
     @BeforeMethod(alwaysRun=true)
-    public void setUp() {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("mydisplayname"));
     }
 
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-    
     @Test
     public void testAttribute() throws Exception {
         entity.setAttribute(TestEntity.NAME, "myname");

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/basic/EntityLocationsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/EntityLocationsTest.java b/core/src/test/java/brooklyn/entity/basic/EntityLocationsTest.java
index 51e1e37..c104acf 100644
--- a/core/src/test/java/brooklyn/entity/basic/EntityLocationsTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/EntityLocationsTest.java
@@ -3,28 +3,14 @@ package brooklyn.entity.basic;
 import java.util.Arrays;
 
 import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.location.Location;
 import brooklyn.location.basic.SimulatedLocation;
-import brooklyn.test.entity.TestApplication;
 
-public class EntityLocationsTest {
+public class EntityLocationsTest extends BrooklynAppUnitTestSupport {
 
-    private TestApplication app;
-
-    @BeforeMethod(alwaysRun=true)
-    public void setUp() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-    }
-    
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-    
     @Test
     public void testDuplicateLocationOnlyAddedOnce() {
         Location l = new SimulatedLocation();

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/basic/EntityPredicatesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/EntityPredicatesTest.java b/core/src/test/java/brooklyn/entity/basic/EntityPredicatesTest.java
index 2818590..08a55a8 100644
--- a/core/src/test/java/brooklyn/entity/basic/EntityPredicatesTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/EntityPredicatesTest.java
@@ -3,37 +3,31 @@ package brooklyn.entity.basic;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
 
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.location.Location;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 
 import com.google.common.collect.ImmutableList;
 
-public class EntityPredicatesTest {
+public class EntityPredicatesTest extends BrooklynAppUnitTestSupport {
 
-    private TestApplication app;
     private TestEntity entity;
     private BasicGroup group;
     private Location loc;
     
     @BeforeMethod(alwaysRun=true)
-    public void setUp() {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("mydisplayname"));
         group = app.createAndManageChild(EntitySpec.create(BasicGroup.class));
         loc = app.getManagementContext().getLocationRegistry().resolve("localhost");
     }
 
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-    
     @Test
     public void testApplicationIdEqualTo() throws Exception {
         assertTrue(EntityPredicates.applicationIdEqualTo(app.getId()).apply(entity));

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/basic/EntityRegistrationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/EntityRegistrationTest.java b/core/src/test/java/brooklyn/entity/basic/EntityRegistrationTest.java
index 9a538c5..e4f6077 100644
--- a/core/src/test/java/brooklyn/entity/basic/EntityRegistrationTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/EntityRegistrationTest.java
@@ -5,16 +5,15 @@ import static org.testng.Assert.assertEquals;
 import java.util.Collection;
 import java.util.List;
 
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.Entity;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.event.SensorEvent;
 import brooklyn.event.SensorEventListener;
 import brooklyn.test.Asserts;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableMap;
 
@@ -22,11 +21,10 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Lists;
 
-public class EntityRegistrationTest {
+public class EntityRegistrationTest extends BrooklynAppUnitTestSupport {
 
     private static final int TIMEOUT_MS = 10*1000;
     
-    private TestApplication app;
     private TestEntity entity;
     private TestEntity entity2;
 
@@ -34,8 +32,9 @@ public class EntityRegistrationTest {
     private List<Entity> removed;
 
     @BeforeMethod(alwaysRun=true)
-    public void setUp() {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         
         added = Lists.newCopyOnWriteArrayList();
         removed = Lists.newCopyOnWriteArrayList();
@@ -50,11 +49,6 @@ public class EntityRegistrationTest {
                 }});
     }
     
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-    
     @Test
     public void testAddAndRemoveChildrenEmitsEvent() {
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/basic/EntitySpecTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/EntitySpecTest.java b/core/src/test/java/brooklyn/entity/basic/EntitySpecTest.java
index 19e4842..ef53cc0 100644
--- a/core/src/test/java/brooklyn/entity/basic/EntitySpecTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/EntitySpecTest.java
@@ -3,46 +3,36 @@ package brooklyn.entity.basic;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
 
-import java.util.Map;
-
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-import brooklyn.config.ConfigKey;
 import brooklyn.enricher.basic.AbstractEnricher;
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.event.basic.BasicConfigKey;
 import brooklyn.location.basic.SimulatedLocation;
 import brooklyn.policy.Enricher;
 import brooklyn.policy.EnricherSpec;
-import brooklyn.policy.EnricherType;
 import brooklyn.policy.Policy;
 import brooklyn.policy.PolicySpec;
 import brooklyn.policy.basic.AbstractPolicy;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.flags.SetFromFlag;
 
 import com.google.common.collect.Iterables;
 
-public class EntitySpecTest {
+public class EntitySpecTest extends BrooklynAppUnitTestSupport {
 
     private static final int TIMEOUT_MS = 10*1000;
     
     private SimulatedLocation loc;
-    private TestApplication app;
     private TestEntity entity;
     
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
+        super.setUp();
         loc = new SimulatedLocation();
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-    }
-    
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/basic/EntityTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/EntityTypeTest.java b/core/src/test/java/brooklyn/entity/basic/EntityTypeTest.java
index 2fd0d4e..ecc55a6 100644
--- a/core/src/test/java/brooklyn/entity/basic/EntityTypeTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/EntityTypeTest.java
@@ -19,10 +19,10 @@ import java.util.Set;
 
 import javax.annotation.Nullable;
 
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.Effector;
 import brooklyn.entity.Entity;
 import brooklyn.entity.proxying.EntitySpec;
@@ -31,7 +31,6 @@ import brooklyn.event.Sensor;
 import brooklyn.event.basic.BasicSensorEvent;
 import brooklyn.event.basic.Sensors;
 import brooklyn.test.TestUtils;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.test.entity.TestEntityImpl;
 import brooklyn.util.collections.CollectionFunctionals;
@@ -44,9 +43,8 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 
-public class EntityTypeTest {
+public class EntityTypeTest extends BrooklynAppUnitTestSupport {
     private static final AttributeSensor<String> TEST_SENSOR = Sensors.newStringSensor("test.sensor");
-    private TestApplication app;
     private EntityInternal entity;
     private EntitySubscriptionTest.RecordingSensorEventListener listener;
     
@@ -59,8 +57,9 @@ public class EntityTypeTest {
     public static class EmptyEntityForTesting extends AbstractEntity {}
     
     @BeforeMethod(alwaysRun=true)
-    public void setUpTestEntity() throws Exception{
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+    @Override
+    public void setUp() throws Exception{
+        super.setUp();
         entity = (EntityInternal) app.createAndManageChild(EntitySpec.create(Entity.class, EmptyEntityForTesting.class));
 //        entity = new AbstractEntity(app) {};
 //        Entities.startManagement(entity);
@@ -70,11 +69,6 @@ public class EntityTypeTest {
         app.getSubscriptionContext().subscribe(entity, SENSOR_REMOVED, listener);
     }
 
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-    
     @Test
     public void testGetName() throws Exception {
         TestEntity entity2 = app.createAndManageChild(EntitySpec.create(TestEntity.class));

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/basic/MapConfigKeyAndFriendsMoreTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/MapConfigKeyAndFriendsMoreTest.java b/core/src/test/java/brooklyn/entity/basic/MapConfigKeyAndFriendsMoreTest.java
index e6498a8..6be5f01 100644
--- a/core/src/test/java/brooklyn/entity/basic/MapConfigKeyAndFriendsMoreTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/MapConfigKeyAndFriendsMoreTest.java
@@ -5,10 +5,10 @@ import java.util.List;
 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 brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.event.basic.ListConfigKey;
 import brooklyn.event.basic.ListConfigKey.ListModifications;
@@ -18,7 +18,6 @@ import brooklyn.event.basic.SetConfigKey;
 import brooklyn.event.basic.SetConfigKey.SetModifications;
 import brooklyn.event.basic.StructuredConfigKey.StructuredModification;
 import brooklyn.event.basic.SubElementConfigKey;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableList;
 import brooklyn.util.collections.MutableMap;
@@ -36,24 +35,19 @@ import com.google.common.collect.ImmutableSet;
  * <p>
  * (also this is pure java so we get nice ide support) */
 @Test
-public class MapConfigKeyAndFriendsMoreTest {
+public class MapConfigKeyAndFriendsMoreTest extends BrooklynAppUnitTestSupport {
 
     private static final Logger log = LoggerFactory.getLogger(MapConfigKeyAndFriendsMoreTest.class);
     
-    private TestApplication app;
     private TestEntity entity;
     
     @BeforeMethod(alwaysRun=true)
-    public void setUp() {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
     }
 
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-
     public void testMapModUsage() throws Exception {
         entity.setConfig(TestEntity.CONF_MAP_THING_OBJECT, MapModifications.add(MutableMap.<String,Object>of("a", 1)));
         log.info("Map-Mod: "+MutableMap.copyOf(entity.getConfigMap().asMapWithStringKeys()));

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/basic/PolicyRegistrationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/PolicyRegistrationTest.java b/core/src/test/java/brooklyn/entity/basic/PolicyRegistrationTest.java
index 3910062..cef015f 100644
--- a/core/src/test/java/brooklyn/entity/basic/PolicyRegistrationTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/PolicyRegistrationTest.java
@@ -7,10 +7,10 @@ import static org.testng.Assert.fail;
 import java.util.Collection;
 import java.util.List;
 
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.event.SensorEvent;
 import brooklyn.event.SensorEventListener;
@@ -19,7 +19,6 @@ import brooklyn.policy.Policy;
 import brooklyn.policy.PolicySpec;
 import brooklyn.policy.basic.AbstractPolicy;
 import brooklyn.test.TestUtils;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableMap;
 
@@ -27,11 +26,10 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Lists;
 
-public class PolicyRegistrationTest {
+public class PolicyRegistrationTest extends BrooklynAppUnitTestSupport {
 
     private static final int TIMEOUT_MS = 10*1000;
     
-    private TestApplication app;
     private TestEntity entity;
     private Policy policy1;
     private Policy policy2;
@@ -40,8 +38,9 @@ public class PolicyRegistrationTest {
     private List<PolicyDescriptor> removed;
 
     @BeforeMethod(alwaysRun=true)
-    public void setUp() {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         policy1 = new AbstractPolicy() {};
         policy2 = new AbstractPolicy() {};
@@ -59,11 +58,6 @@ public class PolicyRegistrationTest {
                 }});
     }
     
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-    
     @Test
     public void testGetPoliciesIsInitiallyEmpty() {
         assertEquals(entity.getPolicies(), ImmutableList.of());

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/drivers/downloads/DownloadSubstitutersTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/drivers/downloads/DownloadSubstitutersTest.java b/core/src/test/java/brooklyn/entity/drivers/downloads/DownloadSubstitutersTest.java
index 7bf6146..93be01e 100644
--- a/core/src/test/java/brooklyn/entity/drivers/downloads/DownloadSubstitutersTest.java
+++ b/core/src/test/java/brooklyn/entity/drivers/downloads/DownloadSubstitutersTest.java
@@ -5,44 +5,36 @@ import static org.testng.Assert.fail;
 
 import java.util.Map;
 
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-import brooklyn.entity.basic.ApplicationBuilder;
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.basic.BrooklynConfigKeys;
-import brooklyn.entity.basic.Entities;
 import brooklyn.entity.drivers.downloads.DownloadResolverManager.DownloadTargets;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.location.Location;
 import brooklyn.location.basic.SimulatedLocation;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 
 import com.google.common.base.Functions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 
-public class DownloadSubstitutersTest {
+public class DownloadSubstitutersTest extends BrooklynAppUnitTestSupport {
 
     private Location loc;
-    private TestApplication app;
     private TestEntity entity;
     private MyEntityDriver driver;
 
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
+        super.setUp();
         loc = new SimulatedLocation();
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         driver = new MyEntityDriver(entity, loc);
     }
     
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-
     @Test
     public void testSimpleSubstitution() throws Exception {
         entity.setConfig(BrooklynConfigKeys.SUGGESTED_VERSION, "myversion");

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/effector/EffectorBasicTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/effector/EffectorBasicTest.java b/core/src/test/java/brooklyn/entity/effector/EffectorBasicTest.java
index 4c95a42..007a3cf 100644
--- a/core/src/test/java/brooklyn/entity/effector/EffectorBasicTest.java
+++ b/core/src/test/java/brooklyn/entity/effector/EffectorBasicTest.java
@@ -5,11 +5,10 @@ import java.util.List;
 import org.junit.Assert;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-import brooklyn.entity.basic.ApplicationBuilder;
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.EntityLocal;
 import brooklyn.entity.proxying.EntitySpec;
@@ -18,33 +17,27 @@ import brooklyn.location.basic.SimulatedLocation;
 import brooklyn.management.Task;
 import brooklyn.management.internal.ManagementContextInternal;
 import brooklyn.test.TestUtils;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableMap;
 
 import com.google.common.collect.ImmutableList;
 
-public class EffectorBasicTest {
+public class EffectorBasicTest extends BrooklynAppUnitTestSupport {
 
     private static final Logger log = LoggerFactory.getLogger(EffectorBasicTest.class);
     
     // NB: more tests of effectors in EffectorSayHiTest and EffectorConcatenateTest
     // as well as EntityConfigMapUsageTest and others
 
-    private TestApplication app;
     private List<SimulatedLocation> locs;
     
     @BeforeMethod(alwaysRun=true)
-    public void setup() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         locs = ImmutableList.of(new SimulatedLocation());
     }
     
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-    
     @Test
     public void testInvokeEffectorStart() {
         app.start(locs);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/effector/EffectorTaskTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/effector/EffectorTaskTest.java b/core/src/test/java/brooklyn/entity/effector/EffectorTaskTest.java
index 92f80e3..d1d5d96 100644
--- a/core/src/test/java/brooklyn/entity/effector/EffectorTaskTest.java
+++ b/core/src/test/java/brooklyn/entity/effector/EffectorTaskTest.java
@@ -3,23 +3,19 @@ package brooklyn.entity.effector;
 import java.util.concurrent.Callable;
 
 import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.Effector;
 import brooklyn.entity.Entity;
 import brooklyn.entity.basic.AbstractEntity;
-import brooklyn.entity.basic.ApplicationBuilder;
 import brooklyn.entity.basic.BrooklynTaskTags;
-import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.EntityInternal;
 import brooklyn.entity.effector.EffectorTasks.EffectorTaskFactory;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.entity.trait.Startable;
 import brooklyn.management.HasTaskChildren;
 import brooklyn.management.Task;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.config.ConfigBag;
@@ -31,18 +27,7 @@ import brooklyn.util.task.Tasks;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Iterables;
 
-public class EffectorTaskTest {
-
-    TestApplication app;
-    @BeforeMethod(alwaysRun=true)
-    public void setup() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-    }
-    
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
+public class EffectorTaskTest extends BrooklynAppUnitTestSupport {
 
     // ----------- syntax 1 -- effector with body in a class
     

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java b/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
index a13da15..bfc8a73 100644
--- a/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
+++ b/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
@@ -21,12 +21,11 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
 
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.Entity;
-import brooklyn.entity.basic.ApplicationBuilder;
 import brooklyn.entity.basic.Attributes;
 import brooklyn.entity.basic.BrooklynTaskTags;
 import brooklyn.entity.basic.Entities;
@@ -39,7 +38,6 @@ import brooklyn.location.Location;
 import brooklyn.location.basic.SimulatedLocation;
 import brooklyn.management.Task;
 import brooklyn.test.Asserts;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.test.entity.TestEntityImpl;
 import brooklyn.util.collections.MutableMap;
@@ -56,27 +54,22 @@ import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.Atomics;
 
 
-public class DynamicClusterTest {
+public class DynamicClusterTest extends BrooklynAppUnitTestSupport {
 
     private static final int TIMEOUT_MS = 2000;
 
-    TestApplication app;
     SimulatedLocation loc;
     SimulatedLocation loc2;
     Random random = new Random();
 
-    @BeforeMethod
-    public void setUp() {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+    @BeforeMethod(alwaysRun=true)
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         loc = new SimulatedLocation();
         loc2 = new SimulatedLocation();
     }
 
-    @AfterMethod(alwaysRun = true)
-    public void tearDown(){
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-
     @Test
     public void creationOkayWithoutNewEntityFactoryArgument() throws Exception {
         app.createAndManageChild(EntitySpec.create(DynamicCluster.class));

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/group/DynamicClusterWithAvailabilityZonesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/group/DynamicClusterWithAvailabilityZonesTest.java b/core/src/test/java/brooklyn/entity/group/DynamicClusterWithAvailabilityZonesTest.java
index a90f2ad..f494dbc 100644
--- a/core/src/test/java/brooklyn/entity/group/DynamicClusterWithAvailabilityZonesTest.java
+++ b/core/src/test/java/brooklyn/entity/group/DynamicClusterWithAvailabilityZonesTest.java
@@ -13,8 +13,8 @@ import java.util.concurrent.atomic.AtomicLong;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.Entity;
-import brooklyn.entity.basic.ApplicationBuilder;
 import brooklyn.entity.basic.EntityLocal;
 import brooklyn.entity.basic.EntityPredicates;
 import brooklyn.entity.group.zoneaware.ProportionalZoneFailureDetector;
@@ -27,7 +27,6 @@ import brooklyn.location.cloud.AbstractAvailabilityZoneExtension;
 import brooklyn.location.cloud.AvailabilityZoneExtension;
 import brooklyn.management.ManagementContext;
 import brooklyn.test.Asserts;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.time.Duration;
 
@@ -38,24 +37,22 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 
-public class DynamicClusterWithAvailabilityZonesTest {
+public class DynamicClusterWithAvailabilityZonesTest extends BrooklynAppUnitTestSupport {
     
-    private ManagementContext managementContext;
-    private TestApplication app;
     private DynamicCluster cluster;
     private SimulatedLocation loc;
     
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-        managementContext = app.getManagementContext();
+        super.setUp();
         cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
                 .configure(DynamicCluster.ENABLE_AVAILABILITY_ZONES, true)
                 .configure(DynamicCluster.INITIAL_SIZE, 0)
                 .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(TestEntity.class)));
         
-        loc = managementContext.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
-        loc.addExtension(AvailabilityZoneExtension.class, new SimulatedAvailabilityZoneExtension(managementContext, loc, ImmutableList.of("zone1", "zone2", "zone3", "zone4")));
+        loc = mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
+        loc.addExtension(AvailabilityZoneExtension.class, new SimulatedAvailabilityZoneExtension(mgmt, loc, ImmutableList.of("zone1", "zone2", "zone3", "zone4")));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/group/DynamicFabricTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/group/DynamicFabricTest.java b/core/src/test/java/brooklyn/entity/group/DynamicFabricTest.java
index 73052d1..af95685 100644
--- a/core/src/test/java/brooklyn/entity/group/DynamicFabricTest.java
+++ b/core/src/test/java/brooklyn/entity/group/DynamicFabricTest.java
@@ -15,13 +15,12 @@ import java.util.concurrent.atomic.AtomicInteger;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.Entity;
 import brooklyn.entity.Group;
-import brooklyn.entity.basic.ApplicationBuilder;
 import brooklyn.entity.basic.Attributes;
 import brooklyn.entity.basic.BasicEntity;
 import brooklyn.entity.basic.Entities;
@@ -35,7 +34,6 @@ import brooklyn.management.Task;
 import brooklyn.test.Asserts;
 import brooklyn.test.TestUtils;
 import brooklyn.test.entity.BlockingEntity;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.repeat.Repeater;
@@ -47,27 +45,22 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 
-public class DynamicFabricTest {
+public class DynamicFabricTest extends BrooklynAppUnitTestSupport {
     private static final Logger log = LoggerFactory.getLogger(DynamicFabricTest.class);
 
     private static final int TIMEOUT_MS = 5*1000;
 
-    private TestApplication app;
     private Location loc1;
     private Location loc2;
     private Location loc3;
 
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
+        super.setUp();
         loc1 = new SimulatedLocation();
         loc2 = new SimulatedLocation();
         loc3 = new SimulatedLocation();
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-    }
-
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/group/DynamicRegionsFabricTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/group/DynamicRegionsFabricTest.java b/core/src/test/java/brooklyn/entity/group/DynamicRegionsFabricTest.java
index 4e6cea2..fa9debe 100644
--- a/core/src/test/java/brooklyn/entity/group/DynamicRegionsFabricTest.java
+++ b/core/src/test/java/brooklyn/entity/group/DynamicRegionsFabricTest.java
@@ -6,17 +6,14 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Set;
 
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.Entity;
-import brooklyn.entity.basic.ApplicationBuilder;
-import brooklyn.entity.basic.Entities;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.location.Location;
 import brooklyn.location.basic.SimulatedLocation;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableSet;
 import brooklyn.util.exceptions.Exceptions;
@@ -27,28 +24,23 @@ import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 
-public class DynamicRegionsFabricTest {
+public class DynamicRegionsFabricTest extends BrooklynAppUnitTestSupport {
 
-    private TestApplication app;
     DynamicRegionsFabric fabric;
     private Location loc1;
     private Location loc2;
     
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
+        super.setUp();
         loc1 = new SimulatedLocation();
         loc2 = new SimulatedLocation();
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
         
         fabric = app.createAndManageChild(EntitySpec.create(DynamicRegionsFabric.class)
                 .configure("memberSpec", EntitySpec.create(TestEntity.class)));
     }
 
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-    
     @Test
     public void testUsesInitialLocations() throws Exception {
         app.start(ImmutableList.of(loc1, loc2));

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/group/GroupPickUpEntitiesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/group/GroupPickUpEntitiesTest.java b/core/src/test/java/brooklyn/entity/group/GroupPickUpEntitiesTest.java
index 463f50c..da28e01 100644
--- a/core/src/test/java/brooklyn/entity/group/GroupPickUpEntitiesTest.java
+++ b/core/src/test/java/brooklyn/entity/group/GroupPickUpEntitiesTest.java
@@ -1,13 +1,12 @@
 package brooklyn.entity.group;
 
 import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.Entity;
 import brooklyn.entity.Group;
-import brooklyn.entity.basic.ApplicationBuilder;
 import brooklyn.entity.basic.BasicGroup;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.EntityInternal;
@@ -20,7 +19,6 @@ import brooklyn.policy.PolicySpec;
 import brooklyn.policy.basic.AbstractPolicy;
 import brooklyn.test.Asserts;
 import brooklyn.test.EntityTestUtils;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.javalang.Boxing;
 
@@ -30,24 +28,19 @@ import com.google.common.collect.ImmutableList;
 /**
  * tests that a group's membership gets updated using subscriptions
  */
-public class GroupPickUpEntitiesTest {
+public class GroupPickUpEntitiesTest extends BrooklynAppUnitTestSupport {
 
-    private TestApplication app;
     private BasicGroup group;
 
     @BeforeMethod(alwaysRun = true)
-    public void setUp() throws Exception{
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         group = app.createAndManageChild(EntitySpec.create(BasicGroup.class));
         
         group.addPolicy(PolicySpec.create(FindUpServicesWithNameBob.class));
     }
 
-    @AfterMethod(alwaysRun = true)
-    public void tearDown() {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-
     @Test
     public void testGroupFindsElement() {
         Assert.assertEquals(group.getMembers().size(), 0);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/group/MembershipTrackingPolicyTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/group/MembershipTrackingPolicyTest.java b/core/src/test/java/brooklyn/entity/group/MembershipTrackingPolicyTest.java
index cedaf2b..f2ccd45 100644
--- a/core/src/test/java/brooklyn/entity/group/MembershipTrackingPolicyTest.java
+++ b/core/src/test/java/brooklyn/entity/group/MembershipTrackingPolicyTest.java
@@ -7,12 +7,11 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
 
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.Entity;
-import brooklyn.entity.basic.ApplicationBuilder;
 import brooklyn.entity.basic.BasicGroup;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.proxying.EntitySpec;
@@ -22,7 +21,6 @@ import brooklyn.location.basic.SimulatedLocation;
 import brooklyn.management.EntityManager;
 import brooklyn.policy.PolicySpec;
 import brooklyn.test.Asserts;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableMap;
 
@@ -31,20 +29,20 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 
-public class MembershipTrackingPolicyTest {
+public class MembershipTrackingPolicyTest extends BrooklynAppUnitTestSupport {
 
     private static final long TIMEOUT_MS = 10*1000;
 
     SimulatedLocation loc;
     EntityManager entityManager;
-    TestApplication app;
     private BasicGroup group;
     private RecordingMembershipTrackingPolicy policy;
 
     @BeforeMethod(alwaysRun=true)
-    public void setUp() {
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         loc = new SimulatedLocation();
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
         entityManager = app.getManagementContext().getEntityManager();
         
         group = app.createAndManageChild(EntitySpec.create(BasicGroup.class)
@@ -55,11 +53,6 @@ public class MembershipTrackingPolicyTest {
         app.start(ImmutableList.of(loc));
     }
 
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-
     private TestEntity createAndManageChildOf(Entity parent) {
         EntityManager entityManager = app.getManagementContext().getEntityManager();
         TestEntity result = entityManager.createEntity(EntitySpec.create(TestEntity.class).parent(parent));

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/group/QuarantineGroupTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/group/QuarantineGroupTest.java b/core/src/test/java/brooklyn/entity/group/QuarantineGroupTest.java
index 94e84d2..31f94a8 100644
--- a/core/src/test/java/brooklyn/entity/group/QuarantineGroupTest.java
+++ b/core/src/test/java/brooklyn/entity/group/QuarantineGroupTest.java
@@ -3,45 +3,38 @@ package brooklyn.entity.group;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-import brooklyn.entity.basic.ApplicationBuilder;
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.location.LocationSpec;
 import brooklyn.location.basic.SimulatedLocation;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 
 import com.google.common.collect.ImmutableList;
 
 
-public class QuarantineGroupTest {
+public class QuarantineGroupTest extends BrooklynAppUnitTestSupport {
 
     private static final int TIMEOUT_MS = 2000;
 
     SimulatedLocation loc;
-    TestApplication app;
     private TestEntity e1;
     private TestEntity e2;
     private QuarantineGroup group;
 
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-        app.getManagementContext().getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
+        super.setUp();
+        mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
         e1 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         e2 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         group = app.createAndManageChild(EntitySpec.create(QuarantineGroup.class));
     }
 
-    @AfterMethod(alwaysRun = true)
-    public void tearDown(){
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-
     @Test
     public void testExpungeMembersWhenNone() throws Exception {
         group.expungeMembers(true);


Mime
View raw message