Skip to content

Commit 57dee65

Browse files
authored
[MNG-8294] Consistency checks when loading parent (#383)
1 parent 284b30f commit 57dee65

File tree

12 files changed

+197
-0
lines changed

12 files changed

+197
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.it;
20+
21+
import java.io.File;
22+
23+
import org.apache.maven.shared.verifier.VerificationException;
24+
import org.apache.maven.shared.verifier.Verifier;
25+
import org.apache.maven.shared.verifier.util.ResourceExtractor;
26+
import org.junit.jupiter.api.Test;
27+
28+
import static org.junit.jupiter.api.Assertions.assertThrows;
29+
30+
/**
31+
* This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-8288">MNG-8288</a>.
32+
*/
33+
class MavenITmng8294ParentChecksTest extends AbstractMavenIntegrationTestCase {
34+
35+
MavenITmng8294ParentChecksTest() {
36+
super("[4.0.0-beta-5,)");
37+
}
38+
39+
/**
40+
* Verify error when mismatch between GAV and relativePath
41+
*/
42+
@Test
43+
void testitbadMismatch() throws Exception {
44+
File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-8294-parent-checks");
45+
46+
Verifier verifier = newVerifier(new File(testDir, "bad-mismatch").getAbsolutePath());
47+
verifier.addCliArgument("validate");
48+
assertThrows(VerificationException.class, verifier::execute);
49+
verifier.verifyTextInLog(
50+
"at org.apache.maven.its.mng8294:parent instead of org.apache.maven.its.mng8294:bad-parent");
51+
}
52+
53+
/**
54+
* Verify error when the parent is not resolvable
55+
*/
56+
@Test
57+
void testitbadNonResolvable() throws Exception {
58+
File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-8294-parent-checks");
59+
60+
Verifier verifier = newVerifier(new File(testDir, "bad-non-resolvable").getAbsolutePath());
61+
verifier.addCliArgument("validate");
62+
assertThrows(VerificationException.class, verifier::execute);
63+
verifier.verifyTextInLog(
64+
"The following artifacts could not be resolved: org.apache.maven.its.mng8294:parent:pom:0.1-SNAPSHOT");
65+
}
66+
67+
/**
68+
* Verify error when a wrong path
69+
*/
70+
@Test
71+
void testitbadWrongPath() throws Exception {
72+
File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-8294-parent-checks");
73+
74+
Verifier verifier = newVerifier(new File(testDir, "bad-wrong-path").getAbsolutePath());
75+
verifier.addCliArgument("validate");
76+
assertThrows(VerificationException.class, verifier::execute);
77+
verifier.verifyTextInLog("points at '../foo' but no POM could be found");
78+
}
79+
80+
/**
81+
* Verify error when a wrong path
82+
*/
83+
@Test
84+
void testitokUsingEmpty() throws Exception {
85+
File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-8294-parent-checks");
86+
87+
Verifier verifier = newVerifier(new File(testDir, "ok-using-empty").getAbsolutePath());
88+
verifier.addCliArgument("validate");
89+
verifier.execute();
90+
verifier.verifyErrorFreeLog();
91+
}
92+
/**
93+
* Verify error when a wrong path
94+
*/
95+
@Test
96+
void testitokUsingGav() throws Exception {
97+
File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-8294-parent-checks");
98+
99+
Verifier verifier = newVerifier(new File(testDir, "ok-using-gav").getAbsolutePath());
100+
verifier.addCliArgument("validate");
101+
verifier.execute();
102+
verifier.verifyErrorFreeLog();
103+
}
104+
/**
105+
* Verify error when a wrong path
106+
*/
107+
@Test
108+
void testitokUsingPath() throws Exception {
109+
File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-8294-parent-checks");
110+
111+
Verifier verifier = newVerifier(new File(testDir, "ok-using-path").getAbsolutePath());
112+
verifier.addCliArgument("validate");
113+
verifier.execute();
114+
verifier.verifyErrorFreeLog();
115+
}
116+
}

core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public TestSuiteOrdering() {
120120
* the tests are to finishing. Newer tests are also more likely to fail, so this is
121121
* a fail fast technique as well.
122122
*/
123+
suite.addTestSuite(MavenITmng8294ParentChecksTest.class);
123124
suite.addTestSuite(MavenITmng8293BomImportFromReactor.class);
124125
suite.addTestSuite(MavenITmng8288NoRootPomTest.class);
125126
suite.addTestSuite(MavenITmng8133RootDirectoryInParentTest.class);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.1.0">
3+
<parent>
4+
<groupId>org.apache.maven.its.mng8294</groupId>
5+
<artifactId>bad-parent</artifactId>
6+
<version>0.1-SNAPSHOT</version>
7+
<relativePath>..</relativePath>
8+
</parent>
9+
10+
<artifactId>myArtifact</artifactId>
11+
</project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.1.0" root="true">
3+
<groupId>org.apache.maven.its.mng8294</groupId>
4+
<artifactId>parent</artifactId>
5+
<version>0.1-SNAPSHOT</version>
6+
<packaging>pom</packaging>
7+
</project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.1.0" root="true">
3+
<parent>
4+
<groupId>org.apache.maven.its.mng8294</groupId>
5+
<artifactId>parent</artifactId>
6+
<version>0.1-SNAPSHOT</version>
7+
</parent>
8+
<artifactId>myArtifact</artifactId>
9+
</project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.1.0" root="true">
3+
<parent>
4+
<relativePath>../foo</relativePath>
5+
</parent>
6+
<groupId>org.apache.maven.its.mng8294</groupId>
7+
<artifactId>parent</artifactId>
8+
<version>0.1-SNAPSHOT</version>
9+
</project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.1.0">
3+
<parent />
4+
<artifactId>myArtifact</artifactId>
5+
</project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.1.0" root="true">
3+
<groupId>org.apache.maven.its.mng8294</groupId>
4+
<artifactId>parent</artifactId>
5+
<version>0.1-SNAPSHOT</version>
6+
<packaging>pom</packaging>
7+
</project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.1.0">
3+
<parent>
4+
<groupId>org.apache.maven.its.mng8294</groupId>
5+
<artifactId>parent</artifactId>
6+
<version>0.1-SNAPSHOT</version>
7+
</parent>
8+
9+
<artifactId>myArtifact</artifactId>
10+
</project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.1.0" root="true">
3+
<groupId>org.apache.maven.its.mng8294</groupId>
4+
<artifactId>parent</artifactId>
5+
<version>0.1-SNAPSHOT</version>
6+
<packaging>pom</packaging>
7+
</project>

0 commit comments

Comments
 (0)