public static void assertContentMatches(String url, String regex) { String contents = getContent(url); Assert.assertNotNull(contents); Assert.assertTrue(contents.matches(regex), "Contents does not match expected regex ("+regex+"): "+contents); }
public static void assertContentContainsText(final String url, final String phrase, final String ...additionalPhrases) { try { String contents = getContent(url); Assert.assertTrue(contents != null && contents.length() > 0); for (String text: Lists.asList(phrase, additionalPhrases)) { if (!contents.contains(text)) { LOG.warn("CONTENTS OF URL "+url+" MISSING TEXT: "+text+"\n"+contents); Assert.fail("URL "+url+" does not contain text: "+text); } } } catch (Exception e) { throw Throwables.propagate(e); } }
public static void assertContentNotContainsText(final String url, final String phrase, final String ...additionalPhrases) { try { String contents = getContent(url); Assert.assertTrue(contents != null); for (String text: Lists.asList(phrase, additionalPhrases)) { if (contents.contains(text)) { LOG.warn("CONTENTS OF URL "+url+" HAS TEXT: "+text+"\n"+contents); Assert.fail("URL "+url+" contain text: "+text); } } } catch (Exception e) { throw Throwables.propagate(e); } }
@Override public void run() { //Wait all apps to become managed String appsContent = HttpTestUtils.getContent(webConsoleUri.toString()+"/v1/applications"); List<String> appIds = parseJsonList(appsContent, ImmutableList.of("id"), String.class); assertEquals(appIds.size(), num); // and then to start List<String> statuses = parseJsonList(appsContent, ImmutableList.of("status"), String.class); for (String status : statuses) { assertEquals(status, Lifecycle.RUNNING.toString().toUpperCase()); } }}); }
@Test(groups={"Integration", "Broken"}) public void testStartsAppOnStartup() throws Exception { BrooklynNode brooklynNode = app.createAndManageChild(newBrooklynNodeSpecForTest() .configure(BrooklynNode.APP, BasicApplicationImpl.class.getName())); app.start(locs); log.info("started "+app+" containing "+brooklynNode+" for "+JavaClassNames.niceClassAndMethod()); URI webConsoleUri = brooklynNode.getAttribute(BrooklynNode.WEB_CONSOLE_URI); waitForApps(webConsoleUri, 1); String apps = HttpTestUtils.getContent(webConsoleUri.toString()+"/v1/applications"); List<String> appType = parseJsonList(apps, ImmutableList.of("spec", "type"), String.class); assertEquals(appType, ImmutableList.of(BasicApplication.class.getName())); }
@Test(groups={"Integration", "Broken"}) public void testUsesLocation() throws Exception { String brooklynPropertiesContents = "brooklyn.location.named.mynamedloc=localhost:(name=myname)\n"+ //force lat+long so test will work when offline "brooklyn.location.named.mynamedloc.latitude=123\n"+ "brooklyn.location.named.mynamedloc.longitude=45.6\n"; BrooklynNode brooklynNode = app.createAndManageChild(newBrooklynNodeSpecForTest() .configure(BrooklynNode.BROOKLYN_LOCAL_PROPERTIES_CONTENTS, brooklynPropertiesContents) .configure(BrooklynNode.APP, BasicApplicationImpl.class.getName()) .configure(BrooklynNode.LOCATIONS, "named:mynamedloc")); app.start(locs); log.info("started "+app+" containing "+brooklynNode+" for "+JavaClassNames.niceClassAndMethod()); URI webConsoleUri = brooklynNode.getAttribute(BrooklynNode.WEB_CONSOLE_URI); waitForApps(webConsoleUri, 1); // Check that "mynamedloc" has been picked up from the brooklyn.properties String locsContent = HttpTestUtils.getContent(webConsoleUri.toString()+"/v1/locations"); List<String> locNames = parseJsonList(locsContent, ImmutableList.of("name"), String.class); assertTrue(locNames.contains("mynamedloc"), "locNames="+locNames); // Find the id of the concrete location instance of the app String appsContent = HttpTestUtils.getContent(webConsoleUri.toString()+"/v1/applications"); List<String[]> appLocationIds = parseJsonList(appsContent, ImmutableList.of("spec", "locations"), String[].class); String appLocationId = Iterables.getOnlyElement(appLocationIds)[0]; // app.getManagementContext().getLocationRegistry() // Check that the concrete location is of the required type String locatedLocationsContent = HttpTestUtils.getContent(webConsoleUri.toString()+"/v1/locations/usage/LocatedLocations"); assertEquals(parseJson(locatedLocationsContent, ImmutableList.of(appLocationId, "name"), String.class), "myname"); assertEquals(parseJson(locatedLocationsContent, ImmutableList.of(appLocationId, "longitude"), Double.class), 45.6, 0.00001); }
@Test(groups={"Integration", "Broken"}) public void testStartsAppViaEffector() throws Exception { BrooklynNode brooklynNode = app.createAndManageChild(newBrooklynNodeSpecForTest()); app.start(locs); log.info("started "+app+" containing "+brooklynNode+" for "+JavaClassNames.niceClassAndMethod()); // note there is also a test for this in DeployApplication final URI webConsoleUri = brooklynNode.getAttribute(BrooklynNode.WEB_CONSOLE_URI); waitForApps(webConsoleUri.toString()); final String id = brooklynNode.invoke(BrooklynNode.DEPLOY_BLUEPRINT, ConfigBag.newInstance() .configure(DeployBlueprintEffector.BLUEPRINT_TYPE, BasicApplication.class.getName()) .getAllConfig()).get(); String apps = HttpTestUtils.getContent(webConsoleUri.toString()+"/v1/applications"); List<String> appType = parseJsonList(apps, ImmutableList.of("spec", "type"), String.class); assertEquals(appType, ImmutableList.of(BasicApplication.class.getName())); HttpTestUtils.assertContentEventuallyMatches( webConsoleUri.toString()+"/v1/applications/"+id+"/entities/"+id+"/sensors/service.state", "\"?(running|RUNNING)\"?"); }
.getAllConfig()).get(); String apps = HttpTestUtils.getContent(webConsoleUri.toString()+"/v1/applications"); List<String> appType = parseJsonList(apps, ImmutableList.of("spec", "type"), String.class); assertEquals(appType, ImmutableList.of(BasicApplication.class.getName()));
String apps = HttpTestUtils.getContent(webConsoleUri.toString()+"/v1/applications"); List<String> appType = parseJsonList(apps, ImmutableList.of("spec", "type"), String.class); assertEquals(appType, ImmutableList.of(BasicApplication.class.getName()));