Coverage Report - org.apache.maven.surefire.testng.TestNGXmlTestSuite
 
Classes in this File Line Coverage Branch Coverage Complexity
TestNGXmlTestSuite
0%
0/33
0%
0/14
3,4
 
 1  
 package org.apache.maven.surefire.testng;
 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 java.io.File;
 23  
 import java.util.ArrayList;
 24  
 import java.util.HashMap;
 25  
 import java.util.List;
 26  
 import java.util.Map;
 27  
 import java.util.Properties;
 28  
 import org.apache.maven.surefire.report.ConsoleOutputCapture;
 29  
 import org.apache.maven.surefire.report.ConsoleOutputReceiver;
 30  
 import org.apache.maven.surefire.report.ReporterException;
 31  
 import org.apache.maven.surefire.report.ReporterFactory;
 32  
 import org.apache.maven.surefire.report.RunListener;
 33  
 import org.apache.maven.surefire.testset.TestSetFailedException;
 34  
 
 35  
 /**
 36  
  * Handles suite xml file definitions for TestNG.
 37  
  *
 38  
  * @author jkuhnert
 39  
  * @author <a href='mailto:the[dot]mindstorm[at]gmail[dot]com'>Alex Popescu</a>
 40  
  */
 41  
 public class TestNGXmlTestSuite
 42  
     implements TestNgTestSuite
 43  
 {
 44  
     private final List suiteFiles;
 45  
 
 46  
     private List<String> suiteFilePaths;
 47  
 
 48  
     private final String testSourceDirectory;
 49  
 
 50  
     private final Map options;
 51  
 
 52  
     private final File reportsDirectory;
 53  
 
 54  
     // Not really used
 55  
     private Map<File,String> testSets;
 56  
 
 57  
     /**
 58  
      * Creates a testng testset to be configured by the specified
 59  
      * xml file(s). The XML files are suite definitions files according to TestNG DTD.
 60  
      */
 61  
     public TestNGXmlTestSuite( List<File> suiteFiles, String testSourceDirectory, Properties confOptions, File reportsDirectory )
 62  0
     {
 63  0
         this.suiteFiles = suiteFiles;
 64  
 
 65  0
         this.options = confOptions;
 66  
 
 67  0
         this.testSourceDirectory = testSourceDirectory;
 68  
 
 69  0
         this.reportsDirectory = reportsDirectory;
 70  0
     }
 71  
 
 72  
     public void execute( ReporterFactory reporterManagerFactory )
 73  
         throws ReporterException, TestSetFailedException
 74  
     {
 75  0
         if ( testSets == null )
 76  
         {
 77  0
             throw new IllegalStateException( "You must call locateTestSets before calling execute" );
 78  
         }
 79  
 //        RunListener reporter = new SynchronizedReporterManager( reporterManagerFactory.createReporter() );
 80  0
         RunListener reporter = reporterManagerFactory.createReporter();
 81  0
         ConsoleOutputCapture.startCapture( (ConsoleOutputReceiver) reporter );
 82  
 
 83  0
         TestNGDirectoryTestSuite.startTestSuite( reporter, this );
 84  0
         TestNGExecutor.run( this.suiteFilePaths, this.testSourceDirectory, this.options, reporter, this,
 85  
                             reportsDirectory );
 86  0
         TestNGDirectoryTestSuite.finishTestSuite( reporter, this );
 87  0
     }
 88  
 
 89  
     public void execute( String testSetName, ReporterFactory reporterManagerFactory )
 90  
         throws TestSetFailedException
 91  
     {
 92  0
         throw new TestSetFailedException( "Cannot run individual test when suite files are specified" );
 93  
     }
 94  
 
 95  
     public Map locateTestSets( ClassLoader classLoader )
 96  
         throws TestSetFailedException
 97  
     {
 98  0
         if ( testSets != null )
 99  
         {
 100  0
             throw new IllegalStateException( "You can't call locateTestSets twice" );
 101  
         }
 102  
 
 103  0
         if ( this.suiteFiles == null )
 104  
         {
 105  0
             throw new IllegalStateException( "No suite files were specified" );
 106  
         }
 107  
 
 108  0
         this.testSets = new HashMap<File,String>();
 109  0
         this.suiteFilePaths = new ArrayList<String>();
 110  
 
 111  0
         for ( Object suiteFile : suiteFiles )
 112  
         {
 113  0
             File file = (File) suiteFile;
 114  0
             if ( !file.exists() || !file.isFile() )
 115  
             {
 116  0
                 throw new TestSetFailedException( "Suite file " + file + " is not a valid file" );
 117  
             }
 118  0
             this.testSets.put( file, file.getAbsolutePath() );
 119  0
             this.suiteFilePaths.add( file.getAbsolutePath() );
 120  0
         }
 121  
 
 122  0
         return this.testSets;
 123  
     }
 124  
 
 125  
     public String getSuiteName()
 126  
     {
 127  0
         String result = (String) options.get( "suitename" );
 128  0
         if ( result == null )
 129  
         {
 130  0
             result = "TestSuite";
 131  
         }
 132  0
         return result;
 133  
     }
 134  
 }