brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [2/4] Extend BrooklynAppUnitTestSupport in core tests
Date Tue, 01 Jul 2014 14:32:09 GMT
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/group/zoneaware/BalancingNodePlacementStrategyTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/group/zoneaware/BalancingNodePlacementStrategyTest.java
b/core/src/test/java/brooklyn/entity/group/zoneaware/BalancingNodePlacementStrategyTest.java
index 7fa0550..85c0f94 100644
--- a/core/src/test/java/brooklyn/entity/group/zoneaware/BalancingNodePlacementStrategyTest.java
+++ b/core/src/test/java/brooklyn/entity/group/zoneaware/BalancingNodePlacementStrategyTest.java
@@ -2,32 +2,23 @@ package brooklyn.entity.group.zoneaware;
 
 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.basic.ApplicationBuilder;
-import brooklyn.entity.basic.Entities;
-import brooklyn.entity.group.zoneaware.BalancingNodePlacementStrategy;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.location.Location;
 import brooklyn.location.LocationSpec;
 import brooklyn.location.basic.SimulatedLocation;
-import brooklyn.management.ManagementContext;
 import brooklyn.test.Asserts;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.LinkedHashMultimap;
 
-public class BalancingNodePlacementStrategyTest {
+public class BalancingNodePlacementStrategyTest extends BrooklynAppUnitTestSupport {
 
-    // TODO Should move BrooklynMgmtContext*TestSupport to core, from software/base
-    
-    private ManagementContext managementContext;
-    private TestApplication app;
     private TestEntity entity1;
     private TestEntity entity2;
     private TestEntity entity3;
@@ -36,11 +27,11 @@ public class BalancingNodePlacementStrategyTest {
     private BalancingNodePlacementStrategy placementStrategy;
     
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-        managementContext = app.getManagementContext();
-        loc1 = managementContext.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
-        loc2 = managementContext.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
+        super.setUp();
+        loc1 = mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
+        loc2 = mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
         entity1 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         Thread.sleep(10); // tiny sleep is to ensure creation time is different for each
entity
         entity2 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
@@ -49,11 +40,6 @@ public class BalancingNodePlacementStrategyTest {
         placementStrategy = new BalancingNodePlacementStrategy();
     }
 
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (managementContext != null) Entities.destroyAll(managementContext);
-    }
-    
     @Test
     public void testAddsBalancedWhenEmpty() throws Exception {
         LinkedHashMultimap<Location, Entity> currentMembers = LinkedHashMultimap.<Location,Entity>create();

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/group/zoneaware/ProportionalZoneFailureDetectorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/group/zoneaware/ProportionalZoneFailureDetectorTest.java
b/core/src/test/java/brooklyn/entity/group/zoneaware/ProportionalZoneFailureDetectorTest.java
index b3ed0f3..dca9b78 100644
--- a/core/src/test/java/brooklyn/entity/group/zoneaware/ProportionalZoneFailureDetectorTest.java
+++ b/core/src/test/java/brooklyn/entity/group/zoneaware/ProportionalZoneFailureDetectorTest.java
@@ -6,45 +6,33 @@ import static org.testng.Assert.assertTrue;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 
-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.group.zoneaware.ProportionalZoneFailureDetector;
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.location.LocationSpec;
 import brooklyn.location.basic.SimulatedLocation;
-import brooklyn.management.ManagementContext;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.time.Duration;
 
 import com.google.common.base.Ticker;
 
-public class ProportionalZoneFailureDetectorTest {
+public class ProportionalZoneFailureDetectorTest extends BrooklynAppUnitTestSupport {
 
-    private ManagementContext managementContext;
-    private TestApplication app;
     private TestEntity entity1;
     private SimulatedLocation loc1;
     private SimulatedLocation loc2;
     
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-        managementContext = app.getManagementContext();
-        loc1 = managementContext.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
-        loc2 = managementContext.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
+        super.setUp();
+        loc1 = mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
+        loc2 = mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
         entity1 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
     }
 
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (managementContext != null) Entities.destroyAll(managementContext);
-    }
-    
     @Test
     public void testRespectsMin() throws Exception {
         ProportionalZoneFailureDetector detector = new ProportionalZoneFailureDetector(2,
Duration.ONE_HOUR, 0.9);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/hello/LocalEntitiesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/hello/LocalEntitiesTest.java b/core/src/test/java/brooklyn/entity/hello/LocalEntitiesTest.java
index aa56c61..53dd878 100644
--- a/core/src/test/java/brooklyn/entity/hello/LocalEntitiesTest.java
+++ b/core/src/test/java/brooklyn/entity/hello/LocalEntitiesTest.java
@@ -17,12 +17,11 @@ import java.util.concurrent.atomic.AtomicReference;
 
 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.testng.collections.Lists;
 
-import brooklyn.entity.basic.ApplicationBuilder;
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.EntityInternal;
 import brooklyn.entity.basic.EntityLocal;
@@ -33,7 +32,6 @@ import brooklyn.location.basic.SimulatedLocation;
 import brooklyn.management.EntityManager;
 import brooklyn.management.Task;
 import brooklyn.test.Asserts;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.time.Time;
 
@@ -45,26 +43,21 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 
 /** tests effector invocation and a variety of sensor accessors and subscribers */
-public class LocalEntitiesTest {
+public class LocalEntitiesTest extends BrooklynAppUnitTestSupport {
 	
 	public static final Logger log = LoggerFactory.getLogger(LocalEntitiesTest.class);
 	
     private SimulatedLocation loc;
-    private TestApplication app;
     private EntityManager entityManager;
 			
-	@BeforeMethod(alwaysRun=true)
+    @BeforeMethod(alwaysRun=true)
+	@Override
 	public void setUp() throws Exception {
+	    super.setUp();
 	    loc = new SimulatedLocation();
-	    app = ApplicationBuilder.newManagedApp(TestApplication.class);
-	    entityManager = app.getManagementContext().getEntityManager();
+	    entityManager = mgmt.getEntityManager();
 	}
 
-    @AfterMethod
-    public void tearDown(){
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-
     @Test
     public void testEffectorUpdatesAttributeSensor() {
         HelloEntity h = app.createAndManageChild(EntitySpec.create(HelloEntity.class));

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/proxying/EntityManagerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/proxying/EntityManagerTest.java b/core/src/test/java/brooklyn/entity/proxying/EntityManagerTest.java
index d353e6a..f57cab9 100644
--- a/core/src/test/java/brooklyn/entity/proxying/EntityManagerTest.java
+++ b/core/src/test/java/brooklyn/entity/proxying/EntityManagerTest.java
@@ -4,14 +4,12 @@ import static org.testng.Assert.assertEquals;
 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.basic.ApplicationBuilder;
-import brooklyn.entity.basic.Entities;
 import brooklyn.management.EntityManager;
-import brooklyn.management.ManagementContext;
 import brooklyn.test.Asserts;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
@@ -21,24 +19,17 @@ import brooklyn.util.collections.MutableMap;
 import com.google.common.base.Predicates;
 import com.google.common.collect.ImmutableList;
 
-public class EntityManagerTest {
+public class EntityManagerTest extends BrooklynAppUnitTestSupport {
 
-    private TestApplication app;
-    private ManagementContext mgmt;
     private EntityManager entityManager;
 
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-        mgmt = app.getManagementContext();
+        super.setUp();
         entityManager = mgmt.getEntityManager();
     }
     
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() {
-        if (mgmt != null) Entities.destroyAll(mgmt);
-    }
-
     @Test
     public void testCreateEntityUsingSpec() {
         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/proxying/EntityProxyTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/proxying/EntityProxyTest.java b/core/src/test/java/brooklyn/entity/proxying/EntityProxyTest.java
index b33896b..92960c5 100644
--- a/core/src/test/java/brooklyn/entity/proxying/EntityProxyTest.java
+++ b/core/src/test/java/brooklyn/entity/proxying/EntityProxyTest.java
@@ -7,11 +7,11 @@ import static org.testng.Assert.assertTrue;
 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.Application;
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.Entity;
 import brooklyn.entity.basic.AbstractEntity;
 import brooklyn.entity.basic.ApplicationBuilder;
@@ -19,10 +19,8 @@ import brooklyn.entity.basic.BrooklynTaskTags;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.StartableApplication;
 import brooklyn.management.EntityManager;
-import brooklyn.management.ManagementContext;
 import brooklyn.management.Task;
 import brooklyn.management.internal.ManagementContextInternal;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableMap;
 
@@ -30,24 +28,17 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 
-public class EntityProxyTest {
+public class EntityProxyTest extends BrooklynAppUnitTestSupport {
 
-    private ManagementContext managementContext;
-    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));
-        managementContext = app.getManagementContext();
     }
     
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-
     @Test
     public void testBuiltAppGivesProxies() {
         assertIsProxy(entity);
@@ -68,7 +59,7 @@ public class EntityProxyTest {
         Object result = entity.identityEffector("abc");
         assertEquals(result, "abc");
         
-        Set<Task<?>> tasks = managementContext.getExecutionManager().getTasksWithAllTags(
+        Set<Task<?>> tasks = mgmt.getExecutionManager().getTasksWithAllTags(
                 ImmutableList.of(ManagementContextInternal.EFFECTOR_TAG, 
                 BrooklynTaskTags.tagForContextEntity(entity)));
         Task<?> task = Iterables.get(tasks, 0);
@@ -78,7 +69,7 @@ public class EntityProxyTest {
     
     @Test
     public void testEntityManagerQueriesGiveProxies() {
-        EntityManager entityManager = managementContext.getEntityManager();
+        EntityManager entityManager = mgmt.getEntityManager();
         
         Application retrievedApp = (Application) entityManager.getEntity(app.getId());
         TestEntity retrievedEntity = (TestEntity) entityManager.getEntity(entity.getId());
@@ -99,7 +90,7 @@ public class EntityProxyTest {
         assertIsProxy(result);
         assertIsProxy(Iterables.get(entity.getChildren(), 0));
         assertIsProxy(result.getParent());
-        assertIsProxy(managementContext.getEntityManager().getEntity(result.getId()));
+        assertIsProxy(mgmt.getEntityManager().getEntity(result.getId()));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/entity/trait/StartableMethodsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/trait/StartableMethodsTest.java b/core/src/test/java/brooklyn/entity/trait/StartableMethodsTest.java
index cdcf94a..f528c22 100644
--- a/core/src/test/java/brooklyn/entity/trait/StartableMethodsTest.java
+++ b/core/src/test/java/brooklyn/entity/trait/StartableMethodsTest.java
@@ -3,42 +3,35 @@ package brooklyn.entity.trait;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.fail;
 
-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.entity.trait.FailingEntity.RecordingEventListener;
 import brooklyn.location.basic.SimulatedLocation;
 import brooklyn.management.Task;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.task.Tasks;
 
 import com.google.common.collect.ImmutableList;
 
-public class StartableMethodsTest {
+public class StartableMethodsTest extends BrooklynAppUnitTestSupport {
 
     private SimulatedLocation loc;
-    private TestApplication app;
     private TestEntity entity;
     private TestEntity entity2;
     private RecordingEventListener listener;
     
     @BeforeMethod(alwaysRun=true)
-    public void setUp() {
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         loc = new SimulatedLocation();
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
         listener = new RecordingEventListener();
     }
     
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-    
     @Test
     public void testStopSequentially() {
         entity = app.createAndManageChild(EntitySpec.create(FailingEntity.class)

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/event/feed/PollerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/event/feed/PollerTest.java b/core/src/test/java/brooklyn/event/feed/PollerTest.java
index 0396869..d39a205 100644
--- a/core/src/test/java/brooklyn/event/feed/PollerTest.java
+++ b/core/src/test/java/brooklyn/event/feed/PollerTest.java
@@ -12,35 +12,34 @@ 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.test.Asserts;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.task.DynamicTasks;
 import brooklyn.util.time.Duration;
 
-public class PollerTest {
+public class PollerTest extends BrooklynAppUnitTestSupport {
 
     private static final Logger LOG = LoggerFactory.getLogger(PollerTest.class);
 
-    private TestApplication app;
     private TestEntity entity;
     private Poller<Integer> poller;
     
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+        super.setUp();
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         poller = new Poller<Integer>(entity, false);
     }
     
     @AfterMethod(alwaysRun=true)
+    @Override
     public void tearDown() throws Exception {
         if (poller != null) poller.stop();
-        if (app != null) Entities.destroyAll(app.getManagementContext());
+        super.tearDown();
     }
     
     @Test(groups={"Integration", "WIP"}) // because takes > 1 second

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/event/feed/function/FunctionFeedTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/event/feed/function/FunctionFeedTest.java b/core/src/test/java/brooklyn/event/feed/function/FunctionFeedTest.java
index a8317b8..34fac38 100644
--- a/core/src/test/java/brooklyn/event/feed/function/FunctionFeedTest.java
+++ b/core/src/test/java/brooklyn/event/feed/function/FunctionFeedTest.java
@@ -14,8 +14,7 @@ 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.basic.EntityLocal;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.event.AttributeSensor;
@@ -26,7 +25,6 @@ import brooklyn.location.Location;
 import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
 import brooklyn.test.Asserts;
 import brooklyn.test.EntityTestUtils;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 
 import com.google.common.base.Function;
@@ -35,28 +33,29 @@ import com.google.common.base.Predicates;
 import com.google.common.collect.ImmutableList;
 import com.google.common.util.concurrent.Callables;
 
-public class FunctionFeedTest {
+public class FunctionFeedTest extends BrooklynAppUnitTestSupport {
 
     final static AttributeSensor<String> SENSOR_STRING = Sensors.newStringSensor("aString",
"");
     final static AttributeSensor<Integer> SENSOR_INT = Sensors.newIntegerSensor("aLong",
"");
 
     private Location loc;
-    private TestApplication app;
     private EntityLocal entity;
     private FunctionFeed feed;
     
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
+        super.setUp();
         loc = new LocalhostMachineProvisioningLocation();
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         app.start(ImmutableList.of(loc));
     }
 
     @AfterMethod(alwaysRun=true)
+    @Override
     public void tearDown() throws Exception {
         if (feed != null) feed.stop();
-        if (app != null) Entities.destroyAll(app.getManagementContext());
+        super.tearDown();
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/event/feed/http/HttpFeedIntegrationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/event/feed/http/HttpFeedIntegrationTest.java b/core/src/test/java/brooklyn/event/feed/http/HttpFeedIntegrationTest.java
index 84ee0ef..a9740f4 100644
--- a/core/src/test/java/brooklyn/event/feed/http/HttpFeedIntegrationTest.java
+++ b/core/src/test/java/brooklyn/event/feed/http/HttpFeedIntegrationTest.java
@@ -9,8 +9,7 @@ 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.basic.EntityLocal;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.event.AttributeSensor;
@@ -21,13 +20,12 @@ import brooklyn.location.basic.PortRanges;
 import brooklyn.test.Asserts;
 import brooklyn.test.EntityTestUtils;
 import brooklyn.test.HttpService;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 
 import com.google.common.base.Functions;
 import com.google.common.collect.ImmutableList;
 
-public class HttpFeedIntegrationTest {
+public class HttpFeedIntegrationTest extends BrooklynAppUnitTestSupport {
 
     final static AttributeSensor<String> SENSOR_STRING = Sensors.newStringSensor("aString",
"");
     final static AttributeSensor<Integer> SENSOR_INT = Sensors.newIntegerSensor("aLong",
"");
@@ -35,23 +33,24 @@ public class HttpFeedIntegrationTest {
     private HttpService httpService;
 
     private Location loc;
-    private TestApplication app;
     private EntityLocal entity;
     private HttpFeed feed;
     
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
+        super.setUp();
         loc = new LocalhostMachineProvisioningLocation();
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         app.start(ImmutableList.of(loc));
     }
 
     @AfterMethod(alwaysRun=true)
+    @Override
     public void tearDown() throws Exception {
         if (feed != null) feed.stop();
         if (httpService != null) httpService.shutdown();
-        if (app != null) Entities.destroyAll(app.getManagementContext());
+        super.tearDown();
     }
 
     @Test(groups = {"Integration"})

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/event/feed/http/HttpFeedTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/event/feed/http/HttpFeedTest.java b/core/src/test/java/brooklyn/event/feed/http/HttpFeedTest.java
index 129281f..a562068 100644
--- a/core/src/test/java/brooklyn/event/feed/http/HttpFeedTest.java
+++ b/core/src/test/java/brooklyn/event/feed/http/HttpFeedTest.java
@@ -14,7 +14,7 @@ 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.EntityFunctions;
 import brooklyn.entity.basic.EntityInternal;
@@ -26,7 +26,6 @@ import brooklyn.event.feed.FeedConfig;
 import brooklyn.event.feed.PollConfig;
 import brooklyn.location.Location;
 import brooklyn.test.Asserts;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableList;
 import brooklyn.util.collections.MutableMap;
@@ -43,7 +42,7 @@ import com.google.common.collect.Lists;
 import com.google.mockwebserver.MockResponse;
 import com.google.mockwebserver.SocketPolicy;
 
-public class HttpFeedTest {
+public class HttpFeedTest extends BrooklynAppUnitTestSupport {
 
     private static final Logger log = LoggerFactory.getLogger(HttpFeedTest.class);
     
@@ -56,12 +55,13 @@ public class HttpFeedTest {
     private URL baseUrl;
     
     private Location loc;
-    private TestApplication app;
     private EntityLocal entity;
     private HttpFeed feed;
     
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
+        super.setUp();
         server = BetterMockWebServer.newInstanceLocalhost();
         for (int i = 0; i < 100; i++) {
             server.enqueue(new MockResponse().setResponseCode(200).addHeader("content-type:
application/json").setBody("{\"foo\":\"myfoo\"}"));
@@ -69,18 +69,18 @@ public class HttpFeedTest {
         server.play();
         baseUrl = server.getUrl("/");
 
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
         loc = app.newLocalhostProvisioningLocation();
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         app.start(ImmutableList.of(loc));
     }
 
     @AfterMethod(alwaysRun=true)
+    @Override
     public void tearDown() throws Exception {
         if (feed != null) feed.stop();
         if (server != null) server.shutdown();
-        if (app != null) Entities.destroyAll(app.getManagementContext());
         feed = null;
+        super.tearDown();
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/event/feed/shell/ShellFeedIntegrationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/event/feed/shell/ShellFeedIntegrationTest.java b/core/src/test/java/brooklyn/event/feed/shell/ShellFeedIntegrationTest.java
index a59c1e0..587c73b 100644
--- a/core/src/test/java/brooklyn/event/feed/shell/ShellFeedIntegrationTest.java
+++ b/core/src/test/java/brooklyn/event/feed/shell/ShellFeedIntegrationTest.java
@@ -9,8 +9,7 @@ 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.basic.EntityLocal;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.event.AttributeSensor;
@@ -21,7 +20,6 @@ import brooklyn.event.feed.ssh.SshValueFunctions;
 import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
 import brooklyn.test.Asserts;
 import brooklyn.test.EntityTestUtils;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.stream.Streams;
 
@@ -29,29 +27,30 @@ import com.google.common.base.Function;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 
-public class ShellFeedIntegrationTest {
+public class ShellFeedIntegrationTest extends BrooklynAppUnitTestSupport {
 
     final static AttributeSensor<String> SENSOR_STRING = Sensors.newStringSensor("aString",
"");
     final static AttributeSensor<Integer> SENSOR_INT = Sensors.newIntegerSensor("anInt",
"");
     final static AttributeSensor<Long> SENSOR_LONG = Sensors.newLongSensor("aLong",
"");
 
     private LocalhostMachineProvisioningLocation loc;
-    private TestApplication app;
     private EntityLocal entity;
     private ShellFeed feed;
     
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
+        super.setUp();
         loc = new LocalhostMachineProvisioningLocation();
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         app.start(ImmutableList.of(loc));
     }
 
     @AfterMethod(alwaysRun=true)
+    @Override
     public void tearDown() throws Exception {
         if (feed != null) feed.stop();
-        if (app != null) Entities.destroyAll(app.getManagementContext());
+        super.tearDown();
         if (loc != null) Streams.closeQuietly(loc);
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/event/feed/ssh/SshFeedIntegrationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/event/feed/ssh/SshFeedIntegrationTest.java b/core/src/test/java/brooklyn/event/feed/ssh/SshFeedIntegrationTest.java
index de46391..d7f0881 100644
--- a/core/src/test/java/brooklyn/event/feed/ssh/SshFeedIntegrationTest.java
+++ b/core/src/test/java/brooklyn/event/feed/ssh/SshFeedIntegrationTest.java
@@ -10,7 +10,7 @@ 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.Attributes;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.EntityLocal;
@@ -21,8 +21,6 @@ import brooklyn.event.basic.Sensors;
 import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
 import brooklyn.location.basic.SshMachineLocation;
 import brooklyn.test.EntityTestUtils;
-import brooklyn.test.entity.LocalManagementContextForTests;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.exceptions.Exceptions;
@@ -37,7 +35,7 @@ import com.google.common.base.Predicates;
 import com.google.common.base.Supplier;
 import com.google.common.collect.ImmutableList;
 
-public class SshFeedIntegrationTest {
+public class SshFeedIntegrationTest extends BrooklynAppUnitTestSupport {
 
     private static final Logger log = LoggerFactory.getLogger(SshFeedIntegrationTest.class);
     
@@ -46,13 +44,13 @@ public class SshFeedIntegrationTest {
 
     private LocalhostMachineProvisioningLocation loc;
     private SshMachineLocation machine;
-    private TestApplication app;
     private EntityLocal entity;
     private SshFeed feed;
     
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class, new LocalManagementContextForTests());
+        super.setUp();
         loc = app.newLocalhostProvisioningLocation();
         machine = loc.obtain();
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
@@ -60,9 +58,10 @@ public class SshFeedIntegrationTest {
     }
 
     @AfterMethod(alwaysRun=true)
+    @Override
     public void tearDown() throws Exception {
         if (feed != null) feed.stop();
-        if (app != null) Entities.destroyAll(app.getManagementContext());
+        super.tearDown();
         if (loc != null) Streams.closeQuietly(loc);
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/location/basic/LocationManagementTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/location/basic/LocationManagementTest.java b/core/src/test/java/brooklyn/location/basic/LocationManagementTest.java
index 66ff21a..8b4d62d 100644
--- a/core/src/test/java/brooklyn/location/basic/LocationManagementTest.java
+++ b/core/src/test/java/brooklyn/location/basic/LocationManagementTest.java
@@ -6,38 +6,27 @@ import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertSame;
 import static org.testng.Assert.assertTrue;
 
-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.location.LocationSpec;
 import brooklyn.management.LocationManager;
-import brooklyn.management.ManagementContext;
-import brooklyn.test.entity.TestApplication;
 
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterables;
 
-public class LocationManagementTest {
+public class LocationManagementTest extends BrooklynAppUnitTestSupport {
 
-    private TestApplication app;
-    private ManagementContext managementContext;
     private LocationManager locationManager;
 
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-        managementContext = app.getManagementContext();
-        locationManager = managementContext.getLocationManager();
+        super.setUp();
+        locationManager = mgmt.getLocationManager();
     }
     
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-
     @Test
     public void testCreateLocationUsingSpec() {
         SshMachineLocation loc = locationManager.createLocation(LocationSpec.create(SshMachineLocation.class)
@@ -50,7 +39,7 @@ public class LocationManagementTest {
     @Test
     public void testCreateLocationUsingResolver() {
         String spec = "byon:(hosts=\"1.1.1.1\")";
-        FixedListMachineProvisioningLocation<SshMachineLocation> loc = (FixedListMachineProvisioningLocation<SshMachineLocation>)
managementContext.getLocationRegistry().resolve(spec);
+        FixedListMachineProvisioningLocation<SshMachineLocation> loc = (FixedListMachineProvisioningLocation<SshMachineLocation>)
mgmt.getLocationRegistry().resolve(spec);
         SshMachineLocation machine = Iterables.getOnlyElement(loc.getAllMachines());
         
         assertSame(locationManager.getLocation(loc.getId()), loc);
@@ -60,7 +49,7 @@ public class LocationManagementTest {
     @Test
     public void testChildrenOfManagedLocationAutoManaged() {
         String spec = "byon:(hosts=\"1.1.1.1\")";
-        FixedListMachineProvisioningLocation<SshMachineLocation> loc = (FixedListMachineProvisioningLocation<SshMachineLocation>)
managementContext.getLocationRegistry().resolve(spec);
+        FixedListMachineProvisioningLocation<SshMachineLocation> loc = (FixedListMachineProvisioningLocation<SshMachineLocation>)
mgmt.getLocationRegistry().resolve(spec);
         SshMachineLocation machine = new SshMachineLocation(ImmutableMap.of("address", "1.2.3.4"));
 
         loc.addChild(machine);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/management/internal/LocalSubscriptionManagerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/management/internal/LocalSubscriptionManagerTest.java
b/core/src/test/java/brooklyn/management/internal/LocalSubscriptionManagerTest.java
index 6e683cb..39bf983 100644
--- a/core/src/test/java/brooklyn/management/internal/LocalSubscriptionManagerTest.java
+++ b/core/src/test/java/brooklyn/management/internal/LocalSubscriptionManagerTest.java
@@ -9,12 +9,11 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 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.BasicGroup;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.proxying.EntitySpec;
@@ -22,30 +21,24 @@ import brooklyn.event.SensorEvent;
 import brooklyn.event.SensorEventListener;
 import brooklyn.management.SubscriptionHandle;
 import brooklyn.management.SubscriptionManager;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 
 /**
  * testing the {@link SubscriptionManager} and associated classes.
  */
-public class LocalSubscriptionManagerTest {
+public class LocalSubscriptionManagerTest extends BrooklynAppUnitTestSupport {
     
     private static final int TIMEOUT_MS = 5000;
     
-    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(){
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-
     private void manage(Entity ...entities) {
         for (Entity e: entities)
             Entities.manage(e);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/policy/basic/EnricherConfigTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/policy/basic/EnricherConfigTest.java b/core/src/test/java/brooklyn/policy/basic/EnricherConfigTest.java
index 35945ba..8433bb9 100644
--- a/core/src/test/java/brooklyn/policy/basic/EnricherConfigTest.java
+++ b/core/src/test/java/brooklyn/policy/basic/EnricherConfigTest.java
@@ -5,23 +5,19 @@ 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.config.ConfigKey;
 import brooklyn.enricher.basic.AbstractEnricher;
-import brooklyn.entity.basic.ApplicationBuilder;
-import brooklyn.entity.basic.Entities;
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.event.basic.BasicConfigKey;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.flags.SetFromFlag;
 
 /**
  * Test that configuration properties are usable and inherited correctly.
  */
-public class EnricherConfigTest {
+public class EnricherConfigTest extends BrooklynAppUnitTestSupport {
     
     // TODO These tests are a copy of PolicyConfigMapUsageTest, which is a code smell.
     // However, the src/main/java code does not contain as much duplication.
@@ -46,18 +42,6 @@ public class EnricherConfigTest {
     
     private BasicConfigKey<String> differentKey = new BasicConfigKey<String>(String.class,
"differentkey", "diffval");
 
-    private TestApplication app;
-    
-    @BeforeMethod(alwaysRun=true)
-    public void setUp() {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-    }
-    
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-    
     @Test
     public void testConfigFlagsPassedInAtConstructionIsAvailable() throws Exception {
         MyEnricher enricher = new MyEnricher(MutableMap.builder()

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/policy/basic/PolicyConfigMapUsageTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/policy/basic/PolicyConfigMapUsageTest.java b/core/src/test/java/brooklyn/policy/basic/PolicyConfigMapUsageTest.java
index ffbf1e8..65fada0 100644
--- a/core/src/test/java/brooklyn/policy/basic/PolicyConfigMapUsageTest.java
+++ b/core/src/test/java/brooklyn/policy/basic/PolicyConfigMapUsageTest.java
@@ -8,16 +8,12 @@ import java.util.Map;
 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.basic.ApplicationBuilder;
-import brooklyn.entity.basic.Entities;
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.event.basic.BasicConfigKey;
 import brooklyn.event.basic.DependentConfiguration;
-import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.exceptions.Exceptions;
@@ -28,7 +24,7 @@ import com.google.common.util.concurrent.Callables;
 /**
  * Test that configuration properties are usable and inherited correctly.
  */
-public class PolicyConfigMapUsageTest {
+public class PolicyConfigMapUsageTest extends BrooklynAppUnitTestSupport {
     private static final int EARLY_RETURN_GRACE = 10;
 
     public static class MyPolicy extends AbstractPolicy {
@@ -51,18 +47,6 @@ public class PolicyConfigMapUsageTest {
     
     private BasicConfigKey<String> differentKey = new BasicConfigKey<String>(String.class,
"differentkey", "diffval");
 
-    private TestApplication app;
-    
-    @BeforeMethod(alwaysRun=true)
-    public void setUp() {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-    }
-    
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-    
     @Test
     public void testConfigFlagsPassedInAtConstructionIsAvailable() throws Exception {
         MyPolicy policy = new MyPolicy(MutableMap.builder()

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1207bc13/core/src/test/java/brooklyn/util/task/TasksTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/util/task/TasksTest.java b/core/src/test/java/brooklyn/util/task/TasksTest.java
index f12b130..bdf43a5 100644
--- a/core/src/test/java/brooklyn/util/task/TasksTest.java
+++ b/core/src/test/java/brooklyn/util/task/TasksTest.java
@@ -6,12 +6,10 @@ import static org.testng.Assert.assertEquals;
 import java.util.Map;
 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.basic.Entities;
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.management.ExecutionContext;
 import brooklyn.test.entity.TestApplication;
 
@@ -21,22 +19,17 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 
 
-public class TasksTest {
+public class TasksTest extends BrooklynAppUnitTestSupport {
 
-    private TestApplication app;
     private ExecutionContext executionContext;
 
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+        super.setUp();
         executionContext = app.getExecutionContext();
     }
     
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-    
     @Test
     public void testResolveNull() throws Exception {
         assertResolvesValue(null, String.class, null);


Mime
View raw message