public void testApplicationApiHandledError() throws Exception { Response r1 = api.getApplicationApi().createFromYaml("name: test"); HttpAsserts.assertNotHealthyStatusCode(r1.getStatus()); // new-style messages first, old-style messages after (during switch to TypePlanTransformer) Asserts.assertStringContainsAtLeastOne(r1.getEntity().toString().toLowerCase(), "invalid plan", "no services"); Asserts.assertStringContainsAtLeastOne(r1.getEntity().toString().toLowerCase(), "format could not be recognized", "Unrecognized application blueprint format"); }
@Test public void testBrooklynCampTagsFailNonList() throws Exception { try { final Entity app = createAndStartApplication( "services:", "- type: " + BasicApplication.class.getName(), " brooklyn.tags:", " tag1: true", " tag2: 2"); fail("Should throw IllegalArgumentException exception; instead got: "+app); } catch (CompoundRuntimeException e) { Asserts.assertStringContainsAtLeastOne(Exceptions.getFirstInteresting(e).getMessage(),"brooklyn.tags must be a list, is: "); } }
@Test public void testBrooklynCampFailDslTags() throws Exception { try { final Entity app = createAndStartApplication( "services:", "- type: " + BasicApplication.class.getName(), " brooklyn.tags:", " - tag1", " - $brooklyn:object:", " type: "+TagsTestObject.class.getName(), " constructor.args:", " - $brooklyn:attributeWhenReady(\"host.name\")"); fail("Should throw IllegalArgumentException exception; instead got "+app); } catch (CompoundRuntimeException e) { Asserts.assertStringContainsAtLeastOne(Exceptions.getFirstInteresting(e).getMessage(),"brooklyn.tags should not contain DeferredSupplier. A DeferredSupplier is made when using $brooklyn:attributeWhenReady"); } }
@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)"); } }