/** * Test user parsing empty field. */ public void testParseUserWithEmptyField() { try { User.parseUser(""); fail("Should have raised an exception here"); } catch (ContainerException expected) { assertEquals("User property has empty value.", expected.getMessage()); } }
/** * Test user parsing with a missing field. */ public void testParseUserWithMissingField() { try { User.parseUser("name:password:role:"); fail("Should have raised an exception here"); } catch (ContainerException expected) { assertEquals("Invalid format for [name:password:role:]", expected.getMessage()); } }
/** * Test {@link ZipURLInstaller#getHome()} when container not installed yet. * @throws Exception If anything goes wrong. */ public void testGetHomeWhenContainerNotInstalled() throws Exception { this.installer.setExtractDir("ram:///tmp"); try { this.installer.getHome(); fail("Should have thrown a container exception here"); } catch (ContainerException expected) { assertEquals("Failed to get container installation home as the container has not yet " + "been installed. Please call install() first.", expected.getMessage()); } }
/** * 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()); } }
/** * Smoke test: startup with no deployable. * @throws Exception If anything goes wrong. */ public void testStartWithNoDeployable() throws Exception { setContainer(createContainer(createConfiguration(ConfigurationType.STANDALONE))); getLocalContainer().start(); assertEquals(State.STARTED, getContainer().getState()); try { getLocalContainer().start(); fail("the second start attempt did not fail"); } catch (ContainerException expected) { assertTrue(expected.getMessage() + " does not contain the word 'restart'", expected.getMessage().contains("restart")); } getLocalContainer().stop(); assertEquals(State.STOPPED, getContainer().getState()); }
/** * Test the creation of a config directory when the target directory exists and is not empty. * @throws Exception If anything goes wrong. */ public void testCreateConfigDirWhenDirectoryNotEmpty() throws Exception { String configDir = "ram:///cargo/testCreateConfigDirWhenDirectoryNotEmpty"; FileObject configDirObject = VFS.getManager().resolveFile(configDir); configDirObject.resolveFile("somefile").createFile(); TestableAbstractStandaloneConfiguration configuration = new TestableAbstractStandaloneConfiguration(configDir); configuration.setFileHandler(new VFSFileHandler()); try { configuration.setupConfigurationDir(); fail("Should have thrown a ContainerException as the directory is not empty"); } catch (ContainerException expected) { assertEquals("Invalid configuration dir " + "[ram:///cargo/testCreateConfigDirWhenDirectoryNotEmpty]. When using standalone " + "configurations, the configuration dir must point to an empty directory. Note " + "that everything in that dir will get deleted by Cargo.", expected.getMessage()); } }
/** * 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()); } }