/** * Wait indefinitely till the container is stopped. * * @param container the local container */ public static void waitTillContainerIsStopped(Container container) { while (container.getState() == State.STARTED) { try { Thread.sleep(SLEEP); } catch (InterruptedException e) { throw new CargoException("Aborting container wait.", e); } } } }
assertEquals(State.STARTED, getContainer().getState()); final long timeout = System.currentTimeMillis() + 30 * 1000; while (!bundleOutput.isFile() && System.currentTimeMillis() < timeout) assertEquals(State.STOPPED, getContainer().getState()); reader = new BufferedReader(new FileReader(bundleOutput)); assertEquals("Goodbye, World", reader.readLine());
/** * Test whether setting system properties is working properly. * @throws Exception If anything goes wrong. */ public void testSystemProperty() throws Exception { String random = UUID.randomUUID().toString(); // Copies the testdata artifact File artifactDir = new File(getTestData().targetDir).getParentFile(); File artifactFile = new File(artifactDir, "systemproperty.war").getAbsoluteFile(); Copy copyTask = (Copy) new AntUtils().createProject().createTask("copy"); copyTask.setTofile(artifactFile); copyTask.setFile(new File(getTestData().getTestDataFileFor("systemproperty-war"))); copyTask.execute(); Deployable war = new DefaultDeployableFactory().createDeployable(getContainer().getId(), artifactFile.getAbsolutePath(), DeployableType.WAR); getLocalContainer().getConfiguration().addDeployable(war); URL pingURL = new URL("http://localhost:" + getTestData().port + "/systemproperty/test?systemPropertyName=random"); getInstalledLocalContainer().getSystemProperties().put("random", random); getLocalContainer().start(); assertEquals(State.STARTED, getContainer().getState()); PingUtils.assertPingTrue(pingURL.getPath() + " not started", random, pingURL, getLogger()); getLocalContainer().stop(); assertEquals(State.STOPPED, getContainer().getState()); PingUtils.assertPingFalse(pingURL.getPath() + " not stopped", pingURL, getLogger()); }
/** * Test static AOP deployment. * @throws Exception If anything goes wrong. */ public void testDeployAopStatically() throws Exception { Deployable aop = new DefaultDeployableFactory().createDeployable(getContainer().getId(), getTestData() .getTestDataFileFor("simple-aop"), DeployableType.AOP); getLocalContainer().getConfiguration().addDeployable(aop); getLocalContainer().start(); assertEquals(State.STARTED, getContainer().getState()); // We're verifying that the AOP is successfully deployed by querying for the defined // pointcut name via jmx MBeanServerConnection server = createMBeanServerConnection(); ObjectName objectName = ObjectName.getInstance(JBOSSAOP_ASPECTMANAGER_OBJECT_NAME); String pointcuts = (String) server.invoke(objectName, "pointcuts", new Object[] {}, new String[] {}); getLogger().debug("Registered aop pointcuts: " + pointcuts.toString(), this.getClass().getName()); assertTrue("Dummy cargo aop pointcut not found", pointcuts.contains("cargoTestDataSimpleAop")); getLocalContainer().stop(); } }
/** * 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()); }
/** * 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()); }
/** * Test HAR deployment. * @throws Exception If anything goes wrong. */ public void testDeployHarStatically() throws Exception { Deployable har = new DefaultDeployableFactory().createDeployable(getContainer().getId(), getTestData() .getTestDataFileFor("simple-har"), DeployableType.HAR); getLocalContainer().getConfiguration().addDeployable(har); getLocalContainer().start(); assertEquals(State.STARTED, getContainer().getState()); // We're verifying that the HAR is successfully deployed by querying it via jmx MBeanServerConnection server = createMBeanServerConnection(); ObjectName objectName = ObjectName.getInstance(SIMPLE_HAR_OBJECT_NAME); // getMBeanInfo will throw exception if not found MBeanInfo mbeanInfo = server.getMBeanInfo(objectName); getLogger().debug("The HAR MBean found: " + mbeanInfo.getDescription(), this.getClass().getName()); assertNotNull("MBean description is null", mbeanInfo.getDescription()); getLocalContainer().stop(); } }