public Void call() throws Exception { for (Deployment d : suiteDeploymentScenario.deployments()) { deploymentEvent.fire(new UnDeployDeployment(findContainer(registry, event.getDeployableContainer()), d)); } return null; } });
@Test public void shouldNotDefaultWhenMultipleArchives() { DeploymentScenario scenario = new DeploymentScenario(); scenario.addDeployment( new DeploymentDescription("A", ShrinkWrap.create(JavaArchive.class)) .setTarget(TargetDescription.DEFAULT)); scenario.addDeployment( new DeploymentDescription("B", ShrinkWrap.create(JavaArchive.class)) .setTarget(TargetDescription.DEFAULT)); Deployment defaultDeployment = scenario.deployment(DeploymentTargetDescription.DEFAULT); Assert.assertNull(defaultDeployment); }
@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 public void shouldAllowMultipleArchiveDeploymentsWithSameArchiveNameWithDifferentTargets() { DeploymentScenario scenario = new DeploymentScenario(); scenario.addDeployment( new DeploymentDescription(DEFAULT_NAME, ShrinkWrap.create(JavaArchive.class, "test.jar")) .setTarget(TargetDescription.DEFAULT)); scenario.addDeployment( new DeploymentDescription("B", ShrinkWrap.create(JavaArchive.class, "test.jar")) .setTarget(new TargetDescription("B"))); Assert.assertEquals(2, scenario.deployments().size()); }
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); } }
@Before public void scenario() throws Exception { registry = new LocalContainerRegistry(injector.get()); when(container1.getContainerName()).thenReturn(CONTAINER_1_NAME); //when(injector.get()).thenReturn(InjectorImpl.of(manager)); when(serviceLoader.onlyOne(eq(DeployableContainer.class))).thenReturn(deployableContainer1); Archive<?> archive = ShrinkWrap.create(JavaArchive.class); scenario.addDeployment( new DeploymentDescription(DEPLOYMENT_1_NAME, archive).setTarget(new TargetDescription(CONTAINER_1_NAME))); registry.create(container1, serviceLoader); bind(SuiteScoped.class, ContainerRegistry.class, registry); bind(ClassScoped.class, DeploymentScenario.class, scenario); }
protected void validate(DeploymentScenario scenario) { ContainerRegistry conReg = containerRegistry.get(); for (TargetDescription target : scenario.targets()) { Container container = conReg.getContainer(target); if (container == null) { for (Deployment deployment : scenario.deployments()) { Container container = conReg.getContainer(deployment.getDescription().getTarget()); if ("custom".equalsIgnoreCase(container.getContainerConfiguration().getMode())) { for (ProtocolDescription proDesc : scenario.protocols()) { if (ProtocolDescription.DEFAULT.equals(proDesc)) { continue;
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); }
@Before public void createSetup() { ContainerRegistry reg = Mockito.mock(ContainerRegistry.class); Container container = Mockito.mock(Container.class); Mockito.when(container.getState()).thenReturn(State.STARTED); Mockito.when(container.getName()).thenReturn("_DEFAULT_"); Container containerStopped = Mockito.mock(Container.class); Mockito.when(containerStopped.getState()).thenReturn(State.STOPPED); Mockito.when(containerStopped.getName()).thenReturn("_CONTAINER_STOPPED_"); Mockito.when(reg.getContainer("_DEFAULT_")).thenReturn(container); Mockito.when(reg.getContainer("_CONTAINER_STOPPED_")).thenReturn(containerStopped); Mockito.when(reg.getContainer(new TargetDescription("_DEFAULT_"))).thenReturn(container); Mockito.when(reg.getContainer(new TargetDescription("_CONTAINER_STOPPED_"))).thenReturn(containerStopped); bind(ApplicationScoped.class, DeploymentScenario.class, new DeploymentScenario()); bind(ApplicationScoped.class, ContainerRegistry.class, reg); fire(new SetupContainers()); // binds the Deployer }
@Override public void stop(String containerQualifier) { 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"); } if (!containerExists(registry.getContainers(), containerQualifier)) { throw new IllegalArgumentException("No container with the specified name exists"); } if (!isControllableContainer(registry.getContainers(), containerQualifier)) { throw new IllegalArgumentException("Could not stop " + containerQualifier + " container. The container life cycle is controlled by Arquillian"); } Container container = registry.getContainer(new TargetDescription(containerQualifier)); List<Deployment> managedDeployments = scenario.startupDeploymentsFor(new TargetDescription(containerQualifier)); for (Deployment d : managedDeployments) { if (d.isDeployed()) { log.info("Automatic undeploying of the managed deployment with name " + d.getDescription().getName() + " from the container with name " + container.getName()); event.fire(new UnDeployDeployment(container, d)); } } log.info("Manual stopping of a server instance"); event.fire(new StopContainer(container)); }
@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 public void shouldAllowMultipleArchiveDeploymentsWithSameArchiveNameWithDifferentTargets() { DeploymentScenario scenario = new DeploymentScenario(); scenario.addDeployment( new DeploymentDescription(DEFAULT_NAME, ShrinkWrap.create(JavaArchive.class, "test.jar")) .setTarget(TargetDescription.DEFAULT)); scenario.addDeployment( new DeploymentDescription("B", ShrinkWrap.create(JavaArchive.class, "test.jar")) .setTarget(new TargetDescription("B"))); Assert.assertEquals(2, scenario.deployments().size()); }
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); } }
@Before public void scenario() throws Exception { registry = new LocalContainerRegistry(injector.get()); when(container1.getContainerName()).thenReturn(CONTAINER_1_NAME); //when(injector.get()).thenReturn(InjectorImpl.of(manager)); when(serviceLoader.onlyOne(eq(DeployableContainer.class))).thenReturn(deployableContainer1); Archive<?> archive = ShrinkWrap.create(JavaArchive.class); scenario.addDeployment( new DeploymentDescription(DEPLOYMENT_1_NAME, archive).setTarget(new TargetDescription(CONTAINER_1_NAME))); registry.create(container1, serviceLoader); bind(SuiteScoped.class, ContainerRegistry.class, registry); bind(ClassScoped.class, DeploymentScenario.class, scenario); }
protected void validate(DeploymentScenario scenario) { ContainerRegistry conReg = containerRegistry.get(); for (TargetDescription target : scenario.targets()) { Container container = conReg.getContainer(target); if (container == null) { for (Deployment deployment : scenario.deployments()) { Container container = conReg.getContainer(deployment.getDescription().getTarget()); if ("custom".equalsIgnoreCase(container.getContainerConfiguration().getMode())) { for (ProtocolDescription proDesc : scenario.protocols()) { if (ProtocolDescription.DEFAULT.equals(proDesc)) { continue;
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); }
@Before public void createSetup() { ContainerRegistry reg = Mockito.mock(ContainerRegistry.class); Container container = Mockito.mock(Container.class); Mockito.when(container.getState()).thenReturn(State.STARTED); Mockito.when(container.getName()).thenReturn("_DEFAULT_"); Container containerStopped = Mockito.mock(Container.class); Mockito.when(containerStopped.getState()).thenReturn(State.STOPPED); Mockito.when(containerStopped.getName()).thenReturn("_CONTAINER_STOPPED_"); Mockito.when(reg.getContainer("_DEFAULT_")).thenReturn(container); Mockito.when(reg.getContainer("_CONTAINER_STOPPED_")).thenReturn(containerStopped); Mockito.when(reg.getContainer(new TargetDescription("_DEFAULT_"))).thenReturn(container); Mockito.when(reg.getContainer(new TargetDescription("_CONTAINER_STOPPED_"))).thenReturn(containerStopped); bind(ApplicationScoped.class, DeploymentScenario.class, new DeploymentScenario()); bind(ApplicationScoped.class, ContainerRegistry.class, reg); fire(new SetupContainers()); // binds the Deployer }
@Override public void stop(String containerQualifier) { 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"); } if (!containerExists(registry.getContainers(), containerQualifier)) { throw new IllegalArgumentException("No container with the specified name exists"); } if (!isControllableContainer(registry.getContainers(), containerQualifier)) { throw new IllegalArgumentException("Could not stop " + containerQualifier + " container. The container life cycle is controlled by Arquillian"); } Container container = registry.getContainer(new TargetDescription(containerQualifier)); List<Deployment> managedDeployments = scenario.startupDeploymentsFor(new TargetDescription(containerQualifier)); for (Deployment d : managedDeployments) { if (d.isDeployed()) { log.info("Automatic undeploying of the managed deployment with name " + d.getDescription().getName() + " from the container with name " + container.getName()); event.fire(new UnDeployDeployment(container, d)); } } log.info("Manual stopping of a server instance"); event.fire(new StopContainer(container)); }
@Test public void shouldNotDefaultWhenMultipleArchives() { DeploymentScenario scenario = new DeploymentScenario(); scenario.addDeployment( new DeploymentDescription("A", ShrinkWrap.create(JavaArchive.class)) .setTarget(TargetDescription.DEFAULT)); scenario.addDeployment( new DeploymentDescription("B", ShrinkWrap.create(JavaArchive.class)) .setTarget(TargetDescription.DEFAULT)); Deployment defaultDeployment = scenario.deployment(DeploymentTargetDescription.DEFAULT); Assert.assertNull(defaultDeployment); }
public Void call() throws Exception { for (Deployment d : suiteDeploymentScenario.deployments()) { deploymentEvent.fire(new DeployDeployment(findContainer(registry, event.getDeployableContainer()), d)); } return null; } });