1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.war.util;
20
21 import java.util.ArrayList;
22
23 import junit.framework.TestCase;
24 import org.apache.maven.artifact.Artifact;
25 import org.apache.maven.model.Dependency;
26
27
28
29
30 public class WebappStructureTest extends TestCase {
31 public void testUnknownFileNotAvailable() {
32 final WebappStructure structure = new WebappStructure(new ArrayList<>());
33 assertFalse(structure.isRegistered("/foo/bar.txt"));
34 }
35
36 public void testRegisterSamePathTwice() {
37 final WebappStructure structure = new WebappStructure(new ArrayList<>());
38 structure.registerFile("overlay1", "WEB-INF/web.xml");
39 assertFalse(structure.registerFile("currentBuild", "WEB-INF/web.xml"));
40 }
41
42 public void testRegisterForced() {
43 final String path = "WEB-INF/web.xml";
44 final WebappStructure structure = new WebappStructure(new ArrayList<>());
45 assertFalse("New file should return false", structure.registerFileForced("overlay1", path));
46 assertEquals("overlay1", structure.getOwner(path));
47 }
48
49 public void testRegisterSamePathTwiceForced() {
50 final String path = "WEB-INF/web.xml";
51 final WebappStructure structure = new WebappStructure(new ArrayList<>());
52 structure.registerFile("overlay1", path);
53 assertEquals("overlay1", structure.getOwner(path));
54 assertTrue("owner replacement should have returned true", structure.registerFileForced("currentBuild", path));
55 assertEquals("currentBuild", structure.getOwner(path));
56 }
57
58 protected Dependency createDependency(
59 String groupId, String artifactId, String version, String type, String scope, String classifier) {
60 final Dependency dep = new Dependency();
61 dep.setGroupId(groupId);
62 dep.setArtifactId(artifactId);
63 dep.setVersion(version);
64 if (type == null) {
65 dep.setType("jar");
66 } else {
67 dep.setType(type);
68 }
69 if (scope != null) {
70 dep.setScope(scope);
71 } else {
72 dep.setScope(Artifact.SCOPE_COMPILE);
73 }
74 if (classifier != null) {
75 dep.setClassifier(classifier);
76 }
77 return dep;
78 }
79
80 protected Dependency createDependency(
81 String groupId, String artifactId, String version, String type, String scope) {
82 return createDependency(groupId, artifactId, version, type, scope, null);
83 }
84
85 protected Dependency createDependency(String groupId, String artifactId, String version, String type) {
86 return createDependency(groupId, artifactId, version, type, null);
87 }
88
89 protected Dependency createDependency(String groupId, String artifactId, String version) {
90 return createDependency(groupId, artifactId, version, null);
91 }
92 }