/** * Test deployment when the container does not support a given deployable type. */ public void testDeployWhenContainerDoesNotSupportDeployableType() { AbstractCopyingInstalledLocalDeployer deployer = new TestableCopyingDeployer( createContainer(createContainerCapability(DeployableType.EAR), null)); try { deployer.deploy(new WAR("dummy")); fail("Should have thrown a ContainerException here"); } catch (ContainerException expected) { assertEquals("WAR archives are not supported for deployment in [mycontainer]. " + "Got [dummy]", expected.getMessage()); } }
/** * Test that the handling of ShouldDeployExpanded functions correctly. */ public void testShouldDeployExpanded() { AbstractCopyingInstalledLocalDeployer deployer = new TestableCopyingDeployer( createContainer(createContainerCapability(DeployableType.WAR), null)); assertTrue(deployer.shouldDeployExpanded(DeployableType.WAR)); deployer.setShouldDeployExpanded(DeployableType.WAR, true); assertTrue(deployer.shouldDeployExpanded(DeployableType.WAR)); deployer.setShouldDeployExpanded(DeployableType.WAR, false); assertFalse(deployer.shouldDeployExpanded(DeployableType.WAR)); deployer.setShouldDeployExpanded(DeployableType.WAR, true); assertTrue(deployer.shouldDeployExpanded(DeployableType.WAR)); }
/** * Create mock container capability. * @param type Deployable type. * @return Mock container capability for given deployable type. */ private ContainerCapability createContainerCapability(DeployableType type) { Mock mockContainerCapability = mock(ContainerCapability.class); mockContainerCapability.stubs().method("supportsDeployableType") .with(eq(type)).will(returnValue(true)); mockContainerCapability.stubs().method("supportsDeployableType") .with(not(eq(type))).will(returnValue(false)); return (ContainerCapability) mockContainerCapability.proxy(); }
/** * Test deployment when the container configuration does not exist (see CARGO-1131). */ public void testDeployWhenContainerConfigurationDoesNotExist() { try { new TestableCopyingDeployer(createContainer( createContainerCapability(DeployableType.WAR), "non-existing")); fail("Should have thrown a CargoException here"); } catch (CargoException expected) { assertTrue("Incorrect message: " + expected.getMessage(), expected.getMessage().contains("ram:///non-existing")); } }
Mock mockConfiguration = mock(LocalConfiguration.class); Mock mockContainer = mock(InstalledLocalContainer.class); mockConfiguration.stubs().method("getHome").will(returnValue("ram:///" + homeString)); mockContainer.stubs().method("getConfiguration").will( returnValue(mockConfiguration.proxy())); mockContainer.stubs().method("getCapability").will(returnValue(capability)); mockContainer.stubs().method("getFileHandler").will(returnValue(this.fileHandler)); mockContainer.stubs().method("getLogger").will(returnValue(new NullLogger())); mockContainer.stubs().method("getId").will(returnValue("mycontainer"));
/** * Test deployment of a WAR in its default context. * @throws Exception If anything goes wrong. */ public void testDeployWhenWarWithDefaultContext() throws Exception { WAR war = new WAR("ram:///some/warfile.war"); this.fsManager.resolveFile(war.getFile()).createFile(); AbstractCopyingInstalledLocalDeployer deployer = new TestableCopyingDeployer( createContainer(createContainerCapability(DeployableType.WAR), null)); assertFalse(this.fsManager.resolveFile("ram:///webapps/warfile.war").exists()); deployer.deploy(war); assertTrue(this.fsManager.resolveFile("ram:///webapps/warfile.war").exists()); }
/** * Test deployment of an expanded WAR in a custom context. * @throws Exception If anything goes wrong. */ public void testDeployToNonExistingDirectory() throws Exception { WAR war = new WAR("ram:///some/warfile.war"); this.fsManager.resolveFile(war.getFile()).createFile(); AbstractCopyingInstalledLocalDeployer deployer = new TestableCopyingDeployerWithDifferentDirectory( createContainer(createContainerCapability(DeployableType.WAR), null)); try { deployer.deploy(war); fail("Should have thrown a CargoException here"); } catch (CargoException expected) { assertTrue("Incorrect message: " + expected.getMessage(), expected.getMessage().contains("ram:///webapps-nonexisting")); } }
/** * Test deployment of a WAR in a custom context. * @throws Exception If anything goes wrong. */ public void testDeployWhenWarWithCustomContext() throws Exception { WAR war = new WAR("ram:///some/warfile.war"); this.fsManager.resolveFile("ram:///some/warfile.war").createFile(); war.setContext("context"); AbstractCopyingInstalledLocalDeployer deployer = new TestableCopyingDeployer( createContainer(createContainerCapability(DeployableType.WAR), null)); assertFalse(this.fsManager.resolveFile("ram:///webapps/context.war").exists()); deployer.deploy(war); assertTrue(this.fsManager.resolveFile("ram:///webapps/context.war").exists()); }
/** * Test whether two WARs can be deployed to the same context. * @throws Exception If anything goes wrong. */ public void testCanBeDeployedWhenTwoWARsInSameWebContext() throws Exception { AbstractCopyingInstalledLocalDeployer deployer = new TestableCopyingDeployer( createContainer(createContainerCapability(DeployableType.WAR), null)); // Create WARs and make sure the wrapped files exist WAR war1 = new WAR("ram:///path1/warfile.war"); this.fsManager.resolveFile(war1.getFile()).createFile(); WAR war2 = new WAR("ram:///path2/warfile.war"); this.fsManager.resolveFile(war2.getFile()).createFile(); // Deploy the first WAR deployer.deploy(war1); assertTrue(this.fsManager.resolveFile("ram:///webapps/warfile.war").exists()); try { // Deploy the second WAR using the same context as the already deployed WAR deployer.deploy(war2); fail("Expected ContainerException because we deployed two WARs with the same context " + "name."); } catch (ContainerException expected) { assertEquals("Failed to deploy [ram:///path2/warfile.war] to [ram:///webapps]. The " + "required web context is already in use by another application.", expected.getMessage()); } }
/** * Test deployment of an expanded WAR in a custom context. * @throws Exception If anything goes wrong. */ public void testDeployWhenExpandedWarWithCustomContext() throws Exception { // Create an expanded WAR WAR war = new WAR("ram:///some/expanded/warfile"); war.setContext("context"); war.setFileHandler(this.fileHandler); this.fsManager.resolveFile(war.getFile()).createFolder(); AbstractCopyingInstalledLocalDeployer deployer = new TestableCopyingDeployer( createContainer(createContainerCapability(DeployableType.WAR), null)); assertFalse(this.fsManager.resolveFile("ram:///webapps/context").exists()); deployer.deploy(war); assertTrue(this.fsManager.resolveFile("ram:///webapps/context").exists()); }