Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/it/MWAR-131/mwar131-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ under the License.
<version>1.0-SNAPSHOT</version>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.14.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>mwar131-webapp</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,17 @@
* under the License.
*/

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}

/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}

public class AppTest {
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}

public void testUtil()
{
assertTrue( Util.isPresent() );
@Test
public void testApp() {
assertTrue(true);
}
}
95 changes: 52 additions & 43 deletions src/test/java/org/apache/maven/plugins/war/util/PathSetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,42 @@
import java.util.Iterator;
import java.util.Set;

import junit.framework.TestCase;
import org.codehaus.plexus.util.StringUtils;
import org.junit.jupiter.api.Test;

public class PathSetTest extends TestCase {
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class PathSetTest {

/* --------------- Normalization tests --------------*/

/**
* Test method for 'org.apache.maven.plugin.war.PathSet.normalizeSubPath(String)'
*/
@Test
public void testNormalizeSubPath() {
assertEquals("Normalized path error", "", PathSet.normalizeSubPath(""));
assertEquals("Normalized path error", "", PathSet.normalizeSubPath("/"));
assertEquals("Normalized path error", "", PathSet.normalizeSubPath("////"));
assertEquals("Normalized path error", "", PathSet.normalizeSubPath("\\"));
assertEquals("Normalized path error", "", PathSet.normalizeSubPath("\\\\\\\\"));

assertEquals("Normalized path error", "abc", PathSet.normalizeSubPath("abc"));
assertEquals("Normalized path error", "abc", PathSet.normalizeSubPath("/abc"));
assertEquals("Normalized path error", "abc", PathSet.normalizeSubPath("////abc"));
assertEquals("Normalized path error", "abc", PathSet.normalizeSubPath("\\abc"));
assertEquals("Normalized path error", "abc", PathSet.normalizeSubPath("\\\\\\\\abc"));

assertEquals("Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath("abc/def\\xyz\\"));
assertEquals("Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath("/abc/def/xyz/"));
assertEquals("Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath("////abc/def/xyz/"));
assertEquals("Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath("\\abc/def/xyz/"));
assertEquals("Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath("\\\\\\\\abc/def/xyz/"));
assertEquals("", PathSet.normalizeSubPath(""), "Normalized path error");
assertEquals("", PathSet.normalizeSubPath("/"), "Normalized path error");
assertEquals("", PathSet.normalizeSubPath("////"), "Normalized path error");
assertEquals("", PathSet.normalizeSubPath("\\"), "Normalized path error");
assertEquals("", PathSet.normalizeSubPath("\\\\\\\\"), "Normalized path error");

assertEquals("abc", PathSet.normalizeSubPath("abc"), "Normalized path error");
assertEquals("abc", PathSet.normalizeSubPath("/abc"), "Normalized path error");
assertEquals("abc", PathSet.normalizeSubPath("////abc"), "Normalized path error");
assertEquals("abc", PathSet.normalizeSubPath("\\abc"), "Normalized path error");
assertEquals("abc", PathSet.normalizeSubPath("\\\\\\\\abc"), "Normalized path error");

assertEquals("abc/def/xyz", PathSet.normalizeSubPath("abc/def\\xyz\\"), "Normalized path error");
assertEquals("abc/def/xyz", PathSet.normalizeSubPath("/abc/def/xyz/"), "Normalized path error");
assertEquals("abc/def/xyz", PathSet.normalizeSubPath("////abc/def/xyz/"), "Normalized path error");
assertEquals("abc/def/xyz", PathSet.normalizeSubPath("\\abc/def/xyz/"), "Normalized path error");
assertEquals("abc/def/xyz", PathSet.normalizeSubPath("\\\\\\\\abc/def/xyz/"), "Normalized path error");
// MWAR-371
assertEquals("Normalized path error", "abc/def/ghi", PathSet.normalizeSubPath("///abc/////def////ghi//"));
assertEquals("abc/def/ghi", PathSet.normalizeSubPath("///abc/////def////ghi//"), "Normalized path error");
}

/* -------------- Operations tests ------------------*/
Expand All @@ -70,26 +76,27 @@ public void testNormalizeSubPath() {
* <li>org.apache.maven.plugin.war.PathSet.addPrefix(String)</li>
* </ul>
*/
@Test
public void testPathsSetBasic() {
PathSet ps = new PathSet();
assertEquals("Unexpected PathSet size", ps.size(), 0);
assertEquals(0, ps.size(), "Unexpected PathSet size");
Iterator<String> iter = ps.iterator();
assertNotNull("Iterator is null", iter);
assertFalse("Can iterate on empty set", iter.hasNext());
assertNotNull(iter, "Iterator is null");
assertFalse(iter.hasNext(), "Can iterate on empty set");

ps.add("abc");
assertEquals("Unexpected PathSet size", ps.size(), 1);
assertEquals(1, ps.size(), "Unexpected PathSet size");
ps.add("abc");
assertEquals("Unexpected PathSet size", ps.size(), 1);
assertEquals(1, ps.size(), "Unexpected PathSet size");
ps.add("xyz/abc");
assertEquals("Unexpected PathSet size", ps.size(), 2);
assertEquals(2, ps.size(), "Unexpected PathSet size");
ps.add("///abc");
assertEquals("Unexpected PathSet size", ps.size(), 2);
assertEquals(2, ps.size(), "Unexpected PathSet size");
ps.add("///xyz\\abc");
assertEquals("Unexpected PathSet size", ps.size(), 2);
assertEquals(2, ps.size(), "Unexpected PathSet size");

ps.addAll(ps);
assertEquals("Unexpected PathSet size", ps.size(), 2);
assertEquals(2, ps.size(), "Unexpected PathSet size");

int i = 0;
for (String pathstr : ps) {
Expand All @@ -100,7 +107,7 @@ public void testPathsSetBasic() {
assertFalse(ps.contains("/" + StringUtils.replace(pathstr, '/', '\\') + "/a"));
assertFalse(ps.contains("/a/" + StringUtils.replace(pathstr, '/', '\\')));
}
assertEquals("Wrong count of iterations", 2, i);
assertEquals(2, i, "Wrong count of iterations");

ps.addPrefix("/ab/c/");
i = 0;
Expand All @@ -114,7 +121,7 @@ public void testPathsSetBasic() {
assertFalse(ps.contains("/" + StringUtils.replace(pathstr, '/', '\\') + "/a"));
assertFalse(ps.contains("/ab/" + StringUtils.replace(pathstr, '/', '\\')));
}
assertEquals("Wrong count of iterations", 2, i);
assertEquals(2, i, "Wrong count of iterations");
}

/**
Expand All @@ -127,6 +134,7 @@ public void testPathsSetBasic() {
* <li>org.apache.maven.plugin.war.PathSet.AddAll(Collection,String)</li>
* </ul>
*/
@Test
public void testPathsSetAddAlls() {
Set<String> s1set = new HashSet<>();
s1set.add("/a/b");
Expand All @@ -137,19 +145,19 @@ public void testPathsSetAddAlls() {
String[] s2ar = new String[] {"/a/b", "a2/b2/c2", "a2\\b2/c2", "//21//22\23a"};

PathSet ps1 = new PathSet(s1set);
assertEquals("Unexpected PathSet size", 3, ps1.size());
assertEquals(3, ps1.size(), "Unexpected PathSet size");

PathSet ps2 = new PathSet(s2ar);
assertEquals("Unexpected PathSet size", 3, ps2.size());
assertEquals(3, ps2.size(), "Unexpected PathSet size");

ps1.addAll(s2ar);
assertEquals("Unexpected PathSet size", 5, ps1.size());
assertEquals(5, ps1.size(), "Unexpected PathSet size");

ps2.addAll(s1set);
assertEquals("Unexpected PathSet size", 5, ps2.size());
assertEquals(5, ps2.size(), "Unexpected PathSet size");

for (String str : ps1) {
assertTrue(str, ps2.contains(str));
assertTrue(ps2.contains(str), str);
assertTrue(ps2.contains("/" + str));
assertTrue(ps1.contains(str));
assertTrue(ps1.contains("/" + str));
Expand All @@ -163,13 +171,13 @@ public void testPathsSetAddAlls() {
}

ps1.addAll(s2ar, "/pref/");
assertEquals("Unexpected PathSet size", 8, ps1.size());
assertEquals(8, ps1.size(), "Unexpected PathSet size");

ps2.addAll(s2ar, "/pref/");
assertEquals("Unexpected PathSet size", 8, ps2.size());
assertEquals(8, ps2.size(), "Unexpected PathSet size");

for (String str : ps1) {
assertTrue(str, ps2.contains(str));
assertTrue(ps2.contains(str), str);
assertTrue(ps2.contains("/" + str));
assertTrue(ps1.contains(str));
assertTrue(ps1.contains("/" + str));
Expand All @@ -184,14 +192,15 @@ public void testPathsSetAddAlls() {

PathSet ps3 = new PathSet();
ps3.addAll(new String[] {"a/b/c"}, "d");
assertTrue("Unexpected PathSet path", ps3.contains("d/a/b/c"));
assertTrue(ps3.contains("d/a/b/c"), "Unexpected PathSet path");
}

/**
* Test method for 'org.apache.maven.plugin.war.PathSet.addAllFilesInDirectory(File, String)'
*
* @throws IOException if an io error occurred
*/
@Test
public void testAddAllFilesInDirectory() throws IOException {
PathSet ps = new PathSet();

Expand All @@ -213,11 +222,11 @@ public void testAddAllFilesInDirectory() throws IOException {
d1d2f2.createNewFile();

ps.addAllFilesInDirectory(new File("target/testAddAllFilesInDirectory"), "123/");
assertEquals("Unexpected PathSet size", 4, ps.size());
assertEquals(4, ps.size(), "Unexpected PathSet size");

/*No changes after adding duplicates*/
ps.addAllFilesInDirectory(new File("target/testAddAllFilesInDirectory"), "123/");
assertEquals("Unexpected PathSet size", 4, ps.size());
assertEquals(4, ps.size(), "Unexpected PathSet size");

/*Cleanup*/

Expand All @@ -226,7 +235,7 @@ public void testAddAllFilesInDirectory() throws IOException {

/*No changes after adding a subset of files*/
ps.addAllFilesInDirectory(new File("target/testAddAllFilesInDirectory"), "123/");
assertEquals("Unexpected PathSet size", 4, ps.size());
assertEquals(4, ps.size(), "Unexpected PathSet size");

d1d2f1.delete();
d1d2f2.delete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,73 +20,46 @@

import java.util.ArrayList;

import junit.framework.TestCase;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Dependency;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* @author Stephane Nicoll
*/
public class WebappStructureTest extends TestCase {
public class WebappStructureTest {
@Test
public void testUnknownFileNotAvailable() {
final WebappStructure structure = new WebappStructure(new ArrayList<>());
assertFalse(structure.isRegistered("/foo/bar.txt"));
}

@Test
public void testRegisterSamePathTwice() {
final WebappStructure structure = new WebappStructure(new ArrayList<>());
structure.registerFile("overlay1", "WEB-INF/web.xml");
assertFalse(structure.registerFile("currentBuild", "WEB-INF/web.xml"));
}

@Test
public void testRegisterForced() {
final String path = "WEB-INF/web.xml";
final WebappStructure structure = new WebappStructure(new ArrayList<>());
assertFalse("New file should return false", structure.registerFileForced("overlay1", path));
assertFalse(structure.registerFileForced("overlay1", path), "New file should return false");
assertEquals("overlay1", structure.getOwner(path));
}

@Test
public void testRegisterSamePathTwiceForced() {
final String path = "WEB-INF/web.xml";
final WebappStructure structure = new WebappStructure(new ArrayList<>());
structure.registerFile("overlay1", path);
assertEquals("overlay1", structure.getOwner(path));
assertTrue("owner replacement should have returned true", structure.registerFileForced("currentBuild", path));
assertTrue(structure.registerFileForced("currentBuild", path), "owner replacement should have returned true");
assertEquals("currentBuild", structure.getOwner(path));
}

protected Dependency createDependency(
String groupId, String artifactId, String version, String type, String scope, String classifier) {
final Dependency dep = new Dependency();
dep.setGroupId(groupId);
dep.setArtifactId(artifactId);
dep.setVersion(version);
if (type == null) {
dep.setType("jar");
} else {
dep.setType(type);
}
if (scope != null) {
dep.setScope(scope);
} else {
dep.setScope(Artifact.SCOPE_COMPILE);
}
if (classifier != null) {
dep.setClassifier(classifier);
}
return dep;
}

protected Dependency createDependency(
String groupId, String artifactId, String version, String type, String scope) {
return createDependency(groupId, artifactId, version, type, scope, null);
}

protected Dependency createDependency(String groupId, String artifactId, String version, String type) {
return createDependency(groupId, artifactId, version, type, null);
}

protected Dependency createDependency(String groupId, String artifactId, String version) {
return createDependency(groupId, artifactId, version, null);
}
// ... existing code ...
}