Beispiel #1
0
  private static synchronized PlexusContainer setupContainer() throws Exception {
    final File f = new File("target/plexus-home");

    if (!f.isDirectory()) {
      f.mkdirs();
    }

    File bundleRoot = new File(TestProperties.getAll().get("nexus.base.dir"));
    System.setProperty("basedir", bundleRoot.getAbsolutePath());
    System.setProperty("bundleBasedir", bundleRoot.getAbsolutePath());
    System.setProperty(
        "plexus.configuration", new File(bundleRoot, "nexus/WEB-INF/plexus.xml").getAbsolutePath());

    System.setProperty(
        "plexus.appbooter.customizers",
        "org.sonatype.nexus.NexusBooterCustomizer," + SeleniumAppBooterCustomizer.class.getName());

    File classworldsConf = new File(bundleRoot, "conf/classworlds.conf");

    if (!classworldsConf.isFile()) {
      throw new IllegalStateException(
          "The bundle classworlds.conf file is not found (\""
              + classworldsConf.getAbsolutePath()
              + "\")!");
    }

    System.setProperty("classworlds.conf", classworldsConf.getAbsolutePath());

    // this is non trivial here, since we are running Nexus in _same_ JVM as tests
    // and the PlexusAppBooterJSWListener (actually theused WrapperManager in it) enforces then
    // Nexus may be
    // started only once in same JVM!
    // So, we are _overrriding_ the in-bundle plexus app booter with the simplest one
    // since we dont need all the bells-and-whistles in Service and JSW
    // but we are still _reusing_ the whole bundle environment by tricking Classworlds Launcher

    // Launcher trick -- begin
    Launcher launcher = new Launcher();
    launcher.setSystemClassLoader(Thread.currentThread().getContextClassLoader());
    launcher.configure(
        new FileInputStream(classworldsConf)); // launcher closes stream upon configuration
    // Launcher trick -- end

    // set the preconfigured world
    final PlexusAppBooter plexusAppBooter =
        new PlexusAppBooter() {
          @Override
          protected void customizeContext(AppContext context) {
            super.customizeContext(context);

            context.put("plexus.app.booter", this);
          }
        };
    plexusAppBooter.setWorld(launcher.getWorld());

    plexusAppBooter.startContainer();

    PlexusContainer c = plexusAppBooter.getContainer();
    return c;
  }
  protected void copyTestResources() throws IOException {
    File source = new File(TestProperties.getString("test.resources.source.folder"), getTestId());
    if (!source.exists()) {
      return;
    }

    File destination = new File(TestProperties.getString("test.resources.folder"), getTestId());

    FileTestingUtils.interpolationDirectoryCopy(source, destination, TestProperties.getAll());
  }
  private PlexusContainer setupContainer(Class<?> baseClass) {
    // ----------------------------------------------------------------------------
    // Context Setup
    // ----------------------------------------------------------------------------

    Map<Object, Object> context = new HashMap<Object, Object>();

    context.put("basedir", getBasedir());
    context.putAll(TestProperties.getAll());

    boolean hasPlexusHome = context.containsKey("plexus.home");

    if (!hasPlexusHome) {
      File f = new File(getBasedir(), "target/plexus-home");

      if (!f.isDirectory()) {
        f.mkdir();
      }

      context.put("plexus.home", f.getAbsolutePath());
    }

    // ----------------------------------------------------------------------------
    // Configuration
    // ----------------------------------------------------------------------------

    ContainerConfiguration containerConfiguration =
        new DefaultContainerConfiguration()
            .setName("test")
            .setContext(context)
            .setContainerConfiguration(baseClass.getName().replace('.', '/') + ".xml");
    containerConfiguration.setClassPathScanning(true);

    customizeContainerConfiguration(containerConfiguration);

    try {
      return new DefaultPlexusContainer(containerConfiguration);
    } catch (PlexusContainerException e) {
      e.printStackTrace();
      fail("Failed to create plexus container.");
      return null;
    }
  }
Beispiel #4
0
 private Map<String, String> getTestProperties() {
   HashMap<String, String> variables = new HashMap<String, String>();
   variables.putAll(TestProperties.getAll());
   return variables;
 }