public void createSnapshotRepo(String repoId) throws IOException {
    RepositoryResource repo = new RepositoryResource();
    repo.setProvider("ivy");
    repo.setFormat("maven2");
    repo.setRepoPolicy("snapshot");
    repo.setChecksumPolicy("ignore");
    repo.setBrowseable(false);

    repo.setId(repoId);
    repo.setName(repoId);
    repo.setRepoType("hosted");
    repo.setWritePolicy(RepositoryWritePolicy.ALLOW_WRITE.name());
    repo.setDownloadRemoteIndexes(true);
    repo.setBrowseable(true);
    repo.setRepoPolicy(RepositoryPolicy.SNAPSHOT.name());
    repo.setChecksumPolicy(ChecksumPolicy.IGNORE.name());

    repo.setIndexable(true); // being sure!!!

    repoUtil.createRepository(repo);

    repo = (RepositoryResource) repoUtil.getRepository(repoId);

    // assert that the repository is created
    Assert.assertTrue(repo.isIndexable());
  }
コード例 #2
0
  @Test
  public void changeProxyStatusTest() throws Exception {
    // change the name of the test repo
    RepositoryMessageUtil repoUtil =
        new RepositoryMessageUtil(
            this.getXMLXStream(), MediaType.APPLICATION_XML, getRepositoryTypeRegistry());

    RepositoryStatusResource repo = repoUtil.getStatus("release-proxy-repo-1");
    repo.setProxyMode(ProxyMode.BLOCKED_AUTO.name());
    repoUtil.updateStatus(repo);

    TaskScheduleUtil.waitForAllTasksToStop();

    SyndFeed systemFeed = FeedUtil.getFeed("systemChanges");
    this.validateLinksInFeeds(systemFeed);

    SyndFeed systemStatusFeed = FeedUtil.getFeed("systemRepositoryStatusChanges");
    this.validateLinksInFeeds(systemStatusFeed);

    Assert.assertTrue(
        findFeedEntry(
            systemFeed, "Repository proxy mode change", new String[] {"release-proxy-repo-1"}));

    Assert.assertTrue(
        findFeedEntry(
            systemStatusFeed,
            "Repository proxy mode change",
            new String[] {"release-proxy-repo-1"}));
  }
  @Test
  public void validateP2ProxyMaxAgeConfig() throws Exception {
    RepositoryProxyResource p2repo = new RepositoryProxyResource();

    p2repo.setRepoType("proxy");
    p2repo.setId("p2proxy");
    p2repo.setName("p2proxy");
    p2repo.setBrowseable(true);
    p2repo.setIndexable(false);
    p2repo.setNotFoundCacheTTL(1440);
    p2repo.setArtifactMaxAge(100);
    p2repo.setMetadataMaxAge(200);
    p2repo.setRepoPolicy("RELEASE");
    p2repo.setProvider("p2");
    p2repo.setProviderRole("org.sonatype.nexus.proxy.repository.Repository");
    p2repo.setOverrideLocalStorageUrl(null);
    p2repo.setDefaultLocalStorageUrl(null);
    p2repo.setDownloadRemoteIndexes(false);
    p2repo.setExposed(true);
    p2repo.setChecksumPolicy("WARN");

    final RepositoryResourceRemoteStorage p2proxyRemoteStorage =
        new RepositoryResourceRemoteStorage();
    p2proxyRemoteStorage.setRemoteStorageUrl("http://p2proxy");
    p2proxyRemoteStorage.setAuthentication(null);
    p2proxyRemoteStorage.setConnectionSettings(null);
    p2proxyRemoteStorage.setHttpProxySettings(null);

    p2repo.setRemoteStorage(p2proxyRemoteStorage);

    p2repo = (RepositoryProxyResource) repoUtil.createRepository(p2repo, false);

    p2repo = (RepositoryProxyResource) repoUtil.getRepository(p2repo.getId());

    assertThat(p2repo.getArtifactMaxAge(), is(100));
    assertThat(p2repo.getMetadataMaxAge(), is(200));

    // now do an update
    p2repo.setArtifactMaxAge(300);
    p2repo.setMetadataMaxAge(400);

    repoUtil.updateRepo(p2repo, false);

    p2repo = (RepositoryProxyResource) repoUtil.getRepository(p2repo.getId());

    assertThat(p2repo.getArtifactMaxAge(), is(300));
    assertThat(p2repo.getMetadataMaxAge(), is(400));
  }
  @Test
  public void hostedTestRelRepoAndDeployFile() throws IOException, Exception {
    // create a release repository
    String repoId = "tmp-releases";
    RepositoryResource repo = new RepositoryResource();
    repo.setProvider("ivy");
    repo.setFormat("maven2");
    repo.setRepoPolicy("release");
    repo.setChecksumPolicy("ignore");
    repo.setBrowseable(false);

    repo.setId(repoId);
    repo.setName(repoId);
    repo.setRepoType("hosted");
    repo.setWritePolicy(RepositoryWritePolicy.ALLOW_WRITE.name());
    repo.setDownloadRemoteIndexes(true);
    repo.setBrowseable(true);
    repo.setRepoPolicy(RepositoryPolicy.RELEASE.name());
    repo.setChecksumPolicy(ChecksumPolicy.IGNORE.name());

    repo.setIndexable(true); // being sure!!!
    repoUtil.createRepository(repo);

    // firstly assert that repository is there
    repo = (RepositoryResource) repoUtil.getRepository(repoId);
    Assert.assertTrue(repo.isIndexable());

    TaskScheduleUtil.waitForAllTasksToStop();

    // then deploy a release artifact
    Gav gav = GavUtil.newGav("ivyRemover", "auth-mod", "1.0");
    getDeployUtils().deployUsingGavWithRest(repoId, gav, getTestFile("simple-artifact.jar"));

    TaskScheduleUtil.waitForAllTasksToStop();
    getEventInspectorsUtil().waitForCalmPeriod();

    // secondly assert that the artifact is in the release repository
    List<NexusArtifact> result = getSearchMessageUtil().searchForGav(gav, repoId);
    Assert.assertEquals(
        result.size(), 1, "Results: \n" + XStreamFactory.getXmlXStream().toXML(result));

    // thirdly assert that there is at least alltogether one release artifact in the release
    // repository
    result = getSearchMessageUtil().searchFor(Collections.singletonMap("q", "ivyRemover"), repoId);
    Assert.assertEquals(
        result.size(), 1, "Results: \n" + XStreamFactory.getXmlXStream().toXML(result));
  }
 protected void createRepository(final String repoId) throws IOException {
   RepositoryResource repo = new RepositoryResource();
   repo.setId(repoId);
   repo.setRepoType("hosted");
   repo.setName(repoId);
   repo.setProvider("maven2");
   repo.setFormat("maven2");
   repo.setRepoPolicy(RepositoryPolicy.RELEASE.name());
   repoUtil.createRepository(repo, false);
 }
コード例 #6
0
  @Before
  public void deploySnapshotArtifacts() throws Exception {
    initFolders();

    File oldSnapshot = getTestFile("repo");

    // Copying to keep an old timestamp
    FileUtils.copyDirectory(oldSnapshot, repositoryPath);

    RepositoryMessageUtil.updateIndexes("nexus-test-harness-snapshot-repo");
  }
コード例 #7
0
  @Test
  public void updateRepoTest() throws Exception {
    // change the name of the test repo
    RepositoryMessageUtil repoUtil =
        new RepositoryMessageUtil(
            this.getXMLXStream(), MediaType.APPLICATION_XML, getRepositoryTypeRegistry());

    RepositoryBaseResource repo = repoUtil.getRepository(this.getTestRepositoryId());
    String oldName = repo.getName();
    String newName = repo.getName() + "-new";
    repo.setName(newName);
    repoUtil.updateRepo(repo);

    TaskScheduleUtil.waitForAllTasksToStop();

    final SyndFeed feed = FeedUtil.getFeed("systemChanges");
    this.validateLinksInFeeds(feed);
    Assert.assertTrue(
        "Update repo feed not found\r\n\r\n" + feed,
        findFeedEntry(feed, "Configuration change", new String[] {newName, oldName}));
  }
コード例 #8
0
  @Test
  public void testIndexTree() throws Exception {
    String repoId = this.getTestRepositoryId();

    // get the index tree
    Response response =
        RequestFacade.doGetRequest(
            RequestFacade.SERVICE_LOCAL + "repositories/" + repoId + "/index_content/");
    Assert.assertEquals(200, response.getStatus().getCode());

    RepositoryMessageUtil repoUtil =
        new RepositoryMessageUtil(this, this.getXMLXStream(), MediaType.APPLICATION_XML);

    RepositoryResource resource = (RepositoryResource) repoUtil.getRepository(repoId);
    resource.setIndexable(false);
    repoUtil.updateRepo(resource);

    // get the index tree
    response =
        RequestFacade.doGetRequest(
            RequestFacade.SERVICE_LOCAL + "repositories/" + repoId + "/index_content/");
    Assert.assertEquals(404, response.getStatus().getCode());
  }
コード例 #9
0
  /**
   * When one of member repositories is blocked the group repository should not fail and just use
   * the valid repositories.
   *
   * @throws Exception not expected
   */
  @Test
  public void blocked() throws Exception {
    repositoryMessageUtil.setBlockProxy("nxcm3339-2", true);

    final File installDir = new File("target/eclipse/nxcm3339");

    installUsingP2(
        getGroupUrl(getTestRepositoryId()),
        "com.sonatype.nexus.p2.its.feature.feature.group",
        installDir.getCanonicalPath());

    final File feature = new File(installDir, "features/com.sonatype.nexus.p2.its.feature_1.0.0");
    assertThat(feature, exists());
    assertThat(feature, isDirectory());
  }
  @Test
  public void testSnapRepoDeployFilesRunTaskDeleteIFRelease() throws IOException, Exception {

    // create a snapshot repository
    createSnapshotRepo(snapRepoId);

    // add some artifacts
    copyToSnapRepo(snapRepoId);

    TaskScheduleUtil.waitForAllTasksToStop();

    // update indexes for search
    RepositoryMessageUtil.updateIndexes(snapRepoId);

    TaskScheduleUtil.waitForAllTasksToStop();

    // set Remover task parameters 2 latest version snapshots should be left over
    ScheduledServicePropertyResource keepSnapshotsProp = new ScheduledServicePropertyResource();
    keepSnapshotsProp.setKey(IVYSnapshotRemovalTaskDescriptor.MIN_TO_KEEP_FIELD_ID);
    keepSnapshotsProp.setValue(String.valueOf(2));

    ScheduledServicePropertyResource ageProp = new ScheduledServicePropertyResource();
    ageProp.setKey(IVYSnapshotRemovalTaskDescriptor.KEEP_DAYS_FIELD_ID);
    ageProp.setValue(String.valueOf(0));

    // and if a release version exists it should be removed too
    ScheduledServicePropertyResource relProp = new ScheduledServicePropertyResource();
    relProp.setKey(IVYSnapshotRemovalTaskDescriptor.REMOVE_WHEN_RELEASED_FIELD_ID);
    relProp.setValue(Boolean.toString(true));

    ScheduledServicePropertyResource repos = new ScheduledServicePropertyResource();
    repos.setKey("IvyRepositoryId");
    repos.setValue(snapRepoId);
    TaskScheduleUtil.runTask(
        "IvySnapshotRemoval",
        IVYSnapshotRemovalTaskDescriptor.ID,
        repos,
        keepSnapshotsProp,
        ageProp,
        relProp);

    TaskScheduleUtil.waitForAllTasksToStop();
    getEventInspectorsUtil().waitForCalmPeriod();

    // firstly assert that there is the artifact "auth-api" version "0.8-102" left over with
    // ".source.jar" and ".jar"
    Gav gav = GavUtil.newGav("ivyRemover", "auth-api", "0.8-102");

    List<NexusArtifact> result = getSearchMessageUtil().searchForGav(gav, snapRepoId);

    Assert.assertEquals(
        result.size(), 2, "Results: \n" + XStreamFactory.getXmlXStream().toXML(result));

    // secondly assert that there is the artifact "auth-api" version "0.8-103" left over with
    // ".source.jar" and ".jar"
    gav = GavUtil.newGav("ivyRemover", "auth-api", "0.8-103");

    result = getSearchMessageUtil().searchForGav(gav, snapRepoId);
    Assert.assertEquals(
        result.size(), 2, "Results: \n" + XStreamFactory.getXmlXStream().toXML(result));

    // thirdly assert that there isn't the artifact "auth-mod" version "0.8-102" left over
    gav = GavUtil.newGav("ivyRemover", "auth-mod", "1.0-102");

    result = getSearchMessageUtil().searchForGav(gav, snapRepoId);
    Assert.assertEquals(
        result.size(), 0, "Results: \n" + XStreamFactory.getXmlXStream().toXML(result));

    // fourthly assert that there isn't the artifact "auth-api" version "0.8-103" left over
    gav = GavUtil.newGav("ivyRemover", "auth-mod", "1.0-103");

    result = getSearchMessageUtil().searchForGav(gav, snapRepoId);
    Assert.assertEquals(
        result.size(), 0, "Results: \n" + XStreamFactory.getXmlXStream().toXML(result));

    // fifthly assert that there are at least 2 of 8 snapshots with 2 jar files in the whole test
    // group, 6 removed
    result =
        getSearchMessageUtil().searchFor(Collections.singletonMap("q", "ivyRemover"), snapRepoId);
    Assert.assertEquals(
        result.size(), 4, "Results: \n" + XStreamFactory.getXmlXStream().toXML(result));
  }
 protected void deleteRepository(final String repoId) throws IOException {
   repoUtil.sendMessage(Method.DELETE, null, repoId);
 }