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