@Test public void testExpectedFailures() { Asserts.expectedFailureOfType(new IllegalStateException(), NoSuchElementException.class, IllegalStateException.class); Asserts.expectedFailureOfType(new IllegalStateException(), NoSuchElementException.class, Object.class); try { Asserts.expectedFailureOfType(new IllegalStateException(), NoSuchElementException.class, Error.class); Asserts.shouldHaveFailedPreviously(); } catch (Throwable e) { Asserts.expectedFailure(e); } }
protected Exception assertTaskFails(Task<?> t) { try { t.get(); Assert.fail("Should have failed"); } catch (Exception e) { Asserts.expectedFailure(e); return e; } return null; }
private Exception assertStartMethodFails(FailingEntity entity) { try { entity.start(locs); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { Asserts.expectedFailure(e); return e; } return null; }
@Test public void testShouldHaveFailed() { int reached = 0; try { try { // in normal tests the following indicates that an expected failure didn't happen // (but here we are testing it) Asserts.shouldHaveFailedPreviously(); reached--; } catch (Throwable e) { // in normal tests the following indicates that a failure was NOT thrown by the above // (but here the call *below* should rethrow) reached++; Asserts.expectedFailure(e); reached--; } reached--; throw new AssertionError("It should have failed previously, with a " + "ShouldHaveFailedPreviouslyAssertionError in the first block rethrown by the second"); } catch (ShouldHaveFailedPreviouslyAssertionError e) { // expected reached++; } reached++; // check code flowed the way we expected Asserts.assertEquals(reached, 3); } }
@Test public void testRequiresThatMemberSpecArgumentIsAnEntitySpec() throws Exception { try { app.createAndManageChild(EntitySpec.create(DynamicCluster.class) .configure("memberSpec", "error")); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { Asserts.expectedFailure(e); } }
@Test public void testThrowsIfTargetDoesNotResolve() throws Exception { final String effectorName = "proxy-effector"; Entity app = createAndStartApplication( "location: localhost", "services:", "- type: " + BasicEntity.class.getName(), " brooklyn.initializers:", " - type: org.apache.brooklyn.core.effector.ProxyEffector", " brooklyn.config:", " name: " + effectorName, " targetEntity: $brooklyn:entity(\"skhbfskdbf\")", " targetEffector: identityEffector" ); waitForApplicationTasks(app); Entity basicEntity = app.getChildren().iterator().next(); Effector<?> effector = basicEntity.getEntityType().getEffectorByName(effectorName).get(); try { basicEntity.invoke(effector, ImmutableMap.<String, Object>of()).get(); Asserts.shouldHaveFailedPreviously("expected exception when invoking effector that does not exist"); } catch (Exception e) { Asserts.expectedFailure(e); } }