11package org .utpsql .maven .plugin .test ;
22
33import java .io .File ;
4+ import java .io .IOException ;
45
6+ import org .apache .commons .io .FileUtils ;
57import org .apache .maven .plugin .testing .MojoRule ;
68import org .junit .Assert ;
79import org .junit .Rule ;
1012
1113public class UtPLSQLMojoTest
1214{
13- public static final String POM_PATH = "src/test/resources/" ;
14-
15- public static final String OUTPUT_DIRECTORY = "target/test-classes" ;
15+ public static final String TARGET_DIRECTORY = "target/test-classes" ;
1616
1717 @ Rule
1818 public MojoRule rule = new MojoRule ();
@@ -23,12 +23,13 @@ public void testDefinition() throws Exception
2323
2424 try
2525 {
26- UtPLSQLMojo myMojo = (UtPLSQLMojo ) rule .lookupConfiguredMojo (new File (POM_PATH ), "test" );
26+ final String PROJECT_NAME = "simple-project" ;
27+ UtPLSQLMojo myMojo = (UtPLSQLMojo ) rule .lookupConfiguredMojo (new File (TARGET_DIRECTORY +"/" +PROJECT_NAME ), "test" );
2728
2829 Assert .assertNotNull (myMojo );
2930 myMojo .execute ();
3031
31- checkCoverReportsGenerated ("utplsql/coverage-sonar-reporter.xml" , "utplsql/sonar-test-reporter.xml" );
32+ checkCoverReportsGenerated (PROJECT_NAME , "utplsql/coverage-sonar-reporter.xml" , "utplsql/sonar-test-reporter.xml" );
3233 }
3334 catch (Exception e )
3435 {
@@ -41,12 +42,24 @@ public void testDefinition() throws Exception
4142 *
4243 * @param files
4344 */
44- private void checkCoverReportsGenerated (String ... files )
45+ private void checkCoverReportsGenerated (String projectName , String ... files )
4546 {
4647 for (String filename : files )
4748 {
48- File file = new File (OUTPUT_DIRECTORY , filename );
49- Assert .assertTrue ("The reporter for " + filename + " was not generated" , file .exists ());
49+ File outputFile = new File (TARGET_DIRECTORY +"/" +projectName +"/target/" , filename );
50+ File expectedOutputFile = new File (TARGET_DIRECTORY +"/" +projectName +"/expected-output/" , filename );
51+
52+ Assert .assertTrue ("The reporter for " + filename + " was not generated" , outputFile .exists ());
53+ try {
54+ // Duration is set to 1 before comparing contents.
55+ Assert .assertEquals ("The files differ!" ,
56+ FileUtils .readFileToString (outputFile , "utf-8" ).replaceAll ("(duration=\" [0-9\\ .]*\" )" , "duration=\" 1\" " ),
57+ FileUtils .readFileToString (expectedOutputFile , "utf-8" ));
58+ } catch (IOException e ) {
59+ // TODO Auto-generated catch block
60+ e .printStackTrace ();
61+ Assert .fail ("Unexpected Exception running the test of Definition" );
62+ }
5063 }
5164 }
5265
0 commit comments