View Javadoc

1   package org.apache.maven.model.converter.plugins;
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 junit.framework.Assert;
23  import org.apache.maven.model.converter.ProjectConverterException;
24  import org.codehaus.plexus.util.xml.Xpp3Dom;
25  
26  import java.io.IOException;
27  
28  /**
29   * @author Dennis Lundberg
30   * @version $Id: PCCJarTest.java 661727 2008-05-30 14:21:49Z bentmann $
31   */
32  public class PCCJarTest
33      extends AbstractPCCTest
34  {
35      protected void setUp()
36          throws Exception
37      {
38          super.setUp();
39  
40          pluginConfigurationConverter = new PCCJar();
41      }
42  
43      public void testBuildConfiguration()
44      {
45          String value;
46  
47          try
48          {
49              projectProperties.load( getClassLoader().getResourceAsStream( "PCCJarTest.properties" ) );
50  
51              pluginConfigurationConverter.buildConfiguration( configuration, v3Model, projectProperties );
52  
53              Xpp3Dom archive = configuration.getChild( "archive" );
54              if ( archive.getChildCount() > 0 )
55              {
56                  value = archive.getChild( "compress" ).getValue();
57                  Assert.assertEquals( "check compress value", "false", value );
58  
59                  value = archive.getChild( "index" ).getValue();
60                  Assert.assertEquals( "check index value", "true", value );
61  
62                  Xpp3Dom manifest = archive.getChild( "manifest" );
63                  if ( manifest.getChildCount() > 0 )
64                  {
65                      value = manifest.getChild( "addClasspath" ).getValue();
66                      Assert.assertEquals( "check addClasspath value", "true", value );
67  
68                      value = manifest.getChild( "addExtensions" ).getValue();
69                      Assert.assertEquals( "check addExtensions value", "true", value );
70  
71                      value = manifest.getChild( "mainClass" ).getValue();
72                      Assert.assertEquals( "check mainClass value", "MyClass", value );
73                  }
74  
75                  Xpp3Dom manifestEntries = archive.getChild( "manifestEntries" );
76                  if ( manifestEntries.getChildCount() > 0 )
77                  {
78                      value = manifestEntries.getChild( "Bar-Attribute" ).getValue();
79                      Assert.assertEquals( "check Bar-Attribute value", "I like toast and jam", value );
80  
81                      value = manifestEntries.getChild( "Foo-Attribute" ).getValue();
82                      Assert.assertEquals( "check Foo-Attribute value", "I like bread and butter", value );
83                  }
84  
85                  value = archive.getChild( "manifestFile" ).getValue();
86                  Assert.assertEquals( "check manifestFile value", "manifest.mf", value );
87              }
88  
89              value = configuration.getChild( "finalName" ).getValue();
90              Assert.assertEquals( "check finalName value", "my.jar", value );
91          }
92          catch ( ProjectConverterException e )
93          {
94              Assert.fail( e.getMessage() );
95          }
96          catch ( IOException e )
97          {
98              Assert.fail( "Unable to find the requested resource." );
99          }
100     }
101 }