@Test
  public void deploySameFileMultipleTimesTest() throws Exception {
    // file to deploy
    File fileToDeploy = this.getTestFile("deploySameFileMultipleTimesTest.xml");

    String deployPath =
        "org/sonatype/nexus-integration-tests/multiple-deploy-test/deploySameFileMultipleTimesTest/1/deploySameFileMultipleTimesTest-1.xml";

    // deploy it
    getDeployUtils().deployWithWagon("http", this.getNexusTestRepoUrl(), fileToDeploy, deployPath);

    // deploy it
    getDeployUtils().deployWithWagon("http", this.getNexusTestRepoUrl(), fileToDeploy, deployPath);
    // deploy it
    getDeployUtils().deployWithWagon("http", this.getNexusTestRepoUrl(), fileToDeploy, deployPath);

    // download it
    File artifact =
        downloadArtifact(
            "org.sonatype.nexus-integration-tests.multiple-deploy-test",
            "deploySameFileMultipleTimesTest",
            "1",
            "xml",
            null,
            "./target/downloaded-jars");

    // make sure its here
    assertTrue(artifact.exists());

    // make sure it is what we expect.
    assertTrue(FileTestingUtils.compareFileSHA1s(fileToDeploy, artifact));
  }
  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());
  }
  protected void copyConfigFile(
      String configFile, String destShortName, Map<String, String> variables, String path)
      throws IOException {
    // the test can override the test config.
    File testConfigFile = this.getOverridableFile(configFile);

    File parent = new File(path);
    if (!parent.isAbsolute()) {
      parent = new File(nexusBaseDir, path == null ? RELATIVE_CONF_DIR : path);
    }

    File destFile = new File(parent, destShortName);
    log.debug("copying " + configFile + " to:  " + destFile);

    FileTestingUtils.interpolationFileCopy(testConfigFile, destFile, variables);
  }
  /**
   * 3. download from mirror fails, retry fails, download succeeds from repository the mirror should
   * be blacklisted
   */
  @Test
  public void downloadFromMirrorTest() throws Exception {
    File content = getTestFile("basic");

    server.addServer("repository", content);
    List<String> mirror1Urls = server.addServer("mirror1", HttpServletResponse.SC_REQUEST_TIMEOUT);
    List<String> mirror2Urls = server.addServer("mirror2", HttpServletResponse.SC_NOT_FOUND);

    server.start();

    Gav gav =
        new Gav(
            "nexus1329",
            "sample",
            "1.0.0",
            null,
            "xml",
            null,
            null,
            null,
            false,
            null,
            false,
            null);

    File artifactFile =
        this.downloadArtifactFromRepository(REPO, gav, "./target/downloads/nexus1329");

    File originalFile = this.getTestFile("basic/nexus1329/sample/1.0.0/sample-1.0.0.xml");
    Assert.assertTrue(FileTestingUtils.compareFileSHA1s(originalFile, artifactFile));

    Assert.assertFalse("Nexus should access first mirror " + mirror1Urls, mirror1Urls.isEmpty());
    Assert.assertEquals("Nexus should retry mirror " + mirror1Urls, mirror1Urls.size(), 3);
    Assert.assertTrue(
        "Nexus should not access second mirror " + mirror2Urls, mirror2Urls.isEmpty());

    MirrorStatusResourceListResponse response = this.messageUtil.getMirrorsStatus(REPO);

    MirrorStatusResource one = (MirrorStatusResource) response.getData().get(0);

    Assert.assertEquals(one.getUrl(), "http://localhost:" + webProxyPort + "/mirror1");
    Assert.assertEquals(one.getStatus(), "Blacklisted");
  }
Ejemplo n.º 5
0
  /** 2. download from mirror fails. download from mirror retry succeeds. no repository access */
  @Test
  public void downloadFileThatIsOnlyInMirrorTest() throws Exception {
    File content = getTestFile("basic");

    List<String> repoUrls = server.addServer("repository", 500);
    List<String> mirror1Urls =
        server.addServer("mirror1", 1, HttpServletResponse.SC_REQUEST_TIMEOUT, content);
    List<String> mirror2Urls = server.addServer("mirror2", 500);

    server.start();

    Gav gav =
        new Gav(
            "nexus1329",
            "sample",
            "1.0.0",
            null,
            "xml",
            null,
            null,
            null,
            false,
            false,
            null,
            false,
            null);

    File artifactFile =
        this.downloadArtifactFromRepository(REPO, gav, "./target/downloads/nexus1329");

    File originalFile = this.getTestFile("basic/nexus1329/sample/1.0.0/sample-1.0.0.xml");
    Assert.assertTrue(FileTestingUtils.compareFileSHA1s(originalFile, artifactFile));

    Assert.assertTrue(
        repoUrls.isEmpty(), "Nexus should not access repository canonical url " + repoUrls);
    Assert.assertTrue(
        mirror2Urls.isEmpty(), "Nexus should not access second mirror " + mirror2Urls);
    Assert.assertFalse(mirror1Urls.isEmpty(), "Nexus should access first mirror " + mirror1Urls);
    Assert.assertEquals(mirror1Urls.size(), 2, "Nexus should retry first mirror " + mirror1Urls);
  }
  /** Nexus should try only the first mirror server */
  @Test
  public void checkSingleMirror() throws Exception {
    beforeCheck();

    File content = getTestFile("basic");

    server.addServer("repository", content);
    List<String> mirror1Urls = server.addServer("mirror1", HttpServletResponse.SC_NOT_FOUND);
    List<String> mirror2Urls = server.addServer("mirror2", HttpServletResponse.SC_NOT_FOUND);

    server.start();

    Gav gav =
        new Gav(
            "nexus1329",
            "sample",
            "1.0.0",
            null,
            "xml",
            null,
            null,
            null,
            false,
            null,
            false,
            null);

    File artifactFile =
        this.downloadArtifactFromRepository(REPO, gav, "./target/downloads/nexus1329");

    File originalFile = this.getTestFile("basic/nexus1329/sample/1.0.0/sample-1.0.0.xml");
    Assert.assertTrue(FileTestingUtils.compareFileSHA1s(originalFile, artifactFile));

    Assert.assertTrue(mirror1Urls.size() > 0, "Nexus should access first mirror " + mirror1Urls);
    Assert.assertTrue(
        mirror2Urls.isEmpty(), "Nexus should not access second mirror " + mirror2Urls);
  }