public Void call() throws Exception { for (Deployment d : suiteDeploymentScenario.deployments()) { deploymentEvent.fire(new DeployDeployment(findContainer(registry, event.getDeployableContainer()), d)); } return null; } });
public Void call() throws Exception { for (Deployment d : suiteDeploymentScenario.deployments()) { deploymentEvent.fire(new DeployDeployment(findContainer(registry, event.getDeployableContainer()), d)); } return null; } });
@Override public void perform(Container container, Deployment deployment) throws Exception { //when a container is manually controlled, the deployment is deployed automatically //once the container is manually started, not now if (!"manual".equals(container.getContainerConfiguration().getMode())) { if (container.getState() != State.STARTED) { throw new IllegalStateException("Trying to deploy a managed deployment " + deployment.getDescription().getName() + " to a non started managed container " + container.getName()); } event.fire(new DeployDeployment(container, deployment)); } } });
@Override public void perform(Container container, Deployment deployment) throws Exception { //when a container is manually controlled, the deployment is deployed automatically //once the container is manually started, not now if (!"manual".equals(container.getContainerConfiguration().getMode())) { if (container.getState() != State.STARTED) { throw new IllegalStateException("Trying to deploy a managed deployment " + deployment.getDescription().getName() + " to a non started managed container " + container.getName()); } event.fire(new DeployDeployment(container, deployment)); } } });
@Override public void deploy(String name) { DeploymentScenario scenario = deploymentScenario.get(); if (scenario == null) { throw new IllegalArgumentException("No deployment scenario in context"); } ContainerRegistry registry = containerRegistry.get(); if (registry == null) { throw new IllegalArgumentException("No container registry in context"); } Deployment deployment = scenario.deployment(new DeploymentTargetDescription(name)); if (deployment == null) { throw new IllegalArgumentException("No deployment in context found with name " + name); } if (deployment.getDescription().managed()) { throw new IllegalArgumentException( "Could not deploy " + name + " deployment. The deployment is controlled by Arquillian"); } Container container = registry.getContainer(deployment.getDescription().getTarget()); if (!container.getState().equals(State.STARTED)) { throw new IllegalArgumentException("Deployment with name " + name + " could not be deployed. Container " + container.getName() + " must be started first."); } event.fire(new DeployDeployment(container, deployment)); }
@Override public void deploy(String name) { DeploymentScenario scenario = deploymentScenario.get(); if (scenario == null) { throw new IllegalArgumentException("No deployment scenario in context"); } ContainerRegistry registry = containerRegistry.get(); if (registry == null) { throw new IllegalArgumentException("No container registry in context"); } Deployment deployment = scenario.deployment(new DeploymentTargetDescription(name)); if (deployment == null) { throw new IllegalArgumentException("No deployment in context found with name " + name); } if (deployment.getDescription().managed()) { throw new IllegalArgumentException( "Could not deploy " + name + " deployment. The deployment is controlled by Arquillian"); } Container container = registry.getContainer(deployment.getDescription().getTarget()); if (!container.getState().equals(State.STARTED)) { throw new IllegalArgumentException("Deployment with name " + name + " could not be deployed. Container " + container.getName() + " must be started first."); } event.fire(new DeployDeployment(container, deployment)); }
@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 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)))); }
public Void call() throws Exception { for (Deployment d : suiteDeploymentScenario.deployments()) { deploymentEvent.fire(new DeployDeployment(findContainer(registry, event.getDeployableContainer()), d)); } return null; } });
@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 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(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 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 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))))); }
log.info("Automatic deploying of the managed deployment with name " + d.getDescription().getName() + " for the container with name " + container.getName()); event.fire(new DeployDeployment(container, d));
log.info("Automatic deploying of the managed deployment with name " + d.getDescription().getName() + " for the container with name " + container.getName()); event.fire(new DeployDeployment(container, d));
log.info("Automatic deploying of the managed deployment with name " + d.getDescription().getName() + " for the container with name " + container.getName()); event.fire(new DeployDeployment(container, d));
log.info("Automatic deploying of the managed deployment with name " + d.getDescription().getName() + " for the container with name " + container.getName()); event.fire(new DeployDeployment(container, d));
@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)))); }