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: PCCSurefireTest.java 661727 2008-05-30 14:21:49Z bentmann $
31   */
32  public class PCCSurefireTest
33      extends AbstractPCCTest
34  {
35      protected void setUp()
36          throws Exception
37      {
38          super.setUp();
39  
40          pluginConfigurationConverter = new PCCSurefire();
41      }
42  
43      public void testBuildConfiguration()
44      {
45          try
46          {
47              projectProperties.load( getClassLoader().getResourceAsStream( "PCCSureFireTest1.properties" ) );
48  
49              pluginConfigurationConverter.buildConfiguration( configuration, v3Model, projectProperties );
50  
51              String value = configuration.getChild( "reportFormat" ).getValue();
52              Assert.assertEquals( "check reportFormat value", "xml", value );
53  
54              value = configuration.getChild( "jvm" ).getValue();
55              Assert.assertEquals( "check jvm value", "java", value );
56  
57              value = configuration.getChild( "argLine" ).getValue();
58              Assert.assertEquals( "check argLine value", "-Xmx160m -verbose", value );
59  
60              value = configuration.getChild( "printSummary" ).getValue();
61              Assert.assertEquals( "check printSummary value", "false", value );
62  
63              Xpp3Dom systemProperties = configuration.getChild( "systemProperties" );
64              if ( systemProperties.getChildCount() == 2 )
65              {
66                  Xpp3Dom systemPropertyOne = systemProperties.getChild( 0 );
67                  Assert.assertEquals( "check systemProperties/prop1 name", "prop1", systemPropertyOne.getName() );
68                  Assert.assertEquals( "check systemProperties/prop1 value", "your value", systemPropertyOne.getValue() );
69  
70                  Xpp3Dom systemPropertyTwo = systemProperties.getChild( 1 );
71                  Assert.assertEquals( "check systemProperties/prop2 name", "basedir", systemPropertyTwo.getName() );
72                  Assert.assertEquals( "check systemProperties/prop2 value", "${basedir}", systemPropertyTwo.getValue() );
73              }
74              else
75              {
76                  Assert.fail( "Wrong number of system properties" );
77              }
78  
79              value = configuration.getChild( "useFile" ).getValue();
80              Assert.assertEquals( "check useFile value", "false", value );
81  
82              value = configuration.getChild( "testFailureIgnore" ).getValue();
83              Assert.assertEquals( "check testFailureIgnore value", "true", value );
84  
85              value = configuration.getChild( "skip" ).getValue();
86              Assert.assertEquals( "check skip value", "true", value );
87          }
88          catch ( ProjectConverterException e )
89          {
90              Assert.fail();
91          }
92          catch ( IOException e )
93          {
94              Assert.fail( "Unable to find the requested resource." );
95          }
96      }
97  
98      public void testBuildConfigurationFork1()
99      {
100         try
101         {
102             projectProperties.load( getClassLoader().getResourceAsStream( "PCCSureFireTest1.properties" ) );
103 
104             pluginConfigurationConverter.buildConfiguration( configuration, v3Model, projectProperties );
105 
106             String value = configuration.getChild( "forkMode" ).getValue();
107             Assert.assertEquals( "check forkMode value", "once", value );
108         }
109         catch ( ProjectConverterException e )
110         {
111             Assert.fail();
112         }
113         catch ( IOException e )
114         {
115             Assert.fail( "Unable to find the requested resource." );
116         }
117     }
118 
119     public void testBuildConfigurationFork2()
120     {
121         try
122         {
123             projectProperties.load( getClassLoader().getResourceAsStream( "PCCSureFireTest2.properties" ) );
124 
125             pluginConfigurationConverter.buildConfiguration( configuration, v3Model, projectProperties );
126 
127             String value = configuration.getChild( "forkMode" ).getValue();
128             Assert.assertEquals( "check forkMode value", "once", value );
129         }
130         catch ( ProjectConverterException e )
131         {
132             Assert.fail();
133         }
134         catch ( IOException e )
135         {
136             Assert.fail( "Unable to find the requested resource." );
137         }
138     }
139 
140     public void testBuildConfigurationFork3()
141     {
142         try
143         {
144             projectProperties.load( getClassLoader().getResourceAsStream( "PCCSureFireTest3.properties" ) );
145 
146             pluginConfigurationConverter.buildConfiguration( configuration, v3Model, projectProperties );
147 
148             String value = configuration.getChild( "forkMode" ).getValue();
149             Assert.assertEquals( "check forkMode value", "perTest", value );
150         }
151         catch ( ProjectConverterException e )
152         {
153             Assert.fail();
154         }
155         catch ( IOException e )
156         {
157             Assert.fail( "Unable to find the requested resource." );
158         }
159     }
160 }