private DeploymentDescription createDeploymentDescription(String targetName) { return new DeploymentDescription(DEPLOYMENT_NAME, ShrinkWrap.create(JavaArchive.class)) .setTarget(new TargetDescription(targetName)); } }
private DeploymentDescription createDeploymentDescription(String targetName) { return new DeploymentDescription(DEPLOYMENT_NAME, ShrinkWrap.create(JavaArchive.class)) .setTarget(new TargetDescription(targetName)); } }
@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)))); }
@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 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 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(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)); }
@Test(expected = IllegalArgumentException.class) public void shouldNotAllowMultipleDescriptorDeploymentsWithSameName() { DeploymentScenario scenario = new DeploymentScenario(); scenario.addDeployment( new DeploymentDescription(DEFAULT_NAME, Descriptors.create(BeansDescriptor.class)) .setTarget(TargetDescription.DEFAULT)); scenario.addDeployment( new DeploymentDescription(DEFAULT_NAME, Descriptors.create(BeansDescriptor.class)) .setTarget(TargetDescription.DEFAULT)); } }
@Test(expected = IllegalArgumentException.class) public void shouldNotAllowMultipleDescriptorDeploymentsWithSameName() { DeploymentScenario scenario = new DeploymentScenario(); scenario.addDeployment( new DeploymentDescription(DEFAULT_NAME, Descriptors.create(BeansDescriptor.class)) .setTarget(TargetDescription.DEFAULT)); scenario.addDeployment( new DeploymentDescription(DEFAULT_NAME, Descriptors.create(BeansDescriptor.class)) .setTarget(TargetDescription.DEFAULT)); } }
@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 shouldNotDefaultWhenMultipleDescriptors() { DeploymentScenario scenario = new DeploymentScenario(); scenario.addDeployment( new DeploymentDescription("A", Descriptors.create(BeansDescriptor.class)) .setTarget(TargetDescription.DEFAULT)); scenario.addDeployment( new DeploymentDescription("B", Descriptors.create(BeansDescriptor.class)) .setTarget(TargetDescription.DEFAULT)); Deployment defaultDeployment = scenario.deployment(DeploymentTargetDescription.DEFAULT); Assert.assertNull(defaultDeployment); }
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionOnUnDeployWhenContainerNotRunning() throws Exception { DeploymentDescription description = new DeploymentDescription(DEPLOYMENT_NAME, ShrinkWrap.create(JavaArchive.class)); description.setTarget(new TargetDescription("_CONTAINER_STOPPED_")); scenario.get().addDeployment(description); deployer.get().undeploy(DEPLOYMENT_NAME); } }
@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()); }
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionOnDeployWhenContainerNotStarted() throws Exception { DeploymentDescription description = new DeploymentDescription(DEPLOYMENT_NAME, ShrinkWrap.create(JavaArchive.class)); description.setTarget(new TargetDescription("_CONTAINER_STOPPED_")); scenario.get().addDeployment(description); deployer.get().deploy(DEPLOYMENT_NAME); }
@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 shouldFireUnDeploymentEventOnUnDeploy() 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().undeploy(DEPLOYMENT_NAME); assertEventFired(UnDeployDeployment.class, 1); }
@Test public void shouldDefaultToSingleDescriptor() { DeploymentDescription deployment = new DeploymentDescription(DEFAULT_NAME, Descriptors.create(BeansDescriptor.class)); deployment.setTarget(TargetDescription.DEFAULT); DeploymentScenario scenario = new DeploymentScenario(); scenario.addDeployment(deployment); DeploymentDescription defaultDeployment = scenario.deployment(DeploymentTargetDescription.DEFAULT).getDescription(); Assert.assertEquals(deployment, defaultDeployment); }
@Test public void shouldNotExportedIfDeploymentIsNotArchive() throws Exception { bind(ApplicationScoped.class, ArquillianDescriptor.class, Descriptors.create(ArquillianDescriptor.class).engine() .deploymentExportPath(EXPORT_PATH)); deployment = new DeploymentDescription(DEPLOYMENT_NAME, Descriptors.create(WebAppDescriptor.class)); deployment.setTarget(new TargetDescription(TARGET_NAME)); fire(new BeforeDeploy(deployableContainer, deployment)); fileShouldExist(false); }