View Javadoc
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.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   * @author Stephane Nicoll
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  }