@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)); }
@Test public void repoEmptyId() { ApplicationValidationContext ctx = new ApplicationValidationContext(); CRepository repo = new CRepository(); repo.setLocalStatus(LocalStatus.IN_SERVICE.toString()); repo.setName("name"); ValidationResponse response = underTest.validateRepository(ctx, repo); assertThat(response.isValid(), is(false)); assertThat(response.isModified(), is(false)); assertThat(response.getValidationErrors(), hasSize(1)); assertThat(response.getValidationWarnings(), hasSize(0)); assertThat(response.getValidationErrors().get(0), hasKey("id")); }
@Test public void testNexus1710Good() throws Exception { // this is after fix: groupId is appended by "-group" to resolve clash ValidationResponse response = underTest.validateModel( new ValidationRequest( getConfigurationFromStream( getClass() .getResourceAsStream( "/org/sonatype/nexus/configuration/upgrade/nexus1710/nexus.xml.result")))); assertThat(response.isValid(), is(true)); assertThat(response.isModified(), is(false)); assertThat(response.getValidationErrors(), hasSize(0)); assertThat(response.getValidationWarnings(), hasSize(0)); }
@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)); }
@Test public void testNexus1710Bad() throws Exception { // this one is easy because you can compare: // /org/sonatype/nexus/configuration/upgrade/nexus1710/nexus.xml.result-bad // with // /org/sonatype/nexus/configuration/upgrade/nexus1710/nexus.xml.result // and you have the diff, and you already have to manually update the good one. // this was before fix: groupId/repoId name clash ValidationResponse response = underTest.validateModel( new ValidationRequest( getConfigurationFromStream( getClass() .getResourceAsStream( "/org/sonatype/nexus/configuration/upgrade/nexus1710/nexus.xml.result-bad")))); assertThat(response.isValid(), is(false)); assertThat(response.isModified(), is(false)); assertThat(response.getValidationErrors(), hasSize(1)); assertThat(response.getValidationWarnings(), hasSize(0)); }