2121import static org .junit .Assert .assertEquals ;
2222import static org .junit .Assert .assertFalse ;
2323import static org .junit .Assert .assertTrue ;
24- import static org .junit .Assert .fail ;
2524
2625public class UtPLSQLMojoIT {
2726
@@ -44,111 +43,107 @@ public static void setUp() throws VerificationException, IOException, XmlPullPar
4443
4544 @ Test
4645 public void simpleProject () throws IOException , VerificationException {
47- final String PROJECT_NAME = "simple-project" ;
48- File testProject = ResourceExtractor .simpleExtractResources (getClass (), "/" + PROJECT_NAME );
46+ final String testFolder = "integration-tests/ simple-project" ;
47+ File testProject = ResourceExtractor .simpleExtractResources (getClass (), "/" + testFolder );
4948
5049 Verifier verifier = createVerifier (testProject );
5150 verifier .executeGoal ("test" );
5251
53- checkReportsGenerated (PROJECT_NAME , "utplsql/sonar-test-reporter.xml" , "utplsql/coverage-sonar-reporter.xml" );
52+ checkReportsGenerated (testFolder , "utplsql/sonar-test-reporter.xml" , "utplsql/coverage-sonar-reporter.xml" );
5453 }
5554
5655 @ Test
5756 public void regexProject () throws IOException , VerificationException {
58- final String PROJECT_NAME = "regex-project" ;
59- File testProject = ResourceExtractor .simpleExtractResources (getClass (), "/" + PROJECT_NAME );
57+ final String testFolder = "integration-tests/ regex-project" ;
58+ File testProject = ResourceExtractor .simpleExtractResources (getClass (), "/" + testFolder );
6059
6160 Verifier verifier = createVerifier (testProject );
6261 verifier .executeGoal ("test" );
6362
64- checkReportsGenerated (PROJECT_NAME , "utplsql/sonar-test-reporter.xml" , "utplsql/coverage-sonar-reporter.xml" );
63+ checkReportsGenerated (testFolder , "utplsql/sonar-test-reporter.xml" , "utplsql/coverage-sonar-reporter.xml" );
6564 }
6665
6766 @ Test
6867 public void typeMappingProject () throws IOException , VerificationException {
69- final String PROJECT_NAME = "type-mapping-project" ;
70- File testProject = ResourceExtractor .simpleExtractResources (getClass (), "/" + PROJECT_NAME );
68+ final String testFolder = "integration-tests/ type-mapping-project" ;
69+ File testProject = ResourceExtractor .simpleExtractResources (getClass (), "/" + testFolder );
7170
7271 Verifier verifier = createVerifier (testProject );
7372 verifier .executeGoal ("test" );
7473
75- checkReportsGenerated (PROJECT_NAME , "utplsql/sonar-test-reporter.xml" , "utplsql/coverage-sonar-reporter.xml" );
74+ checkReportsGenerated (testFolder , "utplsql/sonar-test-reporter.xml" , "utplsql/coverage-sonar-reporter.xml" );
7675 }
7776
7877 @ Test
7978 public void ownerParameterProject () throws IOException , VerificationException {
80- final String PROJECT_NAME = "owner-param-project" ;
81- File testProject = ResourceExtractor .simpleExtractResources (getClass (), "/" + PROJECT_NAME );
79+ final String testFolder = "integration-tests/ owner-param-project" ;
80+ File testProject = ResourceExtractor .simpleExtractResources (getClass (), "/" + testFolder );
8281
8382 Verifier verifier = createVerifier (testProject );
8483 verifier .executeGoal ("test" );
8584
86- checkReportsGenerated (PROJECT_NAME , "utplsql/sonar-test-reporter.xml" , "utplsql/coverage-sonar-reporter.xml" );
85+ checkReportsGenerated (testFolder , "utplsql/sonar-test-reporter.xml" , "utplsql/coverage-sonar-reporter.xml" );
8786 }
8887
8988 @ Test
9089 public void minimalistProject () throws IOException , VerificationException {
91- final String PROJECT_NAME = "minimalist-project" ;
92- File testProject = ResourceExtractor .simpleExtractResources (getClass (), "/" + PROJECT_NAME );
90+ final String testFolder = "integration-tests/ minimalist-project" ;
91+ File testProject = ResourceExtractor .simpleExtractResources (getClass (), "/" + testFolder );
9392
9493 Verifier verifier = createVerifier (testProject );
9594 verifier .executeGoal ("test" );
9695 }
9796
9897 @ Test
9998 public void tagsProject () throws IOException , VerificationException {
100- final String PROJECT_NAME = "tags-project" ;
101- File testProject = ResourceExtractor .simpleExtractResources (getClass (), "/" + PROJECT_NAME );
99+ final String testFolder = "integration-tests/ tags-project" ;
100+ File testProject = ResourceExtractor .simpleExtractResources (getClass (), "/" + testFolder );
102101
103102 Verifier verifier = createVerifier (testProject );
104103 verifier .executeGoal ("test" );
105104
106- checkReportsGenerated (PROJECT_NAME , "utplsql/sonar-test-reporter.xml" );
105+ checkReportsGenerated (testFolder , "utplsql/sonar-test-reporter.xml" );
107106 }
108107
109108 @ Test
110109 public void skipUtplsqlTests () throws IOException , VerificationException {
111- final String PROJECT_NAME = "skip-project" ;
112- File testProject = ResourceExtractor .simpleExtractResources (getClass (), "/" + PROJECT_NAME );
110+ final String testFolder = "integration-tests/ skip-project" ;
111+ File testProject = ResourceExtractor .simpleExtractResources (getClass (), "/" + testFolder );
113112
114113 Verifier verifier = createVerifier (testProject );
115114 verifier .executeGoal ("test" );
116115
117- assertFalse (new File ("target/test-classes/" + PROJECT_NAME + "/target" ).exists ());
116+ assertFalse (new File ("target/test-classes/" + testFolder + "/target" ).exists ());
118117 }
119118
120119 /**
121120 * Duration is set to 1 before comparing contents as it is always different.
122121 * Path separator is set to "/" to ensure windows / linux / mac compatibility.
123122 * \r and \n are removed to provide simpler comparison.
124123 *
125- * @param projectName Project name
126- * @param files Files to compare
124+ * @param testFolder Project name
125+ * @param files Files to compare
127126 */
128- private void checkReportsGenerated (String projectName , String ... files ) {
127+ private void checkReportsGenerated (String testFolder , String ... files ) throws IOException {
129128 for (String filename : files ) {
130- File outputFile = new File ("target/test-classes/" + projectName + "/target" , filename );
131- File expectedOutputFile = new File ("target/test-classes/" + projectName + "/expected-output" , filename );
129+ File outputFile = new File ("target/test-classes/" + testFolder + "/target" , filename );
130+ File expectedOutputFile = new File ("target/test-classes/" + testFolder + "/expected-output" , filename );
132131
133132 assertTrue ("The reporter for " + filename + " was not generated" , outputFile .exists ());
134133
135- try {
136- try (Stream <String > stream = Files .lines (Paths .get ("target" , "test-classes" , projectName , "target" , filename ))) {
137- String outputContent = stream
138- .filter (line -> !line .contains ("<?xml" ))
139- .map (line -> line .replaceAll ("(duration=\" [0-9.]*\" )" , "duration=\" 1\" " ))
140- .map (line -> line .replaceAll ("\\ \\ " , "/" ))
141- .map (line -> line .replaceAll ("\r " , "" ).replaceAll ("\n " , "" ))
142- .collect (Collectors .joining ("\n " ));
143- assertEquals ("The files differ!" ,
144- FileUtils .readFileToString (expectedOutputFile , "utf-8" )
145- .replace ("\r " , "" )
146- .replace ("\n " , "" ),
147- outputContent .replace ("\n " , "" ));
148- }
149- } catch (IOException e ) {
150- e .printStackTrace ();
151- fail ("Unexpected Exception running the test : " + e .getMessage ());
134+ try (Stream <String > stream = Files .lines (Paths .get ("target" , "test-classes" , testFolder , "target" , filename ))) {
135+ String outputContent = stream
136+ .filter (line -> !line .contains ("<?xml" ))
137+ .map (line -> line .replaceAll ("(duration=\" [0-9.]*\" )" , "duration=\" 1\" " ))
138+ .map (line -> line .replaceAll ("\\ \\ " , "/" ))
139+ .map (line -> line .replaceAll ("\r " , "" ).replaceAll ("\n " , "" ))
140+ .collect (Collectors .joining ("\n " ));
141+
142+ assertEquals ("The files differ!" ,
143+ FileUtils .readFileToString (expectedOutputFile , "utf-8" )
144+ .replace ("\r " , "" )
145+ .replace ("\n " , "" ),
146+ outputContent .replace ("\n " , "" ));
152147 }
153148 }
154149 }
0 commit comments