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;
20  
21  import java.io.File;
22  import java.util.LinkedList;
23  
24  import org.apache.maven.plugins.war.stub.MavenProjectBasicStub;
25  import org.apache.maven.plugins.war.stub.ResourceStub;
26  
27  public class WarInPlaceMojoTest extends AbstractWarMojoTest {
28      protected static final String pomFilePath =
29              getBasedir() + "/target/test-classes/unit/warexplodedinplacemojo/plugin-config.xml";
30  
31      protected File getTestDirectory() throws Exception {
32          return new File(getBasedir(), "target/test-classes/unit/warexplodedinplacemojo/test-dir");
33      }
34  
35      private WarInPlaceMojo mojo;
36  
37      public void setUp() throws Exception {
38          super.setUp();
39  
40          mojo = (WarInPlaceMojo) lookupMojo("inplace", pomFilePath);
41          assertNotNull(mojo);
42      }
43  
44      public void testEnvironment() throws Exception {
45          // see setUp
46      }
47  
48      public void testSimpleExplodedInplaceWar() throws Exception {
49          // setup test data
50          String testId = "SimpleExplodedInplaceWar";
51          MavenProjectBasicStub project = new MavenProjectBasicStub();
52          File webAppSource = createWebAppSource(testId);
53          File classesDir = createClassesDir(testId, true);
54          File webAppResource = new File(getTestDirectory(), "resources");
55          File sampleResource = new File(webAppResource, "pix/panis_na.jpg");
56          ResourceStub[] resources = new ResourceStub[] {new ResourceStub()};
57  
58          createFile(sampleResource);
59  
60          // configure mojo
61          resources[0].setDirectory(webAppResource.getAbsolutePath());
62          this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, null, project);
63          setVariableValueToObject(mojo, "webResources", resources);
64          mojo.execute();
65  
66          // validate operation
67          File expectedWebSourceFile = new File(webAppSource, "pansit.jsp");
68          File expectedWebSource2File = new File(webAppSource, "org/web/app/last-exile.jsp");
69          File expectedWebResourceFile = new File(webAppSource, "pix/panis_na.jpg");
70          File expectedWEBINFDir = new File(webAppSource, "WEB-INF");
71          File expectedMETAINFDir = new File(webAppSource, "META-INF");
72  
73          assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
74          assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
75          assertTrue("resources doesn't exist: " + expectedWebResourceFile, expectedWebResourceFile.exists());
76          assertTrue("WEB-INF not found", expectedWEBINFDir.exists());
77          assertTrue("META-INF not found", expectedMETAINFDir.exists());
78      }
79  }