private DeploymentTargetDescription locateDeployment(Method method) { DeploymentTargetDescription target = null; if (method.isAnnotationPresent(OperateOnDeployment.class)) { target = new DeploymentTargetDescription(method.getAnnotation(OperateOnDeployment.class).value()); } else { target = DeploymentTargetDescription.DEFAULT; } return target; }
private DeploymentTargetDescription locateDeployment(Method method) { DeploymentTargetDescription target = null; if (method.isAnnotationPresent(OperateOnDeployment.class)) { target = new DeploymentTargetDescription(method.getAnnotation(OperateOnDeployment.class).value()); } else { target = DeploymentTargetDescription.DEFAULT; } return target; }
@Override public InputStream getDeployment(String name) { DeploymentScenario scenario = deploymentScenario.get(); if (scenario == null) { throw new IllegalArgumentException("No deployment scenario in context"); } Deployment deployment = scenario.deployment(new DeploymentTargetDescription(name)); if (deployment == null) { throw new IllegalArgumentException("No deployment in context found with name " + name); } DeploymentDescription description = deployment.getDescription(); if (description.isArchiveDeployment()) { Archive<?> archive = description.testable() ? description.getTestableArchive() : description.getArchive(); return archive.as(ZipExporter.class).exportAsInputStream(); } else { return new ByteArrayInputStream(description.getDescriptor().exportAsString().getBytes()); } } }
@Override public InputStream getDeployment(String name) { DeploymentScenario scenario = deploymentScenario.get(); if (scenario == null) { throw new IllegalArgumentException("No deployment scenario in context"); } Deployment deployment = scenario.deployment(new DeploymentTargetDescription(name)); if (deployment == null) { throw new IllegalArgumentException("No deployment in context found with name " + name); } DeploymentDescription description = deployment.getDescription(); if (description.isArchiveDeployment()) { Archive<?> archive = description.testable() ? description.getTestableArchive() : description.getArchive(); return archive.as(ZipExporter.class).exportAsInputStream(); } else { return new ByteArrayInputStream(description.getDescriptor().exportAsString().getBytes()); } } }
@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)); }
@Override public void undeploy(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 undeployed. Container " + container.getName() + " must be still running."); } event.fire(new UnDeployDeployment(container, deployment)); }
@Override public void undeploy(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 undeployed. Container " + container.getName() + " must be still running."); } event.fire(new UnDeployDeployment(container, deployment)); }
scenario.deployment(new DeploymentTargetDescription(DEPLOYMENT_1_NAME)).deployed(); scenario.deployment(new DeploymentTargetDescription(DEPLOYMENT_2_NAME)).deployed(); scenario.deployment(new DeploymentTargetDescription(DEPLOYMENT_3_NAME)).deployed(); scenario.deployment(new DeploymentTargetDescription(DEPLOYMENT_4_NAME)).deployed(); scenario.deployment(new DeploymentTargetDescription(DEPLOYMENT_4_NAME)).getDescription().getDescriptor()); scenario.deployment(new DeploymentTargetDescription(DEPLOYMENT_3_NAME)).getDescription().getArchive()); scenario.deployment(new DeploymentTargetDescription(DEPLOYMENT_1_NAME)).getDescription().getArchive()); scenario.deployment(new DeploymentTargetDescription(DEPLOYMENT_2_NAME)) .getDescription() .getTestableArchive());
@Test public void shouldDeployAllManagedDeployments() throws Exception { registry.create(container1, serviceLoader).setState(State.STARTED); registry.create(container2, serviceLoader).setState(State.STARTED); fire(new DeployManagedDeployments()); assertEventFired(DeployDeployment.class, 3); assertEventFiredInContext(DeployDeployment.class, ContainerContext.class); assertEventFiredInContext(DeployDeployment.class, DeploymentContext.class); assertEventFired(BeforeDeploy.class, 3); assertEventFiredInContext(BeforeDeploy.class, ContainerContext.class); assertEventFiredInContext(BeforeDeploy.class, DeploymentContext.class); assertEventFired(AfterDeploy.class, 3); assertEventFiredInContext(AfterDeploy.class, ContainerContext.class); assertEventFiredInContext(AfterDeploy.class, DeploymentContext.class); verify(deployableContainer1, times(1)).deploy(isA(Archive.class)); verify(deployableContainer1, times(1)).deploy(isA(Descriptor.class)); verify(deployableContainer2, times(1)).deploy(isA(Archive.class)); InOrder ordered = inOrder(deployableContainer1, deployableContainer2); ordered.verify(deployableContainer2, times(1)).deploy( scenario.deployment(new DeploymentTargetDescription(DEPLOYMENT_2_NAME)) .getDescription() .getTestableArchive()); ordered.verify(deployableContainer1, times(1)).deploy( scenario.deployment(new DeploymentTargetDescription(DEPLOYMENT_1_NAME)).getDescription().getArchive()); ordered.verify(deployableContainer1, times(1)).deploy( scenario.deployment(new DeploymentTargetDescription(DEPLOYMENT_4_NAME)).getDescription().getDescriptor()); }
@Test public void shouldNotGetWithUnknownName() { DeploymentScenario scenario = new DeploymentScenario(); scenario.addDeployment( new DeploymentDescription("A", ShrinkWrap.create(JavaArchive.class)) .setTarget(TargetDescription.DEFAULT)); scenario.addDeployment( new DeploymentDescription("B", Descriptors.create(BeansDescriptor.class)) .setTarget(TargetDescription.DEFAULT)); Deployment deployment = scenario.deployment(new DeploymentTargetDescription("C")); Assert.assertNull(deployment); }
@Test public void shouldNotGetWithUnknownName() { DeploymentScenario scenario = new DeploymentScenario(); scenario.addDeployment( new DeploymentDescription("A", ShrinkWrap.create(JavaArchive.class)) .setTarget(TargetDescription.DEFAULT)); scenario.addDeployment( new DeploymentDescription("B", Descriptors.create(BeansDescriptor.class)) .setTarget(TargetDescription.DEFAULT)); Deployment deployment = scenario.deployment(new DeploymentTargetDescription("C")); Assert.assertNull(deployment); }
@Test public void shouldNotGetDefaultWithNonDefaultName() { DeploymentScenario scenario = new DeploymentScenario(); scenario.addDeployment( new DeploymentDescription("A", ShrinkWrap.create(JavaArchive.class)) .setTarget(TargetDescription.DEFAULT)); scenario.addDeployment( new DeploymentDescription("B", Descriptors.create(BeansDescriptor.class)) .setTarget(TargetDescription.DEFAULT)); DeploymentDescription deployment = scenario.deployment(new DeploymentTargetDescription("B")).getDescription(); Assert.assertEquals("B", deployment.getName()); }
@Test public void shouldNotGetDefaultWithNonDefaultName() { DeploymentScenario scenario = new DeploymentScenario(); scenario.addDeployment( new DeploymentDescription("A", ShrinkWrap.create(JavaArchive.class)) .setTarget(TargetDescription.DEFAULT)); scenario.addDeployment( new DeploymentDescription("B", Descriptors.create(BeansDescriptor.class)) .setTarget(TargetDescription.DEFAULT)); DeploymentDescription deployment = scenario.deployment(new DeploymentTargetDescription("B")).getDescription(); Assert.assertEquals("B", deployment.getName()); }
private void setupAndExecuteUnDeployment(String containerName, boolean managed) { DeploymentDescription description = createDeploymentDescription(containerName) .shouldBeManaged(managed); scenario.get().addDeployment(description); controller.get().start(containerName); scenario.get().deployment(new DeploymentTargetDescription(DEPLOYMENT_NAME)).deployed(); controller.get().stop(containerName); }
private void setupAndExecuteUnDeployment(String containerName, boolean managed) { DeploymentDescription description = createDeploymentDescription(containerName) .shouldBeManaged(managed); scenario.get().addDeployment(description); controller.get().start(containerName); scenario.get().deployment(new DeploymentTargetDescription(DEPLOYMENT_NAME)).deployed(); controller.get().stop(containerName); }
@Test // checks same as shouldAllowMultipleDeploymentWithSameNameOfDifferentType but added in different order public void shouldAllowMultipleDeploymentWithSameNameOfDifferentTypeOrderIrrelevant() { DeploymentScenario scenario = new DeploymentScenario(); scenario.addDeployment( new DeploymentDescription("A", Descriptors.create(BeansDescriptor.class)) .setTarget(TargetDescription.DEFAULT)); scenario.addDeployment( new DeploymentDescription("A", ShrinkWrap.create(JavaArchive.class)) .setTarget(TargetDescription.DEFAULT)); Deployment deployment = scenario.deployment(new DeploymentTargetDescription("A")); // will default to Archive Assert.assertEquals("A", deployment.getDescription().getName()); Assert.assertTrue(deployment.getDescription().isArchiveDeployment()); }
@Test // checks same as shouldAllowMultipleDeploymentWithSameNameOfDifferentType but added in different order public void shouldAllowMultipleDeploymentWithSameNameOfDifferentTypeOrderIrrelevant() { DeploymentScenario scenario = new DeploymentScenario(); scenario.addDeployment( new DeploymentDescription("A", Descriptors.create(BeansDescriptor.class)) .setTarget(TargetDescription.DEFAULT)); scenario.addDeployment( new DeploymentDescription("A", ShrinkWrap.create(JavaArchive.class)) .setTarget(TargetDescription.DEFAULT)); Deployment deployment = scenario.deployment(new DeploymentTargetDescription("A")); // will default to Archive Assert.assertEquals("A", deployment.getDescription().getName()); Assert.assertTrue(deployment.getDescription().isArchiveDeployment()); }
@Test public void shouldAllowMultipleDeploymentWithSameNameOfDifferentType() { DeploymentScenario scenario = new DeploymentScenario(); scenario.addDeployment( new DeploymentDescription("A", ShrinkWrap.create(JavaArchive.class)) .setTarget(TargetDescription.DEFAULT)); scenario.addDeployment( new DeploymentDescription("A", Descriptors.create(BeansDescriptor.class)) .setTarget(TargetDescription.DEFAULT)); Deployment deployment = scenario.deployment(new DeploymentTargetDescription("A")); // will default to Archive Assert.assertEquals("A", deployment.getDescription().getName()); Assert.assertTrue(deployment.getDescription().isArchiveDeployment()); }
@Test public void shouldAllowMultipleDeploymentWithSameNameOfDifferentType() { DeploymentScenario scenario = new DeploymentScenario(); scenario.addDeployment( new DeploymentDescription("A", ShrinkWrap.create(JavaArchive.class)) .setTarget(TargetDescription.DEFAULT)); scenario.addDeployment( new DeploymentDescription("A", Descriptors.create(BeansDescriptor.class)) .setTarget(TargetDescription.DEFAULT)); Deployment deployment = scenario.deployment(new DeploymentTargetDescription("A")); // will default to Archive Assert.assertEquals("A", deployment.getDescription().getName()); Assert.assertTrue(deployment.getDescription().isArchiveDeployment()); }