4444import uk .co .objectivity .test .db .beans .TestParams ;
4545import uk .co .objectivity .test .db .beans .TestResults ;
4646import uk .co .objectivity .test .db .beans .xml .Compare ;
47+ import uk .co .objectivity .test .db .beans .xml .Condition ;
4748import uk .co .objectivity .test .db .utils .Printer ;
4849import uk .co .objectivity .test .db .utils .SavedTimes ;
4950import uk .co .objectivity .test .db .utils .TCMessages ;
@@ -82,50 +83,56 @@ public void testSQLResults() {
8283 }
8384 compare = testParams .getCmpSqlResultsTest ().getCompare ();
8485 testResults = compare .getCompareMode ().getComparator ().compare (testParams );
86+ if (!testResults .getOutput ().isEmpty ())
87+ logInfo2All (testResults .getOutput () + "\r \n " , tcMsgs );
8588 logInfo2All ("Executed query: \r \n " + testResults .getExecutedQuery (), tcMsgs );
8689
8790 // assertions
8891 if (compare .getCompareMode () == CompareMode .NMB_OF_RESULTS ) {
89- List <uk . co . objectivity . test . db . beans . xml . Assert > assertList = compare .getAssertions ();
92+ List <Condition > assertList = compare .getAssertions ();
9093 if (assertList != null ) {
91- logInfo2All ("Rows count:" + testResults .getNmbOfRows (),tcMsgs );
94+ logInfo2All ("Rows count:" + testResults .getNmbOfRows (), tcMsgs );
9295 TestResults effFinalTR = testResults ;
93- assertList .forEach (a -> logInfo2All (a .getAssertType ().name () + " " + a .getValue (), tcMsgs ));
94- assertList .forEach (a -> a .getAssertType ().assertByType (effFinalTR .getNmbOfRows (), a .getValue ()));
96+ assertList .forEach (a -> logInfo2All (a .getConditionType ().name () + " " + a .getValue (), tcMsgs ));
97+ assertList .forEach (a -> a .getConditionType ().assertByType (effFinalTR .getNmbOfRows (), a .getValue ()));
9598 int p = getIndexByName (testParams .getTestName ());
96- if (p >= 0 ){
99+ if (p >= 0 ) {
97100 savedTimesList .get (p ).setTestResult ("Passed" );
98101 }
99102
100103 }
101- } else if (compare .getCompareMode () == CompareMode .FETCH || compare .getCompareMode () == CompareMode .FILE ) {
102- Assert .assertEquals (testResults .getNmbOfRows (), Integer .valueOf (0 ),
103- "Among " + testResults .getNmbOfComparedRows () +
104- " compared rows, some differences in SQL queries results found - " );
104+ } else if (compare .getCompareMode () == CompareMode .FETCH || compare .getCompareMode () == CompareMode .FILE
105+ || compare .getCompareMode () == CompareMode .KEY ) {
106+ Assert .assertEquals (testResults .getNmbOfRows (), Integer .valueOf (0 ),
107+ "Among " + testResults .getNmbOfComparedRows ()
108+ + " compared rows, some differences in SQL queries results found - " );
105109 } else {
106- Assert .assertEquals (testResults .getNmbOfRows (), Integer .valueOf (0 ),
107- "Differences in SQL queries found - " );
108- }
110+ Assert .assertEquals (testResults .getNmbOfRows (), Integer .valueOf (0 ),
111+ "Differences in SQL queries found - " );
112+ }
109113
110- if (compare .getCompareMode () == CompareMode .FETCH || compare .getCompareMode () == CompareMode .FILE ){
111- logInfo2All ("TEST PASSED, Compared rows:" + testResults .getNmbOfComparedRows (),tcMsgs );
114+ if (compare .getCompareMode () == CompareMode .FETCH || compare .getCompareMode () == CompareMode .FILE
115+ || compare .getCompareMode () == CompareMode .KEY ) {
116+ logInfo2All ("TEST PASSED, Compared rows:" + testResults .getNmbOfComparedRows (), tcMsgs );
112117 } else {
113118 logInfo2All ("TEST PASSED" , tcMsgs );
114119 }
115120
116121 } catch (AssertionError ae ) {
117122 String resultsTextTable = null ;
118- if (compare != null && testResults != null && compare .getCompareMode () != CompareMode .NMB_OF_RESULTS &&
119- compare .getDiffTableSize () > 0 ) {
123+ if (compare != null && testResults != null && compare .getCompareMode () != CompareMode .NMB_OF_RESULTS
124+ && compare .getDiffTableSize () > 0 ) {
120125 resultsTextTable = Printer .getTextTable (testResults );
121126 log .info (resultsTextTable );
122127 }
123128 logFailed2All (ae , tcMsgs , resultsTextTable );
124129 throw ae ;
125130 } catch (Exception e ) {
126131 logFailed2All (e , tcMsgs , null );
127- // it would be better to skip tests which configuration is wrong, and fail only those which really fails
128- // (AssertionError) but fail is more "visible". Maybe user should choose (configuration) if skip or fail
132+ // it would be better to skip tests which configuration is wrong, and fail only
133+ // those which really fails
134+ // (AssertionError) but fail is more "visible". Maybe user should choose
135+ // (configuration) if skip or fail
129136 // on misconfiguration or i.e. DB problems
130137 // throw new SkipException(e.getMessage());
131138 throw new TestException (e );
@@ -136,11 +143,9 @@ public void testSQLResults() {
136143
137144 }
138145
139- public int getIndexByName (String testName )
140- {
141- for (SavedTimes _item : savedTimesList )
142- {
143- if (_item .getTestName ().equals (testName ))
146+ public int getIndexByName (String testName ) {
147+ for (SavedTimes _item : savedTimesList ) {
148+ if (_item .getTestName ().equals (testName ))
144149 return savedTimesList .indexOf (_item );
145150 }
146151 return -1 ;
@@ -159,8 +164,9 @@ private void logFailed2All(Throwable throwable, TCMessages tcMsgs, String additi
159164 }
160165
161166 /**
162- * For TestNG HTML reports purposes. Without this method it does not display test name provided by getTestName()
163- * ITest interface). For i.e. Intellij IDEA uses name provided by getTestName() .
167+ * For TestNG HTML reports purposes. Without this method it does not display
168+ * test name provided by getTestName() ITest interface). For i.e. Intellij IDEA
169+ * uses name provided by getTestName() .
164170 *
165171 * @param result - test results
166172 */
@@ -178,51 +184,52 @@ public void setResultTestName(ITestResult result) {
178184 log .error (ex );
179185 }
180186 }
181- @ AfterSuite
182- public void displaySavedTimesStatistics (){
187+
188+ @ AfterSuite (enabled = false )
189+ public void displaySavedTimesStatistics () {
183190 savedTimesList .sort (Comparator .comparing (SavedTimes ::getDuration ).reversed ());
184- Map <String , List <SavedTimes >> savedTimesListGrouped =
185- savedTimesList . stream () .collect (Collectors .groupingBy (w -> w .getTestName ()));
191+ Map <String , List <SavedTimes >> savedTimesListGrouped = savedTimesList . stream ()
192+ .collect (Collectors .groupingBy (w -> w .getTestName ()));
186193
187194 CellStyle cs = new CellStyle (CellStyle .HorizontalAlign .left , CellStyle .AbbreviationStyle .crop ,
188195 CellStyle .NullStyle .emptyString );
189- Table t = new Table (5 , BorderStyle .DESIGN_TUBES , ShownBorders
190- .SURROUND_HEADER_AND_COLUMNS , false , "" );
196+ Table t = new Table (5 , BorderStyle .DESIGN_TUBES , ShownBorders .SURROUND_HEADER_AND_COLUMNS , false , "" );
191197 t .addCell ("Test Name" , cs );
192198 t .addCell ("Measure Type" , cs );
193199 t .addCell ("Duration min:s:ms" , cs );
194200 t .addCell ("Compared rows" , cs );
195201 t .addCell ("Status" , cs );
196- int i =0 ;
197202 savedTimesListGrouped .forEach ((String key , List <SavedTimes > value ) -> {
198203 value .forEach ((SavedTimes v ) -> {
199- t .addCell (v .getTestName ().trim (), cs )
200- ;
204+ t .addCell (v .getTestName ().trim (), cs );
201205 t .addCell (v .getMeasureType ().trim (), cs );
202- t .addCell (v .getFormattedDuration ().replace ("min:s:ms" , "" ).trim (), cs )
203- ;
206+ t .addCell (v .getFormattedDuration ().replace ("min:s:ms" , "" ).trim (), cs );
204207 t .addCell (v .getNumberOfComparedRows (), cs );
205208 t .addCell (v .getTestResult ().trim (), cs );
206209 });
207210 });
208- String stringTable = "Statistics of queries execution group by test name(" + savedTimesListGrouped .size () + " rows):\r \n " + t .render ();
211+ String stringTable = "Statistics of queries execution group by test name(" + savedTimesListGrouped .size ()
212+ + " rows):\r \n " + t .render ();
209213 Printer .addReporterLog (stringTable );
210214
211- log .log (Level .OFF , "##teamcity[message '" + stringTable + "']" );
215+ log .log (Level .OFF , "##teamcity[message '" + stringTable + "']" );
212216 log .info (stringTable );
213217
214- Table ts = new Table (3 , BorderStyle .DESIGN_TUBES , ShownBorders
215- .SURROUND_HEADER_AND_COLUMNS , false , "" );
218+ Table ts = new Table (3 , BorderStyle .DESIGN_TUBES , ShownBorders .SURROUND_HEADER_AND_COLUMNS , false , "" );
216219 ts .addCell ("Test Name" , cs );
217220 ts .addCell ("Measure Type" , cs );
218221 ts .addCell ("Duration min:s:ms" , cs );
219- savedTimesList .forEach (s -> {ts .addCell (s .getTestName ().trim (), cs )
220- ;ts .addCell (s .getMeasureType ().trim (), cs );ts .addCell (s .getFormattedDuration ().replace ("min:s:ms" ,"" ).trim (), cs );});
222+ savedTimesList .forEach (s -> {
223+ ts .addCell (s .getTestName ().trim (), cs );
224+ ts .addCell (s .getMeasureType ().trim (), cs );
225+ ts .addCell (s .getFormattedDuration ().replace ("min:s:ms" , "" ).trim (), cs );
226+ });
221227
222- stringTable = "Statistics of queries execution sorted by time execution (" + savedTimesList .size () + " rows):\r \n " + ts .render ();
228+ stringTable = "Statistics of queries execution sorted by time execution (" + savedTimesList .size ()
229+ + " rows):\r \n " + ts .render ();
223230 Printer .addReporterLog (stringTable );
224231
225- log .log (Level .OFF , "##teamcity[message '" + stringTable + "']" );
232+ log .log (Level .OFF , "##teamcity[message '" + stringTable + "']" );
226233 log .info (stringTable );
227234
228235 }
0 commit comments