/** Tests {@link #expectedFailure(Throwable)} and that the <code>toString</code> * satisfies {@link #assertStringContains(String, String, String...)}. * @return as per {@link #expectedFailureOfType(Throwable, Class...)} */ public static void expectedFailureContains(Throwable e, String phrase1ToContain, String ...optionalOtherPhrasesToContain) { if (e instanceof ShouldHaveFailedPreviouslyAssertionError) throw (Error)e; try { assertStringContains(Exceptions.collapseText(e), phrase1ToContain, optionalOtherPhrasesToContain); } catch (AssertionError ee) { rethrowPreferredException(e, ee); } }
@Test public void testAssertStrings() { Asserts.assertStringContains("hello", "hello", "he"); try { Asserts.assertStringContains("hello", "goodbye"); Asserts.shouldHaveFailedPreviously(); } catch (AssertionError e) { Asserts.expectedFailureContains(e, "hello", "goodbye"); Asserts.expectedFailureContainsIgnoreCase(e, "hello", "Goodbye"); } Asserts.assertStringContainsIgnoreCase("hello", "Hello"); try { Asserts.assertStringContains("hello", "Hello"); Asserts.shouldHaveFailedPreviously(); } catch (AssertionError e) { Asserts.expectedFailureContains(e, "hello", "Hello"); } Asserts.assertStringContainsAtLeastOne("hello", "hello", "goodbye"); try { Asserts.assertStringContainsAtLeastOne("hello", "Hello", "goodbye"); Asserts.shouldHaveFailedPreviously(); } catch (AssertionError e) { Asserts.expectedFailureContains(e, "hello", "Hello", "goodbye"); } Asserts.assertStringMatchesRegex("hello", "hello", "he.*", "he[ckl]+e*o"); try { Asserts.assertStringMatchesRegex("hello", "hello", "he"); Asserts.shouldHaveFailedPreviously(); } catch (AssertionError e) { Asserts.expectedFailureContains(e, "hello", "matchesRegex(he)"); } }
public void testCatalogCreate()throws Exception { final Response response = api.getCatalogApi().createFromUpload(getFileContentsAsString("catalog/test-catalog.bom").getBytes(), false); Asserts.assertEquals(response.getStatus(), 201); Asserts.assertStringContains(String.valueOf(response.getEntity()), "simple-tomcat:1.0"); }
public void testApplicationApiCreate() throws Exception { Response r1 = api.getApplicationApi().createFromYaml("name: test-1234\n" + "services: [ { type: "+TestEntity.class.getName()+" } ]"); HttpAsserts.assertHealthyStatusCode(r1.getStatus()); log.info("creation result: "+r1.getEntity()); List<ApplicationSummary> apps = api.getApplicationApi().list(null); log.info("apps with test: "+apps); Asserts.assertStringContains(apps.toString(), "test-1234"); }
@Test public void testBasicConfigInheritance_2016_10() throws Exception { doReadConfigInheritance("basic-2016-10", "wj5s8u9h73"); checkNewAppNonInheritingKey1(rebindedApp); Asserts.assertStringContains(origMemento, "isReinherited"); Asserts.assertStringDoesNotContain(origMemento, "NEVER_INHERITED"); Asserts.assertStringDoesNotContain(origMemento, "NeverInherited"); // should write it out as NeverInherited Asserts.assertStringDoesNotContain(newMemento, "isReinherited"); Asserts.assertStringContains(newMemento, "NeverInherited"); }
/** also see {@link RebindWithDeserializingClassRenamesTest} */ @Test public void testPreBasicConfigInheritance_2016_07() throws Exception { doReadConfigInheritance("prebasic-2016-07", "toruf2wxg4"); ConfigKey<?> k = Iterables.getOnlyElement( rebindedApp.config().findKeysDeclared(ConfigPredicates.nameEqualTo("my.config.inheritanceMerged")) ); Asserts.assertStringContains(origMemento, "<parentInheritance class=\"org.apache.brooklyn.config.ConfigInheritance$Merged\"/>"); Asserts.assertStringDoesNotContain(origMemento, BasicConfigInheritance.DEEP_MERGE.getClass().getName()); // should now convert it to BasicConfigInheritance.DEEP_MERGE Asserts.assertStringDoesNotContain(newMemento, "ConfigInheritance$Merged"); Asserts.assertStringDoesNotContain(newMemento, "ConfigInheritance$Legacy$Merged"); Asserts.assertStringContains(newMemento, BasicConfigInheritance.DEEP_MERGE.getClass().getName()); ConfigInheritance inh = k.getInheritanceByContext(InheritanceContext.RUNTIME_MANAGEMENT); Assert.assertEquals(inh, BasicConfigInheritance.DEEP_MERGE); }
@Test public void testMetadataOnSpecCreatedFromItem() throws Exception { addCatalogItem("t1", TestEntity.class.getName()); EntitySpec<? extends Application> spec = EntityManagementUtils.createEntitySpecForApplication( mgmt(), Joiner.on("\n").join( "location: localhost", "services:", "- type: t1")); List<NamedStringTag> yamls = BrooklynTags.findAll(BrooklynTags.YAML_SPEC_KIND, spec.getTags()); Assert.assertEquals(yamls.size(), 1, "Expected 1 yaml tag; instead had: "+yamls); String yaml = Iterables.getOnlyElement(yamls).getContents(); Asserts.assertStringContains(yaml, "services:", "t1", "localhost"); EntitySpec<?> child = Iterables.getOnlyElement( spec.getChildren() ); Assert.assertEquals(child.getType().getName(), TestEntity.class.getName()); Assert.assertEquals(child.getCatalogItemId(), "t1:"+TEST_VERSION); }
@Test public void testSshConfigFromDefault() throws Exception { RecordingSshTool.setCustomResponse(".*myCommand.*", new RecordingSshTool.CustomResponse(0, "myResponse", null)); String bp = loadYaml("config-type-coercion-test.yaml", "location:", " localhost:", " sshToolClass: "+RecordingSshTool.class.getName()); // remove all lines referring to "exact" -- that's useful for expository and running in UI // but it will fail (timeout) if the port isn't available so not good in tests bp = Strings.removeLines(bp, StringPredicates.containsLiteralIgnoreCase("exact")); Entity app = createAndStartApplication(bp); waitForApplicationTasks(app); Map<?, ?> props = RecordingSshTool.getLastExecCmd().env; Assert.assertEquals(props.get("RANGE_PORT_SENSOR"), "20003"); Asserts.assertStringContains((String)props.get("RANGE_PORT_CONFIG"), "{\"start\"", "20003"); Assert.assertEquals(props.get("INT_PORT_CONFIG"), "20001"); Assert.assertEquals(props.get("INT_PORT_DEFAULT_CONFIG"), "30001"); Assert.assertEquals(props.get("RANGE_PORT_DEFAULT_SENSOR"), "30003"); // NB: change in Oct 2016, default values are now coerced just like explicit value // (previous to Oct 2016 this would have returned just "30003+", no json) Asserts.assertStringContains((String)props.get("RANGE_PORT_DEFAULT_CONFIG"), "{\"start\"", "30003"); }
@Test public void testMetadataOnSpecCreatedFromItem() throws Exception { makeItem("t1", SIMPLE_ENTITY_TYPE); EntitySpec<? extends Application> spec = EntityManagementUtils.createEntitySpecForApplication(mgmt(), "services: [ { type: t1 } ]\n" + "location: localhost"); List<NamedStringTag> yamls = BrooklynTags.findAll(BrooklynTags.YAML_SPEC_KIND, spec.getTags()); Assert.assertEquals(yamls.size(), 1, "Expected 1 yaml tag; instead had: "+yamls); String yaml = Iterables.getOnlyElement(yamls).getContents(); Asserts.assertStringContains(yaml, "services:", "t1", "localhost"); EntitySpec<?> child = Iterables.getOnlyElement( spec.getChildren() ); Assert.assertEquals(child.getType().getName(), SIMPLE_ENTITY_TYPE); Assert.assertEquals(child.getCatalogItemId(), "t1:"+TEST_VERSION); }
@Test public void testVersionedName() throws Exception { VersionedName vn = getTestKeyFromEntityMemento("2017-06-versionedname", "n7p20t5h4o", VersionedName.class); Assert.assertEquals(vn, new VersionedName("foo", "1.0.0-foo")); Assert.assertNotEquals(vn, new VersionedName("foo", "1.0.0.foo")); Assert.assertTrue(vn.equalsOsgi(new VersionedName("foo", Version.parseVersion("1.0.0.foo")))); String newEntityContent = getEntityMementoContent(); // log.info("New VN persistence is\n"+newEntityContent); Asserts.assertStringContains(newEntityContent, "1.0.0-foo"); // phrases from original persisted state are changed Asserts.assertStringDoesNotContain(newEntityContent, "<symbolicName>foo"); Asserts.assertStringDoesNotContain(newEntityContent, "<version>1.0.0"); Asserts.assertStringDoesNotContain(newEntityContent, "1.0.0.foo"); // they should now be this Asserts.assertStringContains(newEntityContent, "<name>foo"); Asserts.assertStringContains(newEntityContent, "<v>1.0.0-foo"); }
Asserts.assertStringContains(persistedEntity, entry.getKey()); Asserts.assertStringDoesNotContain(persistedEntity, entry.getValue()); for (Map.Entry<String, String> entry : expectedTransforms.entrySet()) { Asserts.assertStringDoesNotContain(newPersistedEntity, entry.getKey()); Asserts.assertStringContains(newPersistedEntity, entry.getValue());
Assert.assertTrue(yamls.size() >= 1, "Expected at least 1 yaml tag; instead had: "+yamls); String yaml = yamls.iterator().next().getContents(); Asserts.assertStringContains(yaml, "services:", "type: app1r", "localhost");
@Test public void testLaunchApplicationWithCatalogReferencingOtherCatalog() throws Exception { String referencedSymbolicName = "my.catalog.app.id.referenced"; String referrerSymbolicName = "my.catalog.app.id.referring"; addCatalogItems( "brooklyn.catalog:", " name: My Catalog App", " description: My description", " icon_url: classpath://path/to/myicon.jpg", " version: " + TEST_VERSION, " items:", " - id: " + referencedSymbolicName, " item:", " type: " + TestEntity.class.getName(), " - id: " + referrerSymbolicName, " item:", " type: " + ver(referencedSymbolicName, TEST_VERSION)); RegisteredType referrer = mgmt().getTypeRegistry().get(referrerSymbolicName, TEST_VERSION); String planYaml = RegisteredTypes.getImplementationDataStringForSpec(referrer); Asserts.assertStringContains(planYaml, "services"); Entity app = createAndStartApplication("services:", "- type: " + ver(referrerSymbolicName, TEST_VERSION)); Entity entity = Iterables.getOnlyElement(app.getChildren()); assertEquals(entity.getEntityType().getName(), TestEntity.class.getName()); deleteCatalogEntity(referencedSymbolicName); deleteCatalogEntity(referrerSymbolicName); }