public Void call() throws Exception { for (Deployment d : suiteDeploymentScenario.deployments()) { deploymentEvent.fire(new DeployDeployment(findContainer(registry, event.getDeployableContainer()), d)); } return null; } });
@Override public Void call() throws Exception { DeployableContainer<?> deployableContainer = event.getDeployableContainer(); Deployment deployment = event.getDeployment(); DeploymentDescription deploymentDescription = deployment.getDescription(); /* * TODO: should the DeploymentDescription producer some how be automatically registered ? * Or should we just 'know' who is the first one to create the context */ deploymentDescriptionProducer.set(deploymentDescription); deploymentProducer.set(deployment); deployEvent.fire(new BeforeDeploy(deployableContainer, deploymentDescription)); try { if (deploymentDescription.isArchiveDeployment()) { protocolMetadata.set(deployableContainer.deploy( deploymentDescription.getTestableArchive() != null ? deploymentDescription.getTestableArchive() : deploymentDescription.getArchive())); } else { deployableContainer.deploy(deploymentDescription.getDescriptor()); } deployment.deployed(); } catch (Exception e) { deployment.deployedWithError(e); throw e; } deployEvent.fire(new AfterDeploy(deployableContainer, deploymentDescription)); return null; } });
public void verifyExpectedExceptionDuringDeploy(@Observes EventContext<DeployDeployment> context) throws Exception { DeploymentDescription deployment = context.getEvent().getDeployment().getDescription(); boolean deploymentExceptionThrown = true; try { context.proceed(); if (deployment.getExpectedException() != null) { deploymentExceptionThrown = false; throw new RuntimeException( "Expected exception of type " + deployment.getExpectedException().getName() + " during deployment of " + deployment.getName() + ", but no exception was thrown."); } } catch (Exception e) { // if exception is not thrown from the deployment, rethrow it (we threw it). if (!deploymentExceptionThrown) { throw e; } if (deployment.getExpectedException() != null) { if (!containsType(e, deployment.getExpectedException())) { throw e; } } else { throw e; } } }
@Override public Void call() throws Exception { DeployableContainer<?> deployableContainer = event.getDeployableContainer(); Deployment deployment = event.getDeployment(); DeploymentDescription deploymentDescription = deployment.getDescription(); /* * TODO: should the DeploymentDescription producer some how be automatically registered ? * Or should we just 'know' who is the first one to create the context */ deploymentDescriptionProducer.set(deploymentDescription); deploymentProducer.set(deployment); deployEvent.fire(new BeforeDeploy(deployableContainer, deploymentDescription)); try { if (deploymentDescription.isArchiveDeployment()) { protocolMetadata.set(deployableContainer.deploy( deploymentDescription.getTestableArchive() != null ? deploymentDescription.getTestableArchive() : deploymentDescription.getArchive())); } else { deployableContainer.deploy(deploymentDescription.getDescriptor()); } deployment.deployed(); } catch (Exception e) { deployment.deployedWithError(e); throw e; } deployEvent.fire(new AfterDeploy(deployableContainer, deploymentDescription)); return null; } });
public void verifyExpectedExceptionDuringDeploy(@Observes EventContext<DeployDeployment> context) throws Exception { DeploymentDescription deployment = context.getEvent().getDeployment().getDescription(); boolean deploymentExceptionThrown = true; try { context.proceed(); if (deployment.getExpectedException() != null) { deploymentExceptionThrown = false; throw new RuntimeException( "Expected exception of type " + deployment.getExpectedException().getName() + " during deployment of " + deployment.getName() + ", but no exception was thrown."); } } catch (Exception e) { // if exception is not thrown from the deployment, rethrow it (we threw it). if (!deploymentExceptionThrown) { throw e; } if (deployment.getExpectedException() != null) { if (!containsType(e, deployment.getExpectedException())) { throw e; } } else { throw e; } } }
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)))); }
public Void call() throws Exception { for (Deployment d : suiteDeploymentScenario.deployments()) { deploymentEvent.fire(new DeployDeployment(findContainer(registry, event.getDeployableContainer()), d)); } return null; } });
@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 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));