public TargetDescription getTargetDescription() { return deploymentDescription == null ? null : deploymentDescription.getTarget(); }
public TargetDescription getTargetDescription() { return deploymentDescription == null ? null : deploymentDescription.getTarget(); }
public Set<TargetDescription> targets() { Set<TargetDescription> targets = new HashSet<TargetDescription>(); for (Deployment dep : deployments) { targets.add(dep.getDescription().getTarget()); } return targets; }
public Set<TargetDescription> targets() { Set<TargetDescription> targets = new HashSet<TargetDescription>(); for (Deployment dep : deployments) { targets.add(dep.getDescription().getTarget()); } return targets; }
/** * Get all {@link DeploymentDescription} defined to be deployed during Test startup for a specific {@link * TargetDescription} ordered. * * @param target * The Target to filter on * * @return A List of found {@link DeploymentDescription}. Will return a empty list if none are found. */ public List<Deployment> startupDeploymentsFor(TargetDescription target) { Validate.notNull(target, "Target must be specified"); List<Deployment> startupDeployments = new ArrayList<Deployment>(); for (Deployment deployment : deployments) { DeploymentDescription desc = deployment.getDescription(); if (desc.managed() && target.equals(desc.getTarget())) { startupDeployments.add(deployment); } } // sort them by order Collections.sort(startupDeployments, new Comparator<Deployment>() { public int compare(Deployment o1, Deployment o2) { return new Integer(o1.getDescription().getOrder()).compareTo(o2.getDescription().getOrder()); } }); return Collections.unmodifiableList(startupDeployments); }
private String createFileName(DeploymentDescription deployment, Archive<?> archive) { // TODO: where do we get TestClass name from ? return deployment.getTarget().getName() + "_" + deployment.getName() + "_" + archive.getName(); }
private String createFileName(DeploymentDescription deployment, Archive<?> archive) { // TODO: where do we get TestClass name from ? return deployment.getTarget().getName() + "_" + deployment.getName() + "_" + archive.getName(); }
/** * Validate that a deployment with a archive of the same name does not have the same taget */ private void validateNotSameArchiveAndSameTarget(DeploymentDescription deployment) { if (!deployment.isArchiveDeployment()) { return; } for (Deployment existing : archiveDeployments(deployments)) { if (existing.getDescription().getArchive().getName().equals(deployment.getArchive().getName())) { if (existing.getDescription().getTarget().equals(deployment.getTarget())) { throw new IllegalArgumentException("Can not add multiple " + Archive.class.getName() + " archive deployments with the same archive name " + deployment.getName() + " that target the same target " + deployment.getTarget()); } } } } }
/** * Validate that a deployment with a archive of the same name does not have the same taget */ private void validateNotSameArchiveAndSameTarget(DeploymentDescription deployment) { if (!deployment.isArchiveDeployment()) { return; } for (Deployment existing : archiveDeployments(deployments)) { if (existing.getDescription().getArchive().getName().equals(deployment.getArchive().getName())) { if (existing.getDescription().getTarget().equals(deployment.getTarget())) { throw new IllegalArgumentException("Can not add multiple " + Archive.class.getName() + " archive deployments with the same archive name " + deployment.getName() + " that target the same target " + deployment.getTarget()); } } } } }
private void lookup(Method method, ResultCallback callback) { DeploymentTargetDescription deploymentTarget = locateDeployment(method); ContainerRegistry containerRegistry = this.containerRegistry.get(); DeploymentScenario deploymentScenario = this.deploymentScenario.get(); Deployment deployment = deploymentScenario.deployment(deploymentTarget); if (deployment == null && deploymentTarget != DeploymentTargetDescription.DEFAULT) { // trying to operate on a non existing DeploymentTarget (which is not the DEFAULT) throw new IllegalStateException( "No deployment found in " + DeploymentScenario.class.getSimpleName() + " for defined target: " + deploymentTarget.getName() + ". " + "Please verify that the @" + OperateOnDeployment.class.getSimpleName() + " annotation on method " + method.getName() + " match a defined " + "@" + org.jboss.arquillian.container.test.api.Deployment.class.getSimpleName() + ".name"); } if (deployment != null) { Container container = containerRegistry.getContainer(deployment.getDescription().getTarget()); callback.call(container, deployment); } }
private void forEachDeployment(List<Deployment> deployments, Operation<Container, Deployment> operation) throws Exception { injector.get().inject(operation); ContainerRegistry containerRegistry = this.containerRegistry.get(); if (containerRegistry == null) { return; } for (Deployment deployment : deployments) { Container container = containerRegistry.getContainer(deployment.getDescription().getTarget()); operation.perform(container, deployment); } }
private void forEachDeployment(List<Deployment> deployments, Operation<Container, Deployment> operation) throws Exception { injector.get().inject(operation); ContainerRegistry containerRegistry = this.containerRegistry.get(); if (containerRegistry == null) { return; } for (Deployment deployment : deployments) { Container container = containerRegistry.getContainer(deployment.getDescription().getTarget()); operation.perform(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)); }
@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)); }
@Override public List<DeploymentDescription> generate(TestClass testClass) { List<DeploymentDescription> deployments = super.generate(testClass); List<DeploymentDescription> updatedDeployments = new ArrayList<DeploymentDescription>(); for (DeploymentDescription currentDeploymentDescription : deployments) { if (currentDeploymentDescription.getArchive() instanceof PortletArchive) { DeploymentDescription newDescription = new DeploymentDescription(currentDeploymentDescription.getName(), currentDeploymentDescription.getArchive().as(WebArchive.class)); newDescription.shouldBeTestable(currentDeploymentDescription.testable()) .shouldBeManaged(currentDeploymentDescription.managed()) .setOrder(currentDeploymentDescription.getOrder()) .setTarget(currentDeploymentDescription.getTarget()) .setProtocol(currentDeploymentDescription.getProtocol()) .setExpectedException(currentDeploymentDescription.getExpectedException()); updatedDeployments.add(newDescription); } else { updatedDeployments.add(currentDeploymentDescription); } } return updatedDeployments; } }
public void observeBeforeDeploy(@Observes BeforeDeploy event) { DeploymentReport deploymentReport = new DeploymentReport(); DeploymentDescription description = event.getDeployment(); deploymentReport.setArchiveName(description.getArchive().getName()); deploymentReport.setName(description.getName()); int order = description.getOrder(); if (order > 0) { deploymentReport.setOrder(order); } String protocol = description.getProtocol().getName(); if (!protocol.equals("_DEFAULT_")) { deploymentReport.setProtocol(protocol); } else { deploymentReport.setProtocol("_DEFAULT_"); } deploymentReport.setTarget(description.getTarget().getName()); boolean reported = false; for (ContainerReport containerReport : reporter.get().getLastTestSuiteReport().getContainerReports()) { if (containerReport.getQualifier().equals(deploymentReport.getTarget())) { containerReport.getDeploymentReports().add(deploymentReport); reported = true; break; } } if (!reported) { if (reporter.get().getLastTestSuiteReport().getContainerReports().size() == 1) { reporter.get().getLastTestSuiteReport().getContainerReports().get(0).getDeploymentReports().add(deploymentReport); } } }
@Test public void shouldHandleMultipleDeploymentsAllDefault() throws Exception { List<DeploymentDescription> scenario = generate(MultiDeploymentsDefault.class); Assert.assertNotNull(scenario); Assert.assertEquals( "Verify all deployments were found", 2, scenario.size()); for (DeploymentDescription deployment : scenario) { Assert.assertEquals( "Verify deployment has default target", TargetDescription.DEFAULT, deployment.getTarget()); Assert.assertEquals( "Verify deployment has default protocol", ProtocolDescription.DEFAULT, deployment.getProtocol()); Assert.assertEquals(-1, deployment.getOrder()); Assert.assertEquals(true, deployment.managed()); Assert.assertTrue(Validate.isArchiveOfType(JavaArchive.class, deployment.getArchive())); } }
@Test public void shouldHandleMultipleDeploymentsAllDefault() throws Exception { List<DeploymentDescription> scenario = generate(MultiDeploymentsDefault.class); Assert.assertNotNull(scenario); Assert.assertEquals( "Verify all deployments were found", 2, scenario.size()); for (DeploymentDescription deployment : scenario) { Assert.assertEquals( "Verify deployment has default target", TargetDescription.DEFAULT, deployment.getTarget()); Assert.assertEquals( "Verify deployment has default protocol", ProtocolDescription.DEFAULT, deployment.getProtocol()); Assert.assertEquals(-1, deployment.getOrder()); Assert.assertEquals(true, deployment.managed()); Assert.assertTrue(Validate.isArchiveOfType(JavaArchive.class, deployment.getArchive())); } }