You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2024/06/10 19:41:25 UTC

(maven-integration-testing) branch MNG-7758-next-try created (now 565c7f172)

This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a change to branch MNG-7758-next-try
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git


      at 565c7f172 [MNG-7758] Report dependency problems for all repository - extends ITs

This branch includes the following new commits:

     new 565c7f172 [MNG-7758] Report dependency problems for all repository - extends ITs

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(maven-integration-testing) 01/01: [MNG-7758] Report dependency problems for all repository - extends ITs

Posted by sj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a commit to branch MNG-7758-next-try
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git

commit 565c7f17230bb5a1552e898f8c0ca61f9195655a
Author: Slawomir Jaranowski <sl...@payu.com>
AuthorDate: Mon Jun 10 21:41:13 2024 +0200

    [MNG-7758] Report dependency problems for all repository - extends ITs
---
 ...ng3477DependencyResolutionErrorMessageTest.java | 66 ++++++++++++++++++----
 .../{settings.xml => settings-template.xml}        |  4 +-
 2 files changed, 58 insertions(+), 12 deletions(-)

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..20ee0e10c 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,17 +19,21 @@
 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 <a href="https://issues.apache.org/jira/browse/MNG-3477">MNG-3477</a>.
  */
-public class MavenITmng3477DependencyResolutionErrorMessageTest extends AbstractMavenIntegrationTestCase {
+class MavenITmng3477DependencyResolutionErrorMessageTest extends AbstractMavenIntegrationTestCase {
 
     public MavenITmng3477DependencyResolutionErrorMessageTest() {
         super("[2.1.0,3.0-alpha-1),[3.0-beta-1,)");
@@ -40,29 +44,71 @@ public class MavenITmng3477DependencyResolutionErrorMessageTest extends Abstract
      *
      * @throws Exception in case of failure
      */
-    @Test
-    public void testit() throws Exception {
+    void testit(int port, String[] logExpectPatterns) throws Exception {
         File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-3477");
 
         Verifier verifier = newVerifier(testDir.getAbsolutePath());
+
+        Map<String, String> 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("-U");
         verifier.addCliArgument("--settings");
         verifier.addCliArgument("settings.xml");
+        verifier.addCliArgument("validate");
+        verifier.setLogFileName("log-" + port + ".txt");
         try {
-            verifier.addCliArgument("validate");
             verifier.execute();
             fail("Build should have failed to resolve dependency");
         } catch (VerificationException e) {
-            boolean foundCause = false;
             List<String> 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.*"});
+    }
+
+    @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\\).*"
+            });
+
+        } 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/settings.xml b/core-it-suite/src/test/resources/mng-3477/settings-template.xml
similarity index 93%
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..0e0938713 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.
   <mirrors>
     <mirror>
       <id>central</id>
-      <url>http://localhost:54312/repo</url>
+      <url>http://localhost:@port@/repo</url>
       <mirrorOf>central</mirrorOf>
     </mirror>
   </mirrors>
@@ -33,7 +33,7 @@ under the License.
       <repositories>
         <repository>
           <id>maven-core-it</id>
-          <url>http://localhost:54312/repo</url>
+          <url>http://localhost:@port@/repo</url>
           <releases>
             <checksumPolicy>ignore</checksumPolicy>
           </releases>