/** * Create the autodeploy deployable (if the current project is a Java EE deployable) * @param container Container. * @return The autodeploy deployable. * @throws MojoExecutionException If deployable creation fails. */ protected org.codehaus.cargo.container.deployable.Deployable createAutoDeployDeployable( org.codehaus.cargo.container.Container container) throws MojoExecutionException { Deployable deployableElement = new Deployable(); return deployableElement.createDeployable(container.getId(), getCargoProject()); }
/** * {@inheritDoc} */ @Override public void testStartWithOneExpandedWarDeployed() throws Exception { // The WebLogic 12.x container get confused when expanded WARs are redeployed if (!"weblogic12x".equals(getContainer().getId())) { super.testStartWithOneExpandedWarDeployed(); } } }
/** * {@inheritDoc} */ @Override public Deployer createDeployer(Container container, DeployerType deployerType) { DeployerFactoryParameters parameters = new DeployerFactoryParameters(); parameters.container = container; return createImplementation( new RegistrationKey(new SimpleContainerIdentity(container.getId()), deployerType.getType()), parameters, "deployer"); }
/** * {@inheritDoc} */ @Override public Deployer createDeployer(Container container, DeployerType deployerType) { DeployerFactoryParameters parameters = new DeployerFactoryParameters(); parameters.container = container; return createImplementation( new RegistrationKey(new SimpleContainerIdentity(container.getId()), deployerType.getType()), parameters, "deployer"); }
/** * User configures java.sql.Driver -> container provides javax.sql.DataSource with no * transaction support * @throws MalformedURLException If servlet WAR URL cannot be created. */ public void testUserConfiguresDriverAndRequestsDataSource() throws MalformedURLException { DataSourceFixture fixture = ConfigurationFixtureFactory.createDataSource(); if ("glassfish4x".equals(getContainer().getId())) { fixture.jndiLocation = "jdbc/__default"; } testServletThatIssuesGetConnectionFrom(fixture, "datasource"); }
/** * {@inheritDoc} */ @Override public Deployer createDeployer(Container container) { Deployer deployer; DeployerType type = DeployerType.toType(container.getType()); if (isDeployerRegistered(container.getId(), type)) { getLogger().debug("Creating a default [" + type + "] deployer", this.getClass().getName()); deployer = createDeployer(container, type); } else { throw new ContainerException("There's no registered deployer matching your " + "container's type of [" + container.getType().getType() + "]"); } return deployer; }
/** * {@inheritDoc} */ @Override public Deployer createDeployer(Container container) { Deployer deployer; DeployerType type = DeployerType.toType(container.getType()); if (isDeployerRegistered(container.getId(), type)) { getLogger().debug("Creating a default [" + type + "] deployer", this.getClass().getName()); deployer = createDeployer(container, type); } else { throw new ContainerException("There's no registered deployer matching your " + "container's type of [" + container.getType().getType() + "]"); } return deployer; }
/** * Test deployment of a WAR with relative path. * @throws Exception If anything goes wrong. */ public void testDeployWarDefinedWithRelativePath() throws Exception { // Copies the testdata artifact File artifactDir = new File(getTestData().targetDir).getParentFile(); File artifactFile = new File(artifactDir, "simple.war").getAbsoluteFile(); Copy copyTask = (Copy) new AntUtils().createProject().createTask("copy"); copyTask.setTofile(artifactFile); copyTask.setFile(new File(getTestData().getTestDataFileFor("simple-war"))); copyTask.execute(); Deployable war = new DefaultDeployableFactory().createDeployable(getContainer().getId(), artifactFile.getAbsolutePath(), DeployableType.WAR); getLocalContainer().getConfiguration().addDeployable(war); URL warPingURL = new URL("http://localhost:" + getTestData().port + "/simple/index.jsp"); startAndStop(warPingURL); }
/** * Deploy WAR statically. * @throws Exception If anything goes wrong. */ public void testDeployWarStatically() throws Exception { Deployable war = new DefaultDeployableFactory().createDeployable(getContainer().getId(), getTestData().getTestDataFileFor("simple-war"), DeployableType.WAR); getLocalContainer().getConfiguration().addDeployable(war); URL warPingURL = new URL("http://localhost:" + getTestData().port + "/simple-war/index.jsp"); startAndStop(warPingURL); }
/** * Test multiple datasources. * @throws MalformedURLException If servlet WAR URL cannot be created. */ public void testMultipleDataSources() throws MalformedURLException { DataSourceFixture fixture = ConfigurationFixtureFactory.createDataSource(); if ("glassfish4x".equals(getContainer().getId())) { fixture.jndiLocation = "jdbc/__default"; } Configuration config = getLocalContainer().getConfiguration(); config.setProperty(DatasourcePropertySet.DATASOURCE + ".1", fixture .buildDataSourcePropertyString()); fixture = ConfigurationFixtureFactory.createAnotherDataSource(); testServletThatIssuesGetConnectionFrom(fixture, "two-datasources"); } }
/** * Tests servlet. * @param type WAR type. * @throws MalformedURLException If URL cannot be built. */ protected void testWar(String type) throws MalformedURLException { Deployable war = new DefaultDeployableFactory().createDeployable(getContainer().getId(), getTestData() .getTestDataFileFor(type + "-war"), DeployableType.WAR); getLocalContainer().getConfiguration().addDeployable(war); URL warPingURL = new URL("http://localhost:" + getTestData().port + "/" + type + "-war/test"); startAndStop(warPingURL); }
/** * Start container with port offset. * @throws Exception If anything goes wrong. */ public void testStartWithPortOffset() throws Exception { int offsetValue = Integer.valueOf(OFFSET); int portWithOffset = getTestData().port + offsetValue; Deployable war = new DefaultDeployableFactory().createDeployable(getContainer().getId(), getTestData().getTestDataFileFor("simple-war"), DeployableType.WAR); getLocalContainer().getConfiguration().addDeployable(war); URL warPingURL = new URL("http://localhost:" + portWithOffset + "/simple-war/index.jsp"); getLocalContainer().start(); PingUtils.assertPingTrue(warPingURL.getPath() + " not started", warPingURL, getLogger()); getLocalContainer().stop(); PingUtils.assertPingFalse(warPingURL.getPath() + " not stopped", warPingURL, getLogger()); } }
/** * Test expanded WAR with a <code>context.xml</code> file. * @throws Exception If anything goes wrong. */ public void testExpandedWarWithContextXmlFile() throws Exception { // Copy the war from the Maven local repository in order to expand it File artifactDir = new File(getTestData().targetDir).getParentFile(); Expand expandTask = (Expand) new AntUtils().createProject().createTask("unwar"); expandTask.setDest(new File(artifactDir, "tomcat-context")); expandTask.setSrc(new File(getTestData().getTestDataFileFor("tomcatcontext-war"))); expandTask.execute(); Deployable war = new DefaultDeployableFactory().createDeployable(getContainer().getId(), new File(artifactDir, "tomcat-context").getPath(), DeployableType.WAR); getLocalContainer().getConfiguration().addDeployable(war); URL warPingURL = new URL("http://localhost:" + getTestData().port + "/tomcat-context/"); getLocalContainer().start(); PingUtils.assertPingTrue("tomcat context war not started", "Test value is [test value]", warPingURL, getLogger()); getLocalContainer().stop(); PingUtils.assertPingFalse("tomcat context war not stopped", warPingURL, getLogger()); } }
/** * Start spawned container. * @throws Exception If anything goes wrong. */ public void testStartSpawned() throws Exception { Deployable war = new DefaultDeployableFactory().createDeployable(getContainer().getId(), getTestData().getTestDataFileFor("simple-war"), DeployableType.WAR); getLocalContainer().getConfiguration().addDeployable(war); URL pingURL = new URL("http://localhost:" + getTestData().port + "/simple-war/index.jsp"); getLocalContainer().start(); PingUtils.assertPingTrue(pingURL.getPath() + " not started", pingURL, getLogger()); getLocalContainer().stop(); PingUtils.assertPingFalse(pingURL.getPath() + " not stopped", pingURL, getLogger()); } }
/** * Test deployment of a WAR with root path. * @throws Exception If anything goes wrong. */ public void testDeployWarDefinedWithRootPath() throws Exception { WAR war = (WAR) new DefaultDeployableFactory().createDeployable(getContainer().getId(), getTestData().getTestDataFileFor("simple-war"), DeployableType.WAR); war.setContext("/"); getLocalContainer().getConfiguration().addDeployable(war); URL warPingURL = new URL("http://localhost:" + getTestData().port + "/index.jsp"); getLocalContainer().start(); PingUtils.assertPingTrue(warPingURL.getPath() + " not started", "Sample page for testing", warPingURL, getLogger()); getLocalContainer().stop(); PingUtils.assertPingFalse(warPingURL.getPath() + " not stopped", warPingURL, getLogger()); }
/** * Test deployment of a WAR with multi path. * @throws Exception If anything goes wrong. */ public void testDeployWarDefinedWithMultipleContextPath() throws Exception { WAR war = (WAR) new DefaultDeployableFactory().createDeployable(getContainer().getId(), getTestData().getTestDataFileFor("simple-war"), DeployableType.WAR); war.setContext("/a/b"); getLocalContainer().getConfiguration().addDeployable(war); URL warPingURL = new URL("http://localhost:" + getTestData().port + "/a/b/index.jsp"); getLocalContainer().start(); PingUtils.assertPingTrue(warPingURL.getPath() + " not started", "Sample page for testing", warPingURL, getLogger()); getLocalContainer().stop(); PingUtils.assertPingFalse(warPingURL.getPath() + " not stopped", warPingURL, getLogger()); }
/** * Start container with an empty EAR. * @throws Exception If anything goes wrong. */ public void testStartWithOneEmptyEarDeployed() throws Exception { // The Apache Geronimo server doesn't like empty EARs if (getContainer().getId().startsWith("geronimo")) { return; } Deployable ear = new DefaultDeployableFactory().createDeployable(getContainer().getId(), getTestData().getTestDataFileFor("empty-ear"), DeployableType.EAR); getLocalContainer().getConfiguration().addDeployable(ear); getLocalContainer().start(); assertEquals(State.STARTED, getContainer().getState()); getLocalContainer().stop(); assertEquals(State.STOPPED, getContainer().getState()); }
/** * Start container with an EAR containing one WAR. * @throws Exception If anything goes wrong. */ public void testStartWithOneEarWithOneWarDeployed() throws Exception { Deployable ear = new DefaultDeployableFactory().createDeployable(getContainer().getId(), getTestData().getTestDataFileFor("simple-ear"), DeployableType.EAR); getLocalContainer().getConfiguration().addDeployable(ear); URL earPingURL = new URL("http://localhost:" + getTestData().port + "/simpleweb/index.jsp"); getLocalContainer().start(); PingUtils.assertPingTrue("simple ear not started", earPingURL, getLogger()); getLocalContainer().stop(); PingUtils.assertPingFalse("simple ear not stopped", earPingURL, getLogger()); } }
/** * Tests that a servlet has access to a class in added to the extraclasspath * @throws MalformedURLException If the WAR URL cannot be built. */ public void testLoadClass() throws MalformedURLException { Deployable war = new DefaultDeployableFactory().createDeployable(getContainer().getId(), getTestData() .getTestDataFileFor("classpath-war"), DeployableType.WAR); getLocalContainer().getConfiguration().addDeployable(war); URL warPingURL = new URL("http://localhost:" + getTestData().port + "/" + "classpath-war/test"); getLocalContainer().start(); PingUtils.assertPingTrue("simple war should have been started at this point", warPingURL, getLogger()); getLocalContainer().stop(); PingUtils.assertPingFalse("simple war should have been stopped at this point", warPingURL, getLogger()); }
/** * Test static EJB deployment. * @throws Exception If anything goes wrong. */ public void testDeployEjbStatically() throws Exception { setContainer(createContainer(createConfiguration(ConfigurationType.STANDALONE))); Deployable ejb = new DefaultDeployableFactory().createDeployable(getContainer().getId(), getTestData().getTestDataFileFor("simple-ejb"), DeployableType.EJB); getLocalContainer().getConfiguration().addDeployable(ejb); getLocalContainer().start(); SampleHome home = jndiLookup("SampleEJB"); Sample sample = home.create(); assertTrue("Should have returned true", sample.isWorking()); getLocalContainer().stop(); } }