@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; } }
/** * @param testable * the testable to set */ public DeploymentDescription shouldBeTestable(boolean testable) { if (!isArchiveDeployment()) { throw new IllegalArgumentException("A non ArchiveDeployment can not be testable: " + getName()); } this.testable = testable; return this; }
private void logWarningIfArchiveHasUnexpectedFileExtension(final DeploymentDescription deployment) { if (!Validate.archiveHasExpectedFileExtension(deployment.getArchive())) { log.warning("Deployment archive of type " + deployment.getArchive().getClass().getSimpleName() + " has been given an unexpected file extension. Archive name: " + deployment.getArchive().getName() + ", deployment name: " + deployment.getName() + ". It might not be wrong, but the container will" + " rely on the given file extension, the archive type is only a description of a certain structure."); } }
if (Archive.class.isAssignableFrom(deploymentMethod.getReturnType())) deployment = new DeploymentDescription(deploymentAnnotation.name(), invoke(Archive.class, deploymentMethod)); deployment.shouldBeTestable(deploymentAnnotation.testable()); deployment = new DeploymentDescription(deploymentAnnotation.name(), invoke(Descriptor.class, deploymentMethod)); deployment.shouldBeManaged(deploymentAnnotation.managed()); deployment.setOrder(deploymentAnnotation.order()); if (target != null) deployment.setTarget(target); deployment.setProtocol(protocol); deployment.setExpectedException(deploymentMethod.getAnnotation(ShouldThrowException.class).value());
@Test public void shouldDefaultToArchiveWhenDescriptorIsPresent() { 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 defaultDeployment = scenario.deployment(DeploymentTargetDescription.DEFAULT).getDescription(); Assert.assertEquals("A", defaultDeployment.getName()); }
if (deploymentDesc.getOrder() == 1) { Assert.assertEquals( "Verify deployment has specified target", new TargetDescription("target-first"), deploymentDesc.getTarget()); deploymentDesc.getProtocol()); Assert.assertEquals(1, deploymentDesc.getOrder()); Assert.assertEquals(false, deploymentDesc.managed()); Assert.assertEquals(false, deploymentDesc.testable()); Assert.assertTrue(Validate.isArchiveOfType(JavaArchive.class, deploymentDesc.getArchive())); Assert.assertNull(deploymentDesc.getExpectedException()); } else { Assert.assertEquals( "Verify deployment has specified target", new TargetDescription("target-second"), deploymentDesc.getTarget()); Assert.assertEquals( "Verify deployment has specified protocol", new ProtocolDescription("protocol-second"), deploymentDesc.getProtocol()); Assert.assertEquals(2, deploymentDesc.getOrder()); Assert.assertEquals(false, deploymentDesc.managed()); Assert.assertEquals(true, deploymentDesc.testable()); Assert.assertTrue(Validate.isArchiveOfType(JavaArchive.class, deploymentDesc.getArchive())); Assert.assertNull(deploymentDesc.getExpectedException());
/** * 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 buildTestableDeployments(DeploymentScenario scenario, TestClass testCase, ProtocolRegistry protoReg) { for (Deployment deployment : scenario.deployments()) { DeploymentDescription description = deployment.getDescription(); if (!description.testable() || !description.isArchiveDeployment()) { continue; ProtocolDefinition protocolDefinition = protoReg.getProtocol(description.getProtocol()); if (protocolDefinition == null) { protocolDefinition = protoReg.getProtocol( containerRegistry.get() .getContainer(description.getTarget()) .getDeployableContainer() .getDefaultProtocol()); DeploymentPackager packager = protocol.getPackager(); Archive<?> applicationArchive = description.getArchive(); applyApplicationProcessors(description.getArchive(), testCase); applyAuxiliaryProcessors(auxiliaryArchives); description.setTestableArchive( packager.generateDeployment( new TestDeployment(deployment.getDescription(), applicationArchive, auxiliaryArchives),
@Test(expected = IllegalArgumentException.class) public void shouldNotAllowMultipleArchiveDeploymentsWithSameName() { DeploymentScenario scenario = new DeploymentScenario(); scenario.addDeployment( new DeploymentDescription("X", ShrinkWrap.create(JavaArchive.class)) .setTarget(TargetDescription.DEFAULT)); scenario.addDeployment( new DeploymentDescription("X", ShrinkWrap.create(JavaArchive.class)) .setTarget(TargetDescription.DEFAULT)); }
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); } } }
public List<DeploymentDescription> generate(TestClass testClass) { List<DeploymentDescription> descriptions = delegate(testClass); boolean inCeContainer = isDeployedInCeContainer(); List<DeploymentDescription> copy = new ArrayList<>(); for (DeploymentDescription description : descriptions) { Archive<?> archive = description.getArchive(); // only wrap in war, if it's in CE container if (inCeContainer && JavaArchive.class.isInstance(archive)) { JavaArchive jar = JavaArchive.class.cast(archive); copy.add(new DeploymentDescription(description.getName(), toWar(jar))); } else { copy.add(description); } } return copy; }
@Override public String toString() { return getName(); } }
@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 shouldFireDeploymentEventOnDeploy() throws Exception { DeploymentDescription description = new DeploymentDescription(DEPLOYMENT_NAME, ShrinkWrap.create(JavaArchive.class)); description.shouldBeManaged(false); description.setTarget(new TargetDescription("_DEFAULT_")); scenario.get().addDeployment(description); deployer.get().deploy(DEPLOYMENT_NAME); assertEventFired(DeployDeployment.class, 1); }
@Test public void shouldReadExpectedAndOverrideDeployment() { List<DeploymentDescription> scenario = generate(ExpectedDeploymentExceptionSet.class); Assert.assertNotNull(scenario); Assert.assertEquals( "Verify all deployments were found", 1, scenario.size()); DeploymentDescription deploymentOne = scenario.get(0); Assert.assertEquals(false, deploymentOne.testable()); Assert.assertTrue(Validate.isArchiveOfType(JavaArchive.class, deploymentOne.getArchive())); Assert.assertEquals(Exception.class, deploymentOne.getExpectedException()); }
new DeploymentDescription(DEPLOYMENT_1_NAME, ShrinkWrap.create(JavaArchive.class)) .setTarget(new TargetDescription(CONTAINER_1_NAME)) .shouldBeTestable(false) .setOrder(2)); new DeploymentDescription(DEPLOYMENT_2_NAME, ShrinkWrap.create(JavaArchive.class)) .setTarget(new TargetDescription(CONTAINER_2_NAME)) .setOrder(1) .shouldBeTestable(true) .setTestableArchive(ShrinkWrap.create(JavaArchive.class))); new DeploymentDescription(DEPLOYMENT_3_NAME, ShrinkWrap.create(JavaArchive.class)) .setTarget(new TargetDescription(CONTAINER_2_NAME)) .setOrder(3) .shouldBeTestable(false) .shouldBeManaged(false)); new DeploymentDescription(DEPLOYMENT_4_NAME, Descriptors.create(BeansDescriptor.class)) .setTarget(new TargetDescription(CONTAINER_1_NAME)) .setOrder(4) .shouldBeManaged(true));
@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()); } } }
public synchronized void setTargetServerGroups(@Observes BeforeDeploy event) { final String deploymentName = event.getDeployment().getName(); if (serverGroupTargets.containsKey(deploymentName)) { final DeploymentDescription deploymentDescription = event.getDeployment(); final Archive<?> delegate = deploymentDescription.getArchive(); // Note that this breaks if anything else replaces this archive deploymentDescription.setTestableArchive(new ServerGroupArchive<>(delegate, Collections.unmodifiableSet(serverGroupTargets.get(deploymentName)))); } }
private Collection<DeploymentDescription> generateDependencyDeployments(Method deploymentMethod) { Dependencies dependency = deploymentMethod.getAnnotation(Dependencies.class); Collection<DeploymentDescription> deployments = new ArrayList<DeploymentDescription>(); if (dependency.value() != null) for (Addon addon : dependency.value()) { AddonId id = AddonId.from(addon.name(), addon.version()); DeploymentDescription deploymentDescription = new DeploymentDescription(id.toCoordinates(), ShrinkWrap.create(ForgeRemoteAddon.class).setAddonId(id)); deploymentDescription.shouldBeTestable(false); deployments.add(deploymentDescription); } return deployments; }