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