@Test
  public void testBad2() throws Exception {
    // get start with the default config
    this.copyDefaultConfigToPlace();
    this.copyResource("/META-INF/nexus/default-oss-nexus.xml", getNexusConfiguration());
    Configuration config = this.loadNexusConfig(new File(this.getNexusConfiguration()));

    // make it bad

    // invalid policy
    CRepository invalidPolicyRepo = config.getRepositories().get(0);
    Xpp3Dom externalConfig = (Xpp3Dom) invalidPolicyRepo.getExternalConfiguration();
    ExternalConfigUtil.setNodeValue(externalConfig, "repositoryPolicy", "badPolicy");

    // duplicate the repository id
    for (CRepository repo : config.getRepositories()) {
      if (!repo.getId().equals("central")) {
        // duplicate
        repo.setId("central");
        break;
      }
    }

    // TODO: add more errors here

    // now validate it
    ValidationResponse response = underTest.validateModel(new ValidationRequest(config));

    assertThat(response.isValid(), is(false));
    assertThat(response.isModified(), is(false));

    assertThat(response.getValidationErrors(), hasSize(greaterThan(0)));
    assertThat(response.getValidationWarnings(), hasSize(0));
  }
コード例 #2
0
  public void testFrom103_1() throws Exception {
    TimeZone defaultTZ = TimeZone.getDefault();

    // use UTC for this test
    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

    copyFromClasspathToFile(
        "/org/sonatype/nexus/configuration/upgrade/103-1/nexus-103.xml", getNexusConfiguration());

    // trick: copying by nexus.xml the tasks.xml too
    copyFromClasspathToFile(
        "/org/sonatype/nexus/configuration/upgrade/103-1/tasks.xml",
        new File(new File(getNexusConfiguration()).getParentFile(), "tasks.xml"));

    Configuration configuration =
        configurationUpgrader.loadOldConfiguration(new File(getNexusConfiguration()));

    // set back to the default timezone
    TimeZone.setDefault(defaultTZ);

    assertEquals(Configuration.MODEL_VERSION, configuration.getVersion());

    // 6 repos 3 groups
    assertEquals(6 + 3, configuration.getRepositories().size());

    assertEquals(2, configuration.getRepositoryGrouping().getPathMappings().size());

    resultIsFine("/org/sonatype/nexus/configuration/upgrade/103-1/nexus-103.xml", configuration);
    securityResultIsFine(
        "/org/sonatype/nexus/configuration/upgrade/103-1/security-configuration-103.xml");
  }
コード例 #3
0
  public void testFromDECInt() throws Exception {
    copyFromClasspathToFile(
        "/org/sonatype/nexus/configuration/upgrade/nexus-001-3.xml", getNexusConfiguration());

    Configuration configuration =
        configurationUpgrader.loadOldConfiguration(new File(getNexusConfiguration()));

    assertEquals(Configuration.MODEL_VERSION, configuration.getVersion());

    assertEquals(7 + 2, configuration.getRepositories().size());

    assertEquals(2, configuration.getRepositoryGrouping().getPathMappings().size());

    resultIsFine("/org/sonatype/nexus/configuration/upgrade/nexus-001-3.xml", configuration);
    securityResultIsFine(
        "/org/sonatype/nexus/configuration/upgrade/security-configuration-001-3.xml");
  }
コード例 #4
0
  public void testNEXUS2212SaveInvalidConfig() throws Exception {
    Configuration nexusConfig = nexusConfiguration.getConfigurationModel();

    CRepository centralCRepo = null;

    for (CRepository cRepo : nexusConfig.getRepositories()) {
      if (cRepo.getId().equals("central")) {
        centralCRepo = cRepo;
        break;
      }
    }

    assertNotNull(centralCRepo);

    centralCRepo.setLocalStatus(LocalStatus.OUT_OF_SERVICE.name());
    nexusConfiguration.saveConfiguration();
  }
コード例 #5
0
  public void testFrom103_2() throws Exception {
    // same as above, but we have no tasks.xml
    copyFromClasspathToFile(
        "/org/sonatype/nexus/configuration/upgrade/103-2/nexus-103.xml", getNexusConfiguration());

    Configuration configuration =
        configurationUpgrader.loadOldConfiguration(new File(getNexusConfiguration()));

    assertEquals(Configuration.MODEL_VERSION, configuration.getVersion());

    // 6 repos, 1 shadow, 2 groups
    assertEquals(6 + 1 + 2, configuration.getRepositories().size());

    assertEquals(2, configuration.getRepositoryGrouping().getPathMappings().size());

    resultIsFine("/org/sonatype/nexus/configuration/upgrade/103-2/nexus-103.xml", configuration);
    securityResultIsFine(
        "/org/sonatype/nexus/configuration/upgrade/103-2/security-configuration-103.xml");
  }
  @Test
  public void testBad1() throws Exception {
    // get start with the default config
    this.copyDefaultConfigToPlace();
    Configuration config = this.loadNexusConfig(new File(this.getNexusConfiguration()));

    // make it bad

    // remove the name from a repository
    CRepository missingNameRepo = (CRepository) config.getRepositories().get(0);
    missingNameRepo.setName(null);

    // TDOD add 2 more warnings

    // wrong shadow type
    CRepository badShadow = new DefaultCRepository();
    badShadow.setId("badShadow");
    badShadow.setName("Does not follow");
    badShadow.setProviderRole(ShadowRepository.class.getName());
    badShadow.setProviderHint("m2-m1-shadow");
    // Manipulate the dom
    Xpp3Dom externalConfig = new Xpp3Dom("externalConfiguration");
    badShadow.setExternalConfiguration(externalConfig);
    ExternalConfigUtil.setNodeValue(externalConfig, "masterRepositoryId", "non-existent");
    config.addRepository(badShadow);

    // now validate it
    ValidationResponse response = underTest.validateModel(new ValidationRequest(config));

    assertThat(response.getValidationWarnings(), hasSize(1));
    assertThat(response.getValidationErrors(), hasSize(0));

    // codehaus-snapshots has no name, it will be defaulted
    assertThat(response.isModified(), is(true));

    assertThat(response.isValid(), is(true));
  }