/**
   * Test bundle deployment.
   *
   * @throws Exception If anything goes wrong.
   */
  public void testStartWithBundleDeployed() throws Exception {
    BufferedReader reader;
    File bundleOutput;
    if (getContainer().getId().startsWith("glassfish")) {
      // In GlassFish, the server runs in the domain's "config" directory
      LocalConfiguration configuration = getLocalContainer().getConfiguration();
      bundleOutput =
          new File(
              configuration.getHome()
                  + "/"
                  + configuration.getPropertyValue(GlassFishPropertySet.DOMAIN_NAME)
                  + "/config",
              "bundle-output.txt");
    } else {
      bundleOutput =
          new File(getLocalContainer().getConfiguration().getHome(), "bundle-output.txt");
    }
    assertFalse(bundleOutput + " already exists!", bundleOutput.isFile());

    Deployable bundle =
        new DefaultDeployableFactory()
            .createDeployable(
                getContainer().getId(),
                getTestData().getTestDataFileFor("simple-bundle"),
                DeployableType.BUNDLE);

    getLocalContainer().getConfiguration().addDeployable(bundle);

    getLocalContainer().start();
    assertEquals(State.STARTED, getContainer().getState());
    final long timeout = System.currentTimeMillis() + 30 * 1000;
    while (!bundleOutput.isFile() && System.currentTimeMillis() < timeout) {
      // Wait up to timeout while the bundle output is not here
      Thread.sleep(1000);
    }
    assertTrue(bundleOutput + " does not exist!", bundleOutput.isFile());
    reader = new BufferedReader(new FileReader(bundleOutput));
    assertEquals("Hello, World", reader.readLine());
    reader.close();
    reader = null;
    System.gc();

    if (getContainer().getId().startsWith("geronimo")) {
      Deployer deployer = createDeployer(getContainer());
      deployer.undeploy(bundle);
    }

    getLocalContainer().stop();
    assertEquals(State.STOPPED, getContainer().getState());
    reader = new BufferedReader(new FileReader(bundleOutput));
    assertEquals("Goodbye, World", reader.readLine());
    reader.close();
    reader = null;
    System.gc();
  }
  /**
   * {@inheritDoc}
   *
   * @see junit.framework.TestCase#setUp()
   */
  protected void setUp() throws Exception {
    super.setUp();

    this.fsManager = new StandardFileSystemManager();
    this.fsManager.init();
    this.fileHandler = new VFSFileHandler(this.fsManager);

    LocalConfiguration configuration = new JBossStandaloneLocalConfiguration(CONFIGURATION_HOME);
    configuration.setProperty(JBossPropertySet.CONFIGURATION, SERVER_CONFIG);

    this.container = new JBoss4xInstalledLocalContainer(configuration);
    this.container.setHome(CONTAINER_HOME);
  }
 /**
  * If the project's packaging is war, ear or ejb and there is no deployer specified and the user
  * has not defined the auto-deployable inside the <code>&lt;deployables&gt;</code> element, then
  * add the generated artifact to the list of deployables to deploy statically.
  *
  * <p>Note that the reason we check that a deployer element has not been specified is because if
  * it has then the auto deployable will be deployed by the specified deployer.
  *
  * @param container the local container to which to add the project's artifact
  * @throws MojoExecutionException if an error occurs
  */
 protected void addAutoDeployDeployable(LocalContainer container) throws MojoExecutionException {
   if ((getDeployerElement() == null)
       && (getCargoProject().getPackaging() != null)
       && getCargoProject().isJ2EEPackaging()) {
     // Has the auto-deployable already been specified as part of the <deployables> config
     // element?
     if ((getConfigurationElement() == null)
         || (getConfigurationElement().getDeployables() == null)
         || !containsAutoDeployable(getConfigurationElement().getDeployables())) {
       LocalConfiguration configuration = container.getConfiguration();
       configuration.addDeployable(createAutoDeployDeployable(container));
     }
   }
 }