View Javadoc
1   package org.apache.maven.plugins.war.util;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * @author Stephane Nicoll
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 }