public DeploymentScenario addDeployment(DeploymentDescription deployment) { Validate.notNull(deployment, "Deployment must be specified"); validateNotSameNameAndTypeOfDeployment(deployment); validateNotSameArchiveAndSameTarget(deployment); this.deployments.add(new Deployment(deployment)); return this; }
public DeploymentScenario addDeployment(DeploymentDescription deployment) { Validate.notNull(deployment, "Deployment must be specified"); validateNotSameNameAndTypeOfDeployment(deployment); validateNotSameArchiveAndSameTarget(deployment); this.deployments.add(new Deployment(deployment)); return this; }
@Test public void shouldTransformException() throws Exception { TestExceptionDeployThrower.shouldThrow = new IllegalStateException(); Mockito.when(serviceLoader.all(DeploymentExceptionTransformer.class)) .thenReturn(Collections.singletonList(transformer)); Mockito.when(transformer.transform(TestExceptionDeployThrower.shouldThrow)) .thenReturn(new IllegalArgumentException()); fire(new DeployDeployment( container, new Deployment(new DeploymentDescription("test", ShrinkWrap.create(JavaArchive.class)) .setExpectedException(IllegalArgumentException.class)))); }
@Test public void shouldCallDeploymentTransformers() throws Exception { TestExceptionDeployThrower.shouldThrow = new DeploymentException("Could not handle ba", new IllegalArgumentException()); Mockito.when(serviceLoader.all(DeploymentExceptionTransformer.class)) .thenReturn(Collections.singletonList(transformer)); fire(new DeployDeployment( container, new Deployment(new DeploymentDescription("test", ShrinkWrap.create(JavaArchive.class)) .setExpectedException(IllegalArgumentException.class)))); Mockito.verify(transformer, Mockito.times(1)).transform(Mockito.isA(Exception.class)); }
@Test public void shouldCallDeploymentTransformersWithEmptyCauseException() throws Exception { TestExceptionDeployThrower.shouldThrow = new DeploymentException("Could not handle ba", null); Mockito.when(serviceLoader.all(DeploymentExceptionTransformer.class)) .thenReturn(Collections.singletonList(transformer)); fire(new DeployDeployment( container, new Deployment(new DeploymentDescription("test", ShrinkWrap.create(JavaArchive.class)) .setExpectedException(DeploymentException.class)))); Mockito.verify(transformer, Mockito.times(1)).transform(TestExceptionDeployThrower.shouldThrow); }
@Test(expected = DeploymentException.class) public void shouldRethrowExceptionIfWrongExpectedType() throws Exception { TestExceptionDeployThrower.shouldThrow = new DeploymentException("Could not handle ba", new NullPointerException()); Mockito.when(serviceLoader.all(DeploymentExceptionTransformer.class)) .thenReturn(Collections.singletonList(transformer)); fire(new DeployDeployment( container, new Deployment(new DeploymentDescription("test", ShrinkWrap.create(JavaArchive.class)) .setExpectedException(IllegalArgumentException.class)))); }
@Test public void shouldSwallawExceptionIfExpectedAndDeploymentExceptionIsFieldOfThrown() throws Exception { MyDeploymentException myException = new MyDeploymentException("My special exception", new NullPointerException()); TestExceptionDeployThrower.shouldThrow = myException; Mockito.when(serviceLoader.all(DeploymentExceptionTransformer.class)) .thenReturn(Collections.singletonList(transformer)); Mockito.when(transformer.transform(TestExceptionDeployThrower.shouldThrow)).thenReturn( myException.getDeploymentException()); fire(new DeployDeployment(container, new Deployment(new DeploymentDescription("test", ShrinkWrap.create(JavaArchive.class)).setExpectedException(NullPointerException.class)))); }
@Test(expected = DeploymentException.class) public void shouldRethrowExceptionIfExpectedNotSet() throws Exception { TestExceptionDeployThrower.shouldThrow = new DeploymentException("Could not handle ba", new NullPointerException()); fire(new DeployDeployment( container, new Deployment(new DeploymentDescription("test", ShrinkWrap.create(JavaArchive.class))))); }
@Test public void shouldSwallawExceptionIfExpectedAndDeploymentExceptionIsFieldOfThrownAndCauseOfOther() throws Exception { IllegalArgumentException recursiveException = new IllegalArgumentException(new MyDeploymentException( "My special exception", new NullPointerException())); TestExceptionDeployThrower.shouldThrow = recursiveException; Mockito.when(serviceLoader.all(DeploymentExceptionTransformer.class)) .thenReturn(Collections.singletonList(transformer)); Mockito.when(transformer.transform(TestExceptionDeployThrower.shouldThrow)).thenReturn( ((MyDeploymentException) recursiveException.getCause()).getDeploymentException()); fire(new DeployDeployment(container, new Deployment(new DeploymentDescription("test", ShrinkWrap.create(JavaArchive.class)).setExpectedException(NullPointerException.class)))); }
@Test public void shouldSwallowExceptionIfExpected() throws Exception { TestExceptionDeployThrower.shouldThrow = new DeploymentException("Could not handle ba", new NullPointerException()); fire(new DeployDeployment( container, new Deployment(new DeploymentDescription("test", ShrinkWrap.create(JavaArchive.class)) .setExpectedException(NullPointerException.class)))); }
@Test(expected = RuntimeException.class) public void shouldThrowExceptionIfExpectedButNoExceptionThrown() throws Exception { TestExceptionDeployThrower.shouldThrow = null; fire(new DeployDeployment( container, new Deployment(new DeploymentDescription("test", ShrinkWrap.create(JavaArchive.class)) .setExpectedException(IllegalArgumentException.class)))); }
.thenReturn(new ContainerImpl("Z", deployableContainer, new ContainerDefImpl("Z"))); Deployment deploymentZ = new Deployment(new DeploymentDescription("Z", ShrinkWrap.create(JavaArchive.class)) .setTarget(new TargetDescription("Z"))); Deployment deploymentX = new Deployment(new DeploymentDescription("X", ShrinkWrap.create(JavaArchive.class)) .setTarget(new TargetDescription("X")));
.thenReturn(new ContainerImpl("Z", deployableContainer, new ContainerDefImpl("Z"))); Deployment deploymentZ = new Deployment(new DeploymentDescription("Z", ShrinkWrap.create(JavaArchive.class)) .setTarget(new TargetDescription("Z"))); Deployment deploymentX = new Deployment(new DeploymentDescription("X", ShrinkWrap.create(JavaArchive.class)) .setTarget(new TargetDescription("X")));