diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3477DependencyResolutionErrorMessageTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3477DependencyResolutionErrorMessageTest.java
index 5fcdab5dd..d530362b7 100644
--- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3477DependencyResolutionErrorMessageTest.java
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3477DependencyResolutionErrorMessageTest.java
@@ -19,20 +19,25 @@
package org.apache.maven.it;
import java.io.File;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.maven.shared.verifier.VerificationException;
import org.apache.maven.shared.verifier.Verifier;
import org.apache.maven.shared.verifier.util.ResourceExtractor;
+import org.eclipse.jetty.server.NetworkConnector;
+import org.eclipse.jetty.server.Server;
import org.junit.jupiter.api.Test;
/**
* This is a test set for MNG-3477.
+ * and extends for MNG-7758
*/
-public class MavenITmng3477DependencyResolutionErrorMessageTest extends AbstractMavenIntegrationTestCase {
+class MavenITmng3477DependencyResolutionErrorMessageTest extends AbstractMavenIntegrationTestCase {
public MavenITmng3477DependencyResolutionErrorMessageTest() {
- super("[2.1.0,3.0-alpha-1),[3.0-beta-1,)");
+ super("[4.0.0-beta-4,)");
}
/**
@@ -40,29 +45,111 @@ public MavenITmng3477DependencyResolutionErrorMessageTest() {
*
* @throws Exception in case of failure
*/
- @Test
- public void testit() throws Exception {
+ void testit(int port, String[] logExpectPatterns, String projectFile) throws Exception {
File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-3477");
Verifier verifier = newVerifier(testDir.getAbsolutePath());
+
+ Map filterProps = new HashMap<>();
+ filterProps.put("@port@", Integer.toString(port));
+ verifier.filterFile("settings-template.xml", "settings.xml", "UTF-8", filterProps);
+
verifier.setAutoclean(false);
verifier.deleteArtifacts("org.apache.maven.its.mng3477");
- verifier.addCliArgument("--settings");
- verifier.addCliArgument("settings.xml");
+ verifier.addCliArgument("-U");
+ verifier.addCliArguments("--settings", "settings.xml");
+ verifier.addCliArguments("-f", projectFile);
+ verifier.addCliArgument("validate");
+ verifier.setLogFileName("log-" + projectFile + "-" + port + ".txt");
try {
- verifier.addCliArgument("validate");
verifier.execute();
fail("Build should have failed to resolve dependency");
} catch (VerificationException e) {
- boolean foundCause = false;
List lines = verifier.loadLines(verifier.getLogFileName(), "UTF-8");
- for (String line : lines) {
- if (line.matches(".*org.apache.maven.its.mng3477:dep:.*:1.0.*Connection.*refused.*")) {
- foundCause = true;
- break;
+ for (String pattern : logExpectPatterns) {
+ boolean foundCause = false;
+ for (String line : lines) {
+ if (line.matches(pattern)) {
+ foundCause = true;
+ break;
+ }
}
+ assertTrue("Transfer error cause was not found - " + pattern, foundCause);
+ }
+ }
+ }
+
+ /**
+ * Only one exception is returned by DependencyCollectionException.getResult().getExceptions()
+ *
+ * @throws Exception
+ */
+ @Test
+ void connectionProblems() throws Exception {
+ testit(54312, new String[] {".*org.apache.maven.its.mng3477:dep:.*:1.0.*Connection.*refused.*"}, "pom.xml");
+ }
+
+ @Test
+ void connectionProblemsPlugin() throws Exception {
+ testit(
+ 54312,
+ new String[] {
+ ".*The following artifacts could not be resolved: org.apache.maven.its.plugins:maven-it-plugin-not-exists:pom:1.2.3 \\(absent\\): Could not transfer artifact org.apache.maven.its.plugins:maven-it-plugin-not-exists:pom:1.2.3 from/to maven-core-it \\(http://localhost:.*/repo\\): Connection to http://localhost:.*2/repo/ refused.*"
+ },
+ "pom-plugin.xml");
+ }
+
+ @Test
+ void notFoundProblems() throws Exception {
+ Server server = null;
+ try {
+ server = new Server(0);
+ server.start();
+ if (server.isFailed()) {
+ fail("Couldn't bind the server socket to a free port!");
+ }
+
+ int port = ((NetworkConnector) server.getConnectors()[0]).getLocalPort();
+ testit(
+ port,
+ new String[] {
+ ".*Could not find artifact org.apache.maven.its.mng3477:dep:.*:1.0 in central \\(http://localhost:.*/repo\\).*",
+ ".*Could not find artifact org.apache.maven.its.mng3477:dep:.*:1.0 in maven-core-it \\(http://localhost:.*/repo\\).*"
+ },
+ "pom.xml");
+
+ } finally {
+ if (server != null) {
+ server.stop();
+ server.join();
+ }
+ }
+ }
+
+ @Test
+ void notFoundProblemsPlugin() throws Exception {
+ Server server = null;
+ try {
+ server = new Server(0);
+ server.start();
+ if (server.isFailed()) {
+ fail("Couldn't bind the server socket to a free port!");
+ }
+
+ int port = ((NetworkConnector) server.getConnectors()[0]).getLocalPort();
+ testit(
+ port,
+ new String[] {
+ ".*Could not find artifact org.apache.maven.its.plugins:maven-it-plugin-not-exists:jar:1.2.3 in central \\(http://localhost:.*/repo\\).*",
+ ".*Could not find artifact org.apache.maven.its.plugins:maven-it-plugin-not-exists:jar:1.2.3 in maven-core-it \\(http://localhost:.*/repo\\).*"
+ },
+ "pom-plugin.xml");
+
+ } finally {
+ if (server != null) {
+ server.stop();
+ server.join();
}
- assertTrue("Transfer error cause was not found", foundCause);
}
}
}
diff --git a/core-it-suite/src/test/resources/mng-3477/pom-plugin.xml b/core-it-suite/src/test/resources/mng-3477/pom-plugin.xml
new file mode 100644
index 000000000..b267e306d
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-3477/pom-plugin.xml
@@ -0,0 +1,49 @@
+
+
+
+ 4.0.0
+
+ org.apache.maven.its.mng3477
+ test
+ 1
+ jar
+
+ Maven Integration Test :: MNG-3477
+ Tests that dependency resolution errors tell the underlying transport issue.
+
+
+
+
+ org.apache.maven.its.plugins
+ maven-it-plugin-not-exists
+ 1.2.3
+
+
+ test
+
+ compile
+
+ validate
+
+
+
+
+
+
diff --git a/core-it-suite/src/test/resources/mng-3477/settings.xml b/core-it-suite/src/test/resources/mng-3477/settings-template.xml
similarity index 75%
rename from core-it-suite/src/test/resources/mng-3477/settings.xml
rename to core-it-suite/src/test/resources/mng-3477/settings-template.xml
index f55f2d030..5d27e2d5b 100644
--- a/core-it-suite/src/test/resources/mng-3477/settings.xml
+++ b/core-it-suite/src/test/resources/mng-3477/settings-template.xml
@@ -23,7 +23,7 @@ under the License.
central
- http://localhost:54312/repo
+ http://localhost:@port@/repo
central
@@ -33,7 +33,7 @@ under the License.
maven-core-it
- http://localhost:54312/repo
+ http://localhost:@port@/repo
ignore
@@ -42,6 +42,18 @@ under the License.
+
+
+ maven-core-it
+ http://localhost:@port@/repo
+
+ ignore
+
+
+ false
+
+
+