Skip to content

Commit

Permalink
Fix UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed May 29, 2024
1 parent 3bb1b85 commit eb4a75b
Showing 1 changed file with 74 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ private SimpleProblemCollector validate(String pom) throws Exception {
return validateEffective(pom, UnaryOperator.identity());
}

private SimpleProblemCollector validate(String pom, int level) throws Exception {
return validateEffective(pom, mbr -> mbr.setValidationLevel(level));
}

private SimpleProblemCollector validateRaw(String pom) throws Exception {
return validateRaw(pom, UnaryOperator.identity());
}
Expand Down Expand Up @@ -408,7 +412,7 @@ public void testIncompleteParent() throws Exception {
}

public void testHardCodedSystemPath() throws Exception {
SimpleProblemCollector result = validateRaw("hard-coded-system-path.xml");
SimpleProblemCollector result = validateRaw("hard-coded-system-path.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0);

assertViolations(result, 0, 0, 1);

Expand All @@ -417,7 +421,7 @@ public void testHardCodedSystemPath() throws Exception {
"'dependencies.dependency.systemPath' for test:a:jar should use a variable instead of a hard-coded path");

SimpleProblemCollector result_31 =
validateRaw("hard-coded-system-path.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1);
validateRaw("hard-coded-system-path.xml");

assertViolations(result_31, 0, 0, 3);

Expand All @@ -440,8 +444,8 @@ public void testEmptyModule() throws Exception {
assertTrue(result.getErrors().get(0).contains("'modules.module[0]' has been specified without a path"));
}

public void testDuplicatePlugin() throws Exception {
SimpleProblemCollector result = validateRaw("duplicate-plugin.xml");
public void testDuplicatePlugin30() throws Exception {
SimpleProblemCollector result = validateRaw("duplicate-plugin.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0);

assertViolations(result, 0, 0, 4);

Expand All @@ -451,6 +455,17 @@ public void testDuplicatePlugin() throws Exception {
assertTrue(result.getWarnings().get(3).contains("duplicate declaration of plugin profile:managed-duplicate"));
}

public void testDuplicatePlugin() throws Exception {
SimpleProblemCollector result = validateRaw("duplicate-plugin.xml");

assertViolations(result, 0, 4, 0);

assertTrue(result.getErrors().get(0).contains("duplicate declaration of plugin test:duplicate"));
assertTrue(result.getErrors().get(1).contains("duplicate declaration of plugin test:managed-duplicate"));
assertTrue(result.getErrors().get(2).contains("duplicate declaration of plugin profile:duplicate"));
assertTrue(result.getErrors().get(3).contains("duplicate declaration of plugin profile:managed-duplicate"));
}

public void testDuplicatePluginExecution() throws Exception {
SimpleProblemCollector result = validateRaw("duplicate-plugin-execution.xml");

Expand All @@ -462,8 +477,8 @@ public void testDuplicatePluginExecution() throws Exception {
assertContains(result.getErrors().get(3), "duplicate execution with id b");
}

public void testReservedRepositoryId() throws Exception {
SimpleProblemCollector result = validate("reserved-repository-id.xml");
public void testReservedRepositoryId30() throws Exception {
SimpleProblemCollector result = validate("reserved-repository-id.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0);

assertViolations(result, 0, 0, 4);

Expand All @@ -474,6 +489,18 @@ public void testReservedRepositoryId() throws Exception {
result.getWarnings().get(3), "'distributionManagement.snapshotRepository.id' must not be 'local'");
}

public void testReservedRepositoryId() throws Exception {
SimpleProblemCollector result = validate("reserved-repository-id.xml");

assertViolations(result, 0, 4, 0);

assertContains(result.getErrors().get(0), "'repositories.repository.id'" + " must not be 'local'");
assertContains(result.getErrors().get(1), "'pluginRepositories.pluginRepository.id' must not be 'local'");
assertContains(result.getErrors().get(2), "'distributionManagement.repository.id' must not be 'local'");
assertContains(
result.getErrors().get(3), "'distributionManagement.snapshotRepository.id' must not be 'local'");
}

public void testMissingPluginDependencyGroupId() throws Exception {
SimpleProblemCollector result = validate("missing-plugin-dependency-groupId.xml");

Expand Down Expand Up @@ -506,24 +533,40 @@ public void testBadPluginDependencyVersion() throws Exception {
assertTrue(result.getErrors().get(0).contains("test:b"));
}

public void testBadVersion30() throws Exception {
SimpleProblemCollector result = validate("bad-version.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0);

assertViolations(result, 0, 0, 1);

assertContains(result.getWarnings().get(0), "'version' must not contain any of these characters");
}

public void testBadVersion() throws Exception {
SimpleProblemCollector result = validate("bad-version.xml");

assertViolations(result, 0, 1, 0);

assertContains(result.getErrors().get(0), "'version' must not contain any of these characters");
}

public void testBadSnapshotVersion30() throws Exception {
SimpleProblemCollector result = validate("bad-snapshot-version.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0);

assertViolations(result, 0, 0, 1);

assertContains(result.getWarnings().get(0), "'version' must not contain any of these characters");
assertContains(result.getWarnings().get(0), "'version' uses an unsupported snapshot version format");
}

public void testBadSnapshotVersion() throws Exception {
SimpleProblemCollector result = validate("bad-snapshot-version.xml");

assertViolations(result, 0, 0, 1);
assertViolations(result, 0, 1, 0);

assertContains(result.getWarnings().get(0), "'version' uses an unsupported snapshot version format");
assertContains(result.getErrors().get(0), "'version' uses an unsupported snapshot version format");
}

public void testBadRepositoryId() throws Exception {
SimpleProblemCollector result = validate("bad-repository-id.xml");
public void testBadRepositoryId30() throws Exception {
SimpleProblemCollector result = validate("bad-repository-id.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0);

assertViolations(result, 0, 0, 4);

Expand All @@ -540,6 +583,24 @@ public void testBadRepositoryId() throws Exception {
"'distributionManagement.snapshotRepository.id' must not contain any of these characters");
}

public void testBadRepositoryId() throws Exception {
SimpleProblemCollector result = validate("bad-repository-id.xml");

assertViolations(result, 0, 4, 0);

assertContains(
result.getErrors().get(0), "'repositories.repository.id' must not contain any of these characters");
assertContains(
result.getErrors().get(1),
"'pluginRepositories.pluginRepository.id' must not contain any of these characters");
assertContains(
result.getErrors().get(2),
"'distributionManagement.repository.id' must not contain any of these characters");
assertContains(
result.getErrors().get(3),
"'distributionManagement.snapshotRepository.id' must not contain any of these characters");
}

public void testBadDependencyExclusionId() throws Exception {
SimpleProblemCollector result =
validateEffective("bad-dependency-exclusion-id.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0);
Expand Down Expand Up @@ -593,7 +654,7 @@ public void testBadImportScopeClassifier() throws Exception {
}

public void testSystemPathRefersToProjectBasedir() throws Exception {
SimpleProblemCollector result = validateRaw("basedir-system-path.xml");
SimpleProblemCollector result = validateRaw("basedir-system-path.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0);

assertViolations(result, 0, 0, 2);

Expand All @@ -605,7 +666,7 @@ public void testSystemPathRefersToProjectBasedir() throws Exception {
"'dependencies.dependency.systemPath' for test:b:jar should not point at files within the project directory");

SimpleProblemCollector result_31 =
validateRaw("basedir-system-path.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1);
validateRaw("basedir-system-path.xml");

assertViolations(result_31, 0, 0, 4);

Expand Down

0 comments on commit eb4a75b

Please sign in to comment.