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