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