/** * {@inheritDoc} */ @Override public void undeployWebApp(Deployable deployable) { throw new ContainerException("Not supported"); } }
/** * 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 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()); } }
/** * {@inheritDoc} */ @Override public void undeploy(Deployable deployable) { throw new ContainerException("Not supported"); }
/** * 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()); } }
/** * {@inheritDoc} */ @Override public void deploy(Deployable deployable) { throw new ContainerException("Not supported"); }
/** * 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()); } }
/** * {@inheritDoc} */ @Override public void start(Deployable deployable) { throw new ContainerException("Not supported"); }
/** * 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()); }
/** * {@inheritDoc} */ @Override public void stop(Deployable deployable) { throw new ContainerException("Not supported"); }
/** * 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()); } }
/** * {@inheritDoc} */ @Override public void undeployWebApp(Deployable deployable) { throw new ContainerException("Not supported"); } }
/** * @param artifactName the artifact for which to return the location (eg "simple-war"). * @return the location of the artifact as a string */ public String getTestDataFileFor(String artifactName) { String result = this.testDataArtifacts.get(artifactName); if (result == null) { throw new ContainerException("Test data artifact not found [" + artifactName + "]"); } return result; } }
/** * @param artifactName the artifact for which to return the location (eg "simple-war"). * @return the location of the artifact as a string */ public String getTestDataFileFor(String artifactName) { String result = this.testDataArtifacts.get(artifactName); if (result == null) { throw new ContainerException("Test data artifact not found [" + artifactName + "]"); } return result; } }
/** * Pauses the current thread for the specified amount. * * @param ms The time to sleep in milliseconds */ public static void sleep(long ms) { try { Thread.sleep(ms); } catch (InterruptedException e) { throw new ContainerException("Interruption during sleep", e); } } }
/** * Undeploy the handler representing the webapp. * * @param handler the handler representing the webapp * @throws Exception on invocation exception */ public void removeHandler(Object handler) throws Exception { if (handler == null) { return; } if (removeHandlerMethod == null) { throw new ContainerException("No Jetty instance to deploy to"); } removeHandlerMethod.invoke(contextHandlers, new Object[] {handler}); }
/** * Undeploy the handler representing the webapp. * * @param handler the handler representing the webapp * @throws Exception on invocation exception */ public void removeHandler(Object handler) throws Exception { if (handler == null) { return; } if (removeHandlerMethod == null) { throw new ContainerException("No Jetty instance to deploy to"); } removeHandlerMethod.invoke(contextHandlers, new Object[] {handler}); }
/** * Sets up the listener socket. * * @return the listener socket that has been set up */ private ServerSocket setUpListenerSocket() { ServerSocket serverSocket; try { serverSocket = new ServerSocket(this.port); } catch (IOException e) { throw new ContainerException("Error setting up the server listener socket", e); } return serverSocket; } }
/** * @param url url to encode * @return the URL-encoded location that can be passed in a URL */ private String encodeURLLocation(URL url) { String encodedString; try { encodedString = URLEncoder.encode(url.toExternalForm(), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new ContainerException("Failed to encode Deployable location [" + url + "] using an [UTF-8] encoding", e); } return encodedString; } }
/** * @param url url to encode * @return the URL-encoded location that can be passed in a URL */ private String encodeURLLocation(URL url) { String encodedString; try { encodedString = URLEncoder.encode(url.toExternalForm(), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new ContainerException("Failed to encode Deployable location [" + url + "] using an [UTF-8] encoding", e); } return encodedString; } }