View Javadoc
1   /**
2    * The MIT License
3    *
4    * Copyright 2006-2012 The Codehaus.
5    *
6    * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
7    * associated documentation files (the "Software"), to deal in the Software without restriction,
8    * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9    * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
10   * furnished to do so, subject to the following conditions:
11   *
12   * The above copyright notice and this permission notice shall be included in all copies or
13   * substantial portions of the Software.
14   *
15   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
16   * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17   * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18   * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20   */
21  package org.codehaus.mojo.appassembler.daemon.generic;
22  
23  import java.io.File;
24  
25  import javax.xml.parsers.DocumentBuilder;
26  import javax.xml.parsers.DocumentBuilderFactory;
27  
28  import org.codehaus.mojo.appassembler.daemon.AbstractDaemonGeneratorTest;
29  import org.w3c.dom.Document;
30  
31  /**
32   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
33   * @version $Id$
34   */
35  public class GenericDaemonGeneratorTest
36      extends AbstractDaemonGeneratorTest
37  {
38      public void testGenerationWithAllInfoInDescriptor()
39          throws Exception
40      {
41          runTest( "generic", "src/test/resources/project-1/pom.xml", "src/test/resources/project-1/descriptor.xml",
42                   "target/output-1-generic" );
43  
44          File actualAppXml = new File( getTestFile( "target/output-1-generic" ), "app.xml" );
45  
46          assertTrue( "config file is missing: " + actualAppXml.getAbsolutePath(), actualAppXml.isFile() );
47  
48          DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
49  
50          builderFactory.setIgnoringComments( true );
51          builderFactory.setIgnoringElementContentWhitespace( true );
52          DocumentBuilder builder = builderFactory.newDocumentBuilder();
53  
54          Document actual = builder.parse( actualAppXml );
55  
56          assertNodeEquals( "com.westerngeco.example.App", "mainClass", actual );
57          assertNodeEquals( "org/codehaus/mojo/appassembler/project-1/1.0-SNAPSHOT/project-1-1.0-SNAPSHOT.jar",
58                            "relativePath", actual );
59          assertNodeEquals( "345", "initialMemorySize", actual );
60          assertNodeEquals( "234", "maxMemorySize", actual );
61          assertNodeEquals( "321", "maxStackSize", actual );
62          assertNodeEquals( "foo=bar", "systemProperty", actual );
63          assertNodeEquals( "arg1=arg1-value", "commandLineArgument", actual );
64          assertNodeNull( "commandLineArgument", actual );
65  
66      }
67  
68      // MAPPASM-143. The old unit tests testGenerationWithSnapshotDependencies() has been converted into
69      // a integration tests to get the integration test running after a release change etc.
70      private void assertNodeEquals( String expected, String tagName, Document document )
71      {
72          assertEquals( "Node with tag name " + tagName + " does not match", expected,
73                        document.getElementsByTagName( tagName ).item( 0 ).getFirstChild().getNodeValue() );
74      }
75  
76      private void assertNodeNull( String tagName, Document document )
77      {
78          assertNull( document.getElementsByTagName( tagName ).item( 1 ).getFirstChild() );
79      }
80  }