public void run() {
    status = "started";
    File mavenProject = getTestFile("pom.xml").getParentFile();

    System.setProperty("maven.home", TestProperties.getString("maven.instance"));
    Verifier verifier;
    try {
      verifier = new Verifier(mavenProject.getAbsolutePath(), false);
      status = "verifierCreated";
    } catch (VerificationException e) {
      status = "failCreation" + e.getMessage();
      return;
    }

    File mavenRepository = new File(TestProperties.getString("maven.local.repo"));
    verifier.setLocalRepo(mavenRepository.getAbsolutePath());

    verifier.resetStreams();

    List<String> options = new ArrayList<String>();
    options.add("-X");
    options.add("-Dmaven.repo.local=" + mavenRepository.getAbsolutePath());
    options.add("-s " + getOverridableFile("settings.xml"));
    verifier.setCliOptions(options);

    status = "pre-execute";
    try {
      verifier.executeGoal("dependency:resolve");
      status = "executed";
    } catch (VerificationException e) {
      status = "failExecute" + e.getMessage();
    }
  }
 @BeforeMethod
 public void cleanRepo() throws IOException {
   AbstractMavenNexusIT.cleanRepository(
       new File(TestProperties.getString("maven.local.repo")), getTestId());
   AbstractMavenNexusIT.cleanRepository(
       new File(TestProperties.getString("maven.local.repo")), "nxcm281");
 }
  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());
  }
  @Test
  @Category(PROXY.class)
  public void validUser() throws Exception {
    SocketAddress sa =
        new InetSocketAddress("127.0.0.1", TestProperties.getInteger("webproxy.server.port"));
    Proxy p = new Proxy(Proxy.Type.HTTP, sa);

    URL url = new URL("http://www.google.com/index.html");
    HttpURLConnection con = (HttpURLConnection) url.openConnection(p);

    byte[] encodedUserPwd = Base64.encodeBase64("admin:123".getBytes());
    con.setRequestProperty("Proxy-Authorization", "Basic " + new String(encodedUserPwd));
    con.getInputStream();

    for (int i = 0; i < 100; i++) {
      Thread.sleep(200);

      List<String> uris = server.getAccessedUris();
      for (String uri : uris) {
        if (uri.contains("google.com")) {
          return;
        }
      }
    }

    Assert.fail("Proxy was not able to access google.com");
  }
示例#5
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;
  }
  private void setupLog4j() throws IOException {
    File defaultLog4j = new File(TestProperties.getFile("default-configs"), "log4j.properties");
    // File confLog4j = new File( nexusWorkDir, "conf/log4j.properties" );

    updateLog4j(defaultLog4j);
    // updateLog4j( confLog4j );
  }
  @Test
  public void downloadWithPermition() throws Exception {
    AbstractMavenNexusIT.cleanRepository(
        new File(TestProperties.getString("maven.local.repo")), getTestId());

    TestContainer.getInstance().getTestContext().useAdminForRequests();
    replaceUserRole(TEST_USER_NAME, "nx-admin");

    download();
  }
  @Test(expected = IOException.class)
  @Category(PROXY.class)
  public void withoutUser() throws Exception {
    SocketAddress sa =
        new InetSocketAddress("127.0.0.1", TestProperties.getInteger("webproxy.server.port"));
    Proxy p = new Proxy(Proxy.Type.HTTP, sa);

    URL url = new URL("http://www.google.com/index.html");
    URLConnection con = url.openConnection(p);

    con.getInputStream();

    Assert.fail("Proxy was not able to access google.com");
  }
  public static File getResource(String resource) {
    log.debug("Looking for resource: " + resource);
    // URL classURL = Thread.currentThread().getContextClassLoader().getResource( resource );

    File rootDir = new File(TestProperties.getString("test.resources.folder"));
    File file = new File(rootDir, resource);

    if (!file.exists()) {
      return null;
    }

    log.debug("found: " + file);

    return file;
  }
 static {
   nexusApplicationPort = TestProperties.getInteger("nexus.application.port");
   nexusControlPort = TestProperties.getInteger("nexus.control.port");
   nexusBaseDir = TestProperties.getString("nexus.base.dir");
   nexusWorkDir = TestProperties.getString("nexus.work.dir");
   WORK_CONF_DIR = nexusWorkDir + "/conf";
   nexusLogDir = TestProperties.getString("nexus.log.dir");
   nexusBaseUrl = TestProperties.getString("nexus.base.url");
   baseNexusUrl = nexusBaseUrl;
 }
示例#11
0
  @Test(expected = IOException.class)
  @Category(PROXY.class)
  public void invalidUser() throws Exception {
    SocketAddress sa =
        new InetSocketAddress("127.0.0.1", TestProperties.getInteger("webproxy.server.port"));
    Proxy p = new Proxy(Proxy.Type.HTTP, sa);

    URL url = new URL("http://www.google.com/index.html");
    HttpURLConnection con = (HttpURLConnection) url.openConnection(p);

    byte[] encodedUserPwd = Base64.encodeBase64("admin:1234".getBytes());
    con.setRequestProperty("Proxy-Authorization", "Basic " + new String(encodedUserPwd));
    con.getInputStream();

    Assert.fail("Proxy was not able to access google.com");
  }
  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;
    }
  }
  @Override
  protected void copyTestResources() throws IOException {
    super.copyTestResources();

    String proxyRepoBaseUrl = TestProperties.getString("proxy.repo.base.url");
    Assert.assertTrue(proxyRepoBaseUrl.startsWith("http://"));

    replaceInFile(
        "target/nexus/proxy-repo/p2repowithftpmirror/artifacts.xml",
        "${proxy-repo-base-url}",
        proxyRepoBaseUrl);
    replaceInFile(
        "target/nexus/proxy-repo/p2repowithftpmirror/mirrors.xml",
        "${proxy-repo-base-url}",
        proxyRepoBaseUrl);
    replaceInFile(
        "target/nexus/proxy-repo/p2repowithftpmirror/mirrors.xml",
        "${ftp-proxy-repo-base-url}",
        "ftp" + proxyRepoBaseUrl.substring(4));
  }
  private void updateLog4j(File log4jFile) throws IOException {
    EnhancedProperties properties = new EnhancedProperties();
    if (log4jFile.exists()) {
      FileInputStream input = new FileInputStream(log4jFile);
      properties.load(input);
      IOUtil.close(input);
    }

    attachPropertiesToLog(properties);

    String newFileName = this.getTestId() + "/test-config/log4j.properties";
    File newLog4JFile = new File(TestProperties.getString("test.resources.folder"), newFileName);
    newLog4JFile.getParentFile().mkdirs();
    FileOutputStream output = new FileOutputStream(newLog4JFile);
    try {
      properties.store(output);
    } finally {
      IOUtil.close(output);
    }
  }
  private void setupMockJira() throws Exception {

    final int port = Integer.parseInt(TestProperties.getString("jira-server-port"));

    final File mockDb = getTestFile("jira-mock.db");

    StubJira mock = new StubJira();
    mock.setDatabase(Files.toString(mockDb, Charset.forName("utf-8")));

    // we have to give a real version (set in DB and here), because either nexus freaks out
    // otherwise
    MockAttachmentHandler handler = new MockAttachmentHandler();
    handler.setSupportedVersion("4.3");

    handler.setMock(mock);
    List<AttachmentHandler> handlers = Arrays.<AttachmentHandler>asList(handler);
    server = new JettyServerProvider();
    server.setPort(port);
    server.addServlet(new JiraXmlRpcTestServlet(mock, server.getUrl(), handlers));
    server.start();
  }
  @Override
  public void copyTestResources() throws IOException {
    super.copyTestResources();

    final String proxyRepoBaseUrl = TestProperties.getString("proxy.repo.base.url");

    replaceInFile(
        localStorageDir + "/meclipse0393/memberrepo1/artifacts.xml",
        "${proxy-repo-base-url}",
        proxyRepoBaseUrl);
    replaceInFile(
        localStorageDir + "/meclipse0393/memberrepo2/artifacts.xml",
        "${proxy-repo-base-url}",
        proxyRepoBaseUrl);
    replaceInFile(
        localStorageDir + "/meclipse0393/memberrepo1/mirrors.xml",
        "${proxy-repo-base-url}",
        proxyRepoBaseUrl);
    replaceInFile(
        localStorageDir + "/meclipse0393/memberrepo2/mirrors.xml",
        "${proxy-repo-base-url}",
        proxyRepoBaseUrl);
  }
示例#17
0
  @Test
  @Category(PROXY.class)
  public void checkWebProxy() throws Exception {
    SocketAddress sa =
        new InetSocketAddress("127.0.0.1", TestProperties.getInteger("webproxy.server.port"));
    Proxy p = new Proxy(Proxy.Type.HTTP, sa);

    URL url = new URL("http://www.google.com/index.html");
    URLConnection conn = url.openConnection(p);
    conn.getInputStream();

    for (int i = 0; i < 100; i++) {
      Thread.sleep(200);

      List<String> uris = server.getAccessedUris();
      for (String uri : uris) {
        if (uri.contains("google.com")) {
          return;
        }
      }
    }

    Assert.fail("Proxy was not able to access google.com");
  }
 private String createUrl(String targetRepoId) {
   return "http:////localhost:"
       + TestProperties.getString("nexus.application.port")
       + "/nexus/content/repositories/"
       + targetRepoId;
 }
示例#19
0
 private Map<String, String> getTestProperties() {
   HashMap<String, String> variables = new HashMap<String, String>();
   variables.putAll(TestProperties.getAll());
   return variables;
 }