You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2015/12/17 13:32:33 UTC
[2/7] incubator-brooklyn git commit: Simplify GeoDns tests
Simplify GeoDns 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/06a8f610
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/06a8f610
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/06a8f610
Branch: refs/heads/master
Commit: 06a8f610a8b57860b7a7016328e02eb5375d7116
Parents: c85c378
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Wed Dec 9 16:31:19 2015 +0000
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Wed Dec 9 16:55:12 2015 +0000
----------------------------------------------------------------------
.../geoscaling/GeoscalingDnsServiceImpl.java | 18 +--
.../entity/dns/AbstractGeoDnsServiceTest.java | 125 +++++++++----------
.../geoscaling/GeoscalingIntegrationTest.java | 62 +++++----
.../dns/geoscaling/GeoscalingWebClientTest.java | 41 ++++--
4 files changed, 136 insertions(+), 110 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/06a8f610/software/webapp/src/main/java/org/apache/brooklyn/entity/dns/geoscaling/GeoscalingDnsServiceImpl.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/main/java/org/apache/brooklyn/entity/dns/geoscaling/GeoscalingDnsServiceImpl.java b/software/webapp/src/main/java/org/apache/brooklyn/entity/dns/geoscaling/GeoscalingDnsServiceImpl.java
index 4273dac..e04b8ec 100644
--- a/software/webapp/src/main/java/org/apache/brooklyn/entity/dns/geoscaling/GeoscalingDnsServiceImpl.java
+++ b/software/webapp/src/main/java/org/apache/brooklyn/entity/dns/geoscaling/GeoscalingDnsServiceImpl.java
@@ -61,9 +61,11 @@ public class GeoscalingDnsServiceImpl extends AbstractGeoDnsServiceImpl implemen
super.init();
// defaulting to randomized subdomains makes deploying multiple applications easier
- if (getConfig(RANDOMIZE_SUBDOMAIN_NAME)==null) config().set(RANDOMIZE_SUBDOMAIN_NAME, true);
-
- Boolean trustAll = getConfig(SSL_TRUST_ALL);
+ if (config().get(RANDOMIZE_SUBDOMAIN_NAME) == null) {
+ config().set(RANDOMIZE_SUBDOMAIN_NAME, true);
+ }
+
+ Boolean trustAll = config().get(SSL_TRUST_ALL);
if (Boolean.TRUE.equals(trustAll)) {
webClient = new GeoscalingWebClient(HttpTool.httpClientBuilder().trustAll().build());
} else {
@@ -88,11 +90,11 @@ public class GeoscalingDnsServiceImpl extends AbstractGeoDnsServiceImpl implemen
boolean isConfigured = false;
public synchronized void applyConfig() {
- randomizeSmartSubdomainName = getConfig(RANDOMIZE_SUBDOMAIN_NAME);
- username = getConfig(GEOSCALING_USERNAME);
- password = getConfig(GEOSCALING_PASSWORD);
- primaryDomainName = getConfig(GEOSCALING_PRIMARY_DOMAIN_NAME);
- smartSubdomainName = getConfig(GEOSCALING_SMART_SUBDOMAIN_NAME);
+ randomizeSmartSubdomainName = config().get(RANDOMIZE_SUBDOMAIN_NAME);
+ username = config().get(GEOSCALING_USERNAME);
+ password = config().get(GEOSCALING_PASSWORD);
+ primaryDomainName = config().get(GEOSCALING_PRIMARY_DOMAIN_NAME);
+ smartSubdomainName = config().get(GEOSCALING_SMART_SUBDOMAIN_NAME);
// Ensure all mandatory configuration is provided.
checkNotNull(username, "The GeoScaling username is not specified");
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/06a8f610/software/webapp/src/test/java/org/apache/brooklyn/entity/dns/AbstractGeoDnsServiceTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/org/apache/brooklyn/entity/dns/AbstractGeoDnsServiceTest.java b/software/webapp/src/test/java/org/apache/brooklyn/entity/dns/AbstractGeoDnsServiceTest.java
index 5ce2c1b..2048680 100644
--- a/software/webapp/src/test/java/org/apache/brooklyn/entity/dns/AbstractGeoDnsServiceTest.java
+++ b/software/webapp/src/test/java/org/apache/brooklyn/entity/dns/AbstractGeoDnsServiceTest.java
@@ -18,6 +18,7 @@
*/
package org.apache.brooklyn.entity.dns;
+import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import java.util.Collection;
@@ -35,31 +36,23 @@ import org.apache.brooklyn.api.mgmt.ManagementContext;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.core.config.ConfigKeys;
import org.apache.brooklyn.core.entity.Attributes;
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.entity.EntityInternal;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
+import org.apache.brooklyn.core.entity.EntityAsserts;
import org.apache.brooklyn.core.location.BasicLocationRegistry;
import org.apache.brooklyn.core.location.LocationConfigKeys;
import org.apache.brooklyn.core.location.Locations;
import org.apache.brooklyn.core.location.Machines;
import org.apache.brooklyn.core.location.SimulatedLocation;
import org.apache.brooklyn.core.location.geo.HostGeoInfo;
-import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
-import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
import org.apache.brooklyn.core.test.entity.TestEntity;
-import org.apache.brooklyn.entity.dns.AbstractGeoDnsService;
-import org.apache.brooklyn.entity.dns.AbstractGeoDnsServiceImpl;
-import org.apache.brooklyn.entity.dns.AbstractGeoDnsServiceTest;
import org.apache.brooklyn.entity.group.DynamicFabric;
import org.apache.brooklyn.entity.group.DynamicGroup;
import org.apache.brooklyn.entity.group.DynamicRegionsFabric;
-import org.apache.brooklyn.test.EntityTestUtils;
import org.apache.brooklyn.util.collections.CollectionFunctionals;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.apache.brooklyn.location.ssh.SshMachineLocation;
@@ -69,7 +62,8 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
-public class AbstractGeoDnsServiceTest {
+public class AbstractGeoDnsServiceTest extends BrooklynAppUnitTestSupport {
+
public static final Logger log = LoggerFactory.getLogger(AbstractGeoDnsServiceTest.class);
private static final String WEST_IP = "100.0.0.1";
@@ -80,8 +74,6 @@ public class AbstractGeoDnsServiceTest {
private static final String NORTH_IP = "10.0.0.1";
private static final double NORTH_LATITUDE = 60, NORTH_LONGITUDE = 0;
- private ManagementContext managementContext;
-
private Location westParent;
private Location westChild;
private Location westChildWithLocation;
@@ -92,16 +84,15 @@ public class AbstractGeoDnsServiceTest {
private Location northParent;
private Location northChildWithLocation;
- private TestApplication app;
private DynamicRegionsFabric fabric;
private DynamicGroup testEntities;
private GeoDnsTestService geoDns;
-
+ @Override
@BeforeMethod(alwaysRun=true)
- public void setup() {
- managementContext = new LocalManagementContext();
-
+ public void setUp() throws Exception {
+ super.setUp();
+
westParent = newSimulatedLocation("West parent", WEST_LATITUDE, WEST_LONGITUDE);
// west uses public IP for name, so is always picked up
@@ -116,7 +107,7 @@ public class AbstractGeoDnsServiceTest {
// north has a private IP and private hostname so should not be picked up when we turn off ADD_ANYTHING
northParent = newSimulatedLocation("North parent", NORTH_LATITUDE, NORTH_LONGITUDE);
northChildWithLocation = newSshMachineLocation("North child", "localhost", NORTH_IP, northParent, NORTH_LATITUDE, NORTH_LONGITUDE);
- ((BasicLocationRegistry)managementContext.getLocationRegistry()).registerResolver(new LocationResolver() {
+ ((BasicLocationRegistry) mgmt.getLocationRegistry()).registerResolver(new LocationResolver() {
@Override
public Location newLocationFromString(Map locationFlags, String spec, LocationRegistry registry) {
if (!spec.equals("test:north")) throw new IllegalStateException("unsupported");
@@ -135,41 +126,36 @@ public class AbstractGeoDnsServiceTest {
}
});
- Locations.manage(westParent, managementContext);
- Locations.manage(eastParent, managementContext);
- Locations.manage(northParent, managementContext);
+ Locations.manage(westParent, mgmt);
+ Locations.manage(eastParent, mgmt);
+ Locations.manage(northParent, mgmt);
- app = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext);
fabric = app.createAndManageChild(EntitySpec.create(DynamicRegionsFabric.class)
.configure(DynamicFabric.MEMBER_SPEC, EntitySpec.create(TestEntity.class)));
-
+
testEntities = app.createAndManageChild(EntitySpec.create(DynamicGroup.class)
.configure(DynamicGroup.ENTITY_FILTER, Predicates.instanceOf(TestEntity.class)));
- geoDns = app.createAndManageChild(EntitySpec.create(GeoDnsTestService.class));
- geoDns.setTargetEntityProvider(testEntities);
- }
- @AfterMethod(alwaysRun=true)
- public void tearDown() throws Exception {
- if (app != null) Entities.destroyAll(app.getManagementContext());
+ geoDns = app.createAndManageChild(EntitySpec.create(GeoDnsTestService.class)
+ .configure(AbstractGeoDnsService.ENTITY_PROVIDER, testEntities));
}
private SimulatedLocation newSimulatedLocation(String name, double lat, double lon) {
- return managementContext.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class)
+ return mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class)
.displayName(name)
.configure("latitude", lat)
.configure("longitude", lon));
}
private Location newSshMachineLocation(String name, String address, Location parent) {
- return managementContext.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)
+ return mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)
.parent(parent)
.displayName(name)
.configure("address", address));
}
private Location newSshMachineLocation(String name, String hostname, String address, Location parent, double lat, double lon) {
- return managementContext.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)
+ return mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)
.parent(parent)
.displayName(name)
.configure("hostname", hostname)
@@ -183,85 +169,92 @@ public class AbstractGeoDnsServiceTest {
app.start( ImmutableList.of(westChildWithLocation, eastChildWithLocationAndWithPrivateHostname) );
publishSensors(2, true, true, true);
- EntityTestUtils.assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(2));
- assertTrue(geoDns.getTargetHostsByName().containsKey("West child with location"), "targets="+geoDns.getTargetHostsByName());
- assertTrue(geoDns.getTargetHostsByName().containsKey("East child with location"), "targets="+geoDns.getTargetHostsByName());
+ assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(2));
+ assertIsTarget("West child with location");
+ assertIsTarget("East child with location");
}
-
+
@Test
public void testGeoInfoOnParentLocation() {
app.start( ImmutableList.of(westChild, eastChild) );
publishSensors(2, true, false, false);
-
- EntityTestUtils.assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(2));
- assertTrue(geoDns.getTargetHostsByName().containsKey("West child"), "targets="+geoDns.getTargetHostsByName());
- assertTrue(geoDns.getTargetHostsByName().containsKey("East child"), "targets="+geoDns.getTargetHostsByName());
+
+ assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(2));
+ assertIsTarget("West child");
+ assertIsTarget("East child");
}
@Test
public void testSubscribesToHostname() {
- ((EntityInternal)geoDns).config().set(GeoDnsTestServiceImpl.ADD_ANYTHING, false);
+ geoDns.config().set(GeoDnsTestServiceImpl.ADD_ANYTHING, false);
app.start( ImmutableList.of(westChild, eastChildWithLocationAndWithPrivateHostname) );
Assert.assertEquals(geoDns.getTargetHostsByName().size(), 0);
publishSensors(2, true, true, true);
-
- EntityTestUtils.assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(2));
+
+ assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(2));
Assert.assertEquals(geoDns.getTargetHostsByName().size(), 2);
- assertTrue(geoDns.getTargetHostsByName().containsKey("West child"), "targets="+geoDns.getTargetHostsByName());
- assertTrue(geoDns.getTargetHostsByName().containsKey("East child with location"), "targets="+geoDns.getTargetHostsByName());
+ assertIsTarget("West child");
+ assertIsTarget("East child with location");
}
protected void publishSensors(int expectedSize, boolean includeServiceUp, boolean includeHostname, boolean includeAddress) {
// First wait for the right size of group; the dynamic group gets notified asynchronously
// of nodes added/removed, so if we don't wait then might not set value for all members.
- EntityTestUtils.assertGroupSizeEqualsEventually(testEntities, expectedSize);
-
+ EntityAsserts.assertGroupSizeEqualsEventually(testEntities, expectedSize);
+
for (Entity e: testEntities.getMembers()) {
if (includeServiceUp)
- ((EntityInternal)e).sensors().set(Attributes.SERVICE_UP, true);
-
+ e.sensors().set(Attributes.SERVICE_UP, true);
+
SshMachineLocation l = Machines.findUniqueMachineLocation(e.getLocations(), SshMachineLocation.class).get();
if (includeAddress)
- ((EntityInternal)e).sensors().set(Attributes.ADDRESS, l.getAddress().getHostAddress());
+ e.sensors().set(Attributes.ADDRESS, l.getAddress().getHostAddress());
String h = (String) l.config().getBag().getStringKey("hostname");
if (h==null) h = l.getAddress().getHostName();
if (includeHostname)
- ((EntityInternal)e).sensors().set(Attributes.HOSTNAME, h);
+ e.sensors().set(Attributes.HOSTNAME, h);
}
}
-
+
@Test
public void testChildAddedLate() {
app.start( ImmutableList.of(westChild, eastChildWithLocationAndWithPrivateHostname) );
publishSensors(2, true, false, false);
- EntityTestUtils.assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(2));
-
+ assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(2));
+
String id3 = fabric.addRegion("test:north");
publishSensors(3, true, false, false);
try {
- EntityTestUtils.assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(3));
+ assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(3));
} catch (Throwable e) {
log.warn("Did not pick up third entity, targets are "+geoDns.getAttribute(AbstractGeoDnsService.TARGETS)+" (rethrowing): "+e);
Exceptions.propagate(e);
}
- assertTrue(geoDns.getTargetHostsByName().containsKey("North child"), "targets="+geoDns.getTargetHostsByName());
-
- log.info("targets: "+geoDns.getTargetHostsByName());
- }
+ assertIsTarget("North child");
+ log.info("targets: "+geoDns.getTargetHostsByName());
+ }
@Test
public void testFiltersEntirelyPrivate() {
- ((EntityInternal)geoDns).config().set(GeoDnsTestServiceImpl.ADD_ANYTHING, false);
+ geoDns.config().set(GeoDnsTestServiceImpl.ADD_ANYTHING, false);
app.start( ImmutableList.of(westChild, eastChildWithLocationAndWithPrivateHostname, northChildWithLocation) );
Assert.assertEquals(geoDns.getTargetHostsByName().size(), 0);
publishSensors(3, true, true, true);
-
- EntityTestUtils.assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(2));
+
+ assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(2));
Assert.assertEquals(geoDns.getTargetHostsByName().size(), 2);
- assertTrue(geoDns.getTargetHostsByName().containsKey("West child"), "targets="+geoDns.getTargetHostsByName());
- assertTrue(geoDns.getTargetHostsByName().containsKey("East child with location"), "targets="+geoDns.getTargetHostsByName());
- assertTrue(!geoDns.getTargetHostsByName().containsKey("North child"), "targets="+geoDns.getTargetHostsByName());
+ assertIsTarget("West child");
+ assertIsTarget("East child with location");
+ assertIsNotTarget("North child");
+ }
+
+ private void assertIsTarget(String target) {
+ assertTrue(geoDns.getTargetHostsByName().containsKey(target), "targets=" + geoDns.getTargetHostsByName());
+ }
+
+ private void assertIsNotTarget(String target) {
+ assertFalse(geoDns.getTargetHostsByName().containsKey(target), "targets=" + geoDns.getTargetHostsByName());
}
@ImplementedBy(GeoDnsTestServiceImpl.class)
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/06a8f610/software/webapp/src/test/java/org/apache/brooklyn/entity/dns/geoscaling/GeoscalingIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/org/apache/brooklyn/entity/dns/geoscaling/GeoscalingIntegrationTest.java b/software/webapp/src/test/java/org/apache/brooklyn/entity/dns/geoscaling/GeoscalingIntegrationTest.java
index f030987..75c6c2f 100644
--- a/software/webapp/src/test/java/org/apache/brooklyn/entity/dns/geoscaling/GeoscalingIntegrationTest.java
+++ b/software/webapp/src/test/java/org/apache/brooklyn/entity/dns/geoscaling/GeoscalingIntegrationTest.java
@@ -22,20 +22,19 @@ import static org.testng.Assert.assertEquals;
import java.net.InetAddress;
-import org.apache.brooklyn.api.entity.EntityLocal;
import org.apache.brooklyn.api.entity.EntitySpec;
import org.apache.brooklyn.api.location.LocationSpec;
import org.apache.brooklyn.api.mgmt.ManagementContext;
import org.apache.brooklyn.core.entity.Attributes;
-import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.internal.BrooklynProperties;
import org.apache.brooklyn.core.location.geo.HostGeoInfo;
import org.apache.brooklyn.core.location.geo.HostGeoLookup;
import org.apache.brooklyn.core.location.geo.MaxMind2HostGeoLookup;
import org.apache.brooklyn.core.location.geo.UtraceHostGeoLookup;
-import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
+import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
+import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
import org.apache.brooklyn.core.test.entity.TestEntity;
-import org.apache.brooklyn.entity.dns.geoscaling.GeoscalingDnsService;
-import org.apache.brooklyn.entity.dns.geoscaling.GeoscalingScriptGenerator;
import org.apache.brooklyn.entity.group.DynamicGroup;
import org.apache.brooklyn.test.Asserts;
import org.apache.brooklyn.util.collections.MutableMap;
@@ -44,6 +43,7 @@ import org.apache.brooklyn.util.internal.BrooklynSystemProperties;
import org.apache.brooklyn.util.net.Networking;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.testng.SkipException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -55,7 +55,7 @@ import com.google.common.collect.ImmutableList;
/**
* {@link GeoscalingScriptGenerator} unit tests.
*/
-public class GeoscalingIntegrationTest {
+public class GeoscalingIntegrationTest extends BrooklynAppUnitTestSupport {
private static final Logger LOG = LoggerFactory.getLogger(GeoscalingIntegrationTest.class);
@@ -64,8 +64,6 @@ public class GeoscalingIntegrationTest {
private final InetAddress addrWithGeo = Networking.getLocalHost();
private final InetAddress addrWithoutGeo = Networking.getInetAddressWithFixedName(StubHostGeoLookup.HOMELESS_IP);
- private ManagementContext mgmt;
- private TestApplication app;
private TestEntity target;
private DynamicGroup group;
private GeoscalingDnsService geoDns;
@@ -73,28 +71,35 @@ public class GeoscalingIntegrationTest {
private SshMachineLocation locWithGeo;
private SshMachineLocation locWithoutGeo;
-
+
+ @Override
@BeforeMethod(alwaysRun=true)
public void setUp() throws Exception {
+ // Want to load username and password from user's properties.
+ mgmt = LocalManagementContextForTests.newInstance(BrooklynProperties.Factory.newDefault());
+ super.setUp();
+
origGeoLookupImpl = BrooklynSystemProperties.HOST_GEO_LOOKUP_IMPL.getValue();
HostGeoInfo.clearCachedLookup();
- app = TestApplication.Factory.newManagedInstanceForTests();
- mgmt = app.getManagementContext();
-
target = app.createAndManageChild(EntitySpec.create(TestEntity.class));
-
group = app.createAndManageChild(EntitySpec.create(DynamicGroup.class)
.configure(DynamicGroup.ENTITY_FILTER, Predicates.instanceOf(TestEntity.class)));
-
+
+ String username = getBrooklynProperty(mgmt, "brooklyn.geoscaling.username");
+ String password = getBrooklynProperty(mgmt, "brooklyn.geoscaling.password");
+ if (username == null || password == null) {
+ throw new SkipException("Set brooklyn.geoscaling.username and brooklyn.geoscaling.password in brooklyn.properties to enable test");
+ }
+
geoDns = app.createAndManageChild(EntitySpec.create(GeoscalingDnsService.class)
.displayName("Geo-DNS")
- .configure("username", "cloudsoft")
- .configure("password", "cl0uds0ft")
- .configure("primaryDomainName", primaryDomain)
- .configure("smartSubdomainName", subDomain)
- .configure("targetEntityProvider", group));
-
+ .configure(GeoscalingDnsService.GEOSCALING_USERNAME, username)
+ .configure(GeoscalingDnsService.GEOSCALING_PASSWORD, password)
+ .configure(GeoscalingDnsService.GEOSCALING_PRIMARY_DOMAIN_NAME, primaryDomain)
+ .configure(GeoscalingDnsService.GEOSCALING_SMART_SUBDOMAIN_NAME, subDomain)
+ .configure(GeoscalingDnsService.ENTITY_PROVIDER, group));
+
locWithGeo = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)
.configure("address", addrWithGeo)
.configure("name", "Edinburgh")
@@ -106,22 +111,27 @@ public class GeoscalingIntegrationTest {
.configure("address", addrWithoutGeo)
.configure("name", "Nowhere"));
}
-
+
+ @Override
@AfterMethod(alwaysRun=true)
public void tearDown() throws Exception {
+ super.tearDown();
if (origGeoLookupImpl != null) {
System.setProperty(BrooklynSystemProperties.HOST_GEO_LOOKUP_IMPL.getPropertyName(), origGeoLookupImpl);
} else {
System.clearProperty(BrooklynSystemProperties.HOST_GEO_LOOKUP_IMPL.getPropertyName());
}
- if (mgmt != null) Entities.destroyAll(mgmt);
HostGeoInfo.clearCachedLookup();
}
-
+
+ private String getBrooklynProperty(ManagementContext mgmt, String property) {
+ return ((ManagementContextInternal) mgmt).getBrooklynProperties().getFirst(property);
+ }
+
@Test(groups={"Integration"})
public void testRoutesToExpectedLocation() {
// Without this config, running on a home network (i.e. no public IP) the entity will have a private IP and will be ignored
- ((EntityLocal)geoDns).config().set(GeoscalingDnsService.INCLUDE_HOMELESS_ENTITIES, true);
+ geoDns.config().set(GeoscalingDnsService.INCLUDE_HOMELESS_ENTITIES, true);
target.sensors().set(Attributes.HOSTNAME,addrWithGeo.getHostName());
@@ -135,7 +145,7 @@ public class GeoscalingIntegrationTest {
@Test(groups={"Integration"})
public void testIgnoresAddressWithoutGeography() throws Exception {
System.setProperty(BrooklynSystemProperties.HOST_GEO_LOOKUP_IMPL.getPropertyName(), StubHostGeoLookup.class.getName());
- ((EntityLocal)geoDns).config().set(GeoscalingDnsService.INCLUDE_HOMELESS_ENTITIES, false); // false is default
+ geoDns.config().set(GeoscalingDnsService.INCLUDE_HOMELESS_ENTITIES, false); // false is default
app.start(ImmutableList.of(locWithoutGeo));
target.sensors().set(Attributes.HOSTNAME, StubHostGeoLookup.HOMELESS_IP);
@@ -152,7 +162,7 @@ public class GeoscalingIntegrationTest {
@Test(groups={"Integration"})
public void testIncludesAddressWithoutGeography() {
System.setProperty(BrooklynSystemProperties.HOST_GEO_LOOKUP_IMPL.getPropertyName(), StubHostGeoLookup.class.getName());
- ((EntityLocal)geoDns).config().set(GeoscalingDnsService.INCLUDE_HOMELESS_ENTITIES, true);
+ geoDns.config().set(GeoscalingDnsService.INCLUDE_HOMELESS_ENTITIES, true);
app.start(ImmutableList.of(locWithoutGeo));
target.sensors().set(Attributes.HOSTNAME, StubHostGeoLookup.HOMELESS_IP);
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/06a8f610/software/webapp/src/test/java/org/apache/brooklyn/entity/dns/geoscaling/GeoscalingWebClientTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/org/apache/brooklyn/entity/dns/geoscaling/GeoscalingWebClientTest.java b/software/webapp/src/test/java/org/apache/brooklyn/entity/dns/geoscaling/GeoscalingWebClientTest.java
index d29ae5b..325cd81 100644
--- a/software/webapp/src/test/java/org/apache/brooklyn/entity/dns/geoscaling/GeoscalingWebClientTest.java
+++ b/software/webapp/src/test/java/org/apache/brooklyn/entity/dns/geoscaling/GeoscalingWebClientTest.java
@@ -26,11 +26,17 @@ import static org.apache.brooklyn.entity.dns.geoscaling.GeoscalingWebClient.PROV
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
+import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.core.internal.BrooklynProperties;
+import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
+import org.apache.brooklyn.core.test.BrooklynMgmtUnitTestSupport;
+import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
import org.apache.brooklyn.entity.dns.geoscaling.GeoscalingWebClient.Domain;
import org.apache.brooklyn.entity.dns.geoscaling.GeoscalingWebClient.SmartSubdomain;
import org.apache.brooklyn.util.http.HttpTool;
import org.apache.brooklyn.util.text.Strings;
import org.apache.http.client.HttpClient;
+import org.testng.SkipException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -100,12 +106,9 @@ at org.apache.brooklyn.entity.dns.geoscaling.GeoscalingWebClient.login(Geoscalin
... 31 more
*/
@Test(groups="Broken", enabled=false)
-public class GeoscalingWebClientTest {
+public class GeoscalingWebClientTest extends BrooklynMgmtUnitTestSupport {
private final static String GEOSCALING_URL = "https://www.geoscaling.com";
- private final static String USERNAME = "cloudsoft";
- private final static String PASSWORD = "cl0uds0ft";
-
private final static String PRIMARY_DOMAIN = "domain-" + Strings.makeRandomId(5) + ".test.org";
private final static String SUBDOMAIN = "subdomain-" + Strings.makeRandomId(5);
@@ -115,18 +118,29 @@ public class GeoscalingWebClientTest {
private Domain domain;
private SmartSubdomain smartSubdomain;
-
- @BeforeMethod(alwaysRun=true)
- public void setUp() {
+
+ @Override
+ @BeforeMethod(alwaysRun = true)
+ public void setUp() throws Exception {
+ // Want to load username and password from user's properties.
+ mgmt = LocalManagementContextForTests.newInstance(BrooklynProperties.Factory.newDefault());
+
+ String username = getBrooklynProperty(mgmt, "brooklyn.geoscaling.username");
+ String password = getBrooklynProperty(mgmt, "brooklyn.geoscaling.password");
+ if (username == null || password == null) {
+ throw new SkipException("Set brooklyn.geoscaling.username and brooklyn.geoscaling.password in brooklyn.properties to enable test");
+ }
+
// Insecurely use "trustAll" so that don't need to import signature into trust store
// before test will work on jenkins machine.
HttpClient httpClient = HttpTool.httpClientBuilder().uri(GEOSCALING_URL).trustAll().build();
geoscaling = new GeoscalingWebClient(httpClient);
- geoscaling.login(USERNAME, PASSWORD);
+ geoscaling.login(username, password);
+ super.setUp();
}
@AfterMethod(alwaysRun=true)
- public void tearDown() {
+ public void tearDown() throws Exception {
if (smartSubdomain != null)
smartSubdomain.delete();
@@ -135,8 +149,15 @@ public class GeoscalingWebClientTest {
if (geoscaling != null)
geoscaling.logout();
+
+ super.tearDown();
+
}
-
+
+ private String getBrooklynProperty(ManagementContext mgmt, String property) {
+ return ((ManagementContextInternal) mgmt).getBrooklynProperties().getFirst(property);
+ }
+
@Test(groups = "Integration")
public void testSimpleNames() {
testWebClient(PRIMARY_DOMAIN, SUBDOMAIN);