@@ -62,14 +62,17 @@ public class TestVerifier {
62
62
63
63
public enum TestStatus {
64
64
PENDING , RUNNING , PASS , EXECUTION_FAILURE , VERIFICATION_FAILURE , ORDER_MISMATCH , TIMEOUT ,
65
- CANCELED
65
+ CANCELED , ORDERBY_FAILURE
66
66
};
67
67
68
68
public TestVerifier (List <Integer > types , String query , List <String > columnLabels , List <String > verificationType ) {
69
69
this .types = types ;
70
70
this .query = query ;
71
71
this .columnLabels = columnLabels ;
72
72
this .verificationTypes = verificationType ;
73
+ if (verificationType .get (0 ).equalsIgnoreCase ("text" )) {
74
+ this .checkType = false ;
75
+ }
73
76
}
74
77
75
78
public TestVerifier () {
@@ -90,7 +93,7 @@ public TestVerifier() {
90
93
*/
91
94
public TestStatus verifySqllineResult (String expectedOutput ,
92
95
String actualOutput , boolean verifyOrderBy ) throws IOException , VerificationException ,
93
- IllegalAccessException {
96
+ IllegalAccessException , OrderbyException {
94
97
String cleanedUpFile = cleanUpSqllineOutputFile (actualOutput );
95
98
return verifyResultSet (expectedOutput , cleanedUpFile , verifyOrderBy );
96
99
}
@@ -128,7 +131,7 @@ private String cleanUpSqllineOutputFile(String actualOutput) throws IOException
128
131
* @throws Exception
129
132
*/
130
133
public TestStatus verifyResultSet (String expectedOutput , String actualOutput )
131
- throws IllegalAccessException , IOException , VerificationException {
134
+ throws IllegalAccessException , IOException , VerificationException , OrderbyException {
132
135
return verifyResultSet (expectedOutput , actualOutput , false );
133
136
}
134
137
@@ -146,7 +149,7 @@ public TestStatus verifyResultSet(String expectedOutput, String actualOutput)
146
149
* @throws Exception
147
150
*/
148
151
public TestStatus verifyResultSet (String expectedOutput , String actualOutput , boolean verifyOrderBy )
149
- throws IOException , VerificationException , IllegalAccessException {
152
+ throws IOException , VerificationException , IllegalAccessException , OrderbyException {
150
153
if (testStatus == TestStatus .EXECUTION_FAILURE
151
154
|| testStatus == TestStatus .CANCELED ) {
152
155
return testStatus ;
@@ -540,15 +543,15 @@ private static class IndexAndOrder {
540
543
*/
541
544
public TestStatus verifyResultSetOrders (String filename ,
542
545
List <String > columnLabels , Map <String , String > orderByColumns )
543
- throws IOException , VerificationException , IllegalAccessException {
546
+ throws IOException , VerificationException , IllegalAccessException , OrderbyException {
544
547
loadFromFileToMap (filename , true );
545
548
List <IndexAndOrder > columnIndexAndOrder = getColumnIndexAndOrderList (
546
549
columnLabels , orderByColumns , true );
547
550
// if one or more order-by columns is not present in the result set,
548
551
// then skip this part of the verification.
549
552
if (columnIndexAndOrder == null ) {
550
553
LOG .debug ("skipping order verification" );
551
- return TestStatus . PASS ;
554
+ throw new OrderbyException ( "Order mismatch " ) ;
552
555
}
553
556
if (!isOrdered (columnIndexAndOrder , orderByColumns )) {
554
557
LOG .info ("\n Order mismatch in actual result set." );
@@ -558,7 +561,7 @@ public TestStatus verifyResultSetOrders(String filename,
558
561
}
559
562
560
563
private Map <Integer , String > getColumnIndexAndOrder (
561
- List <String > columnLabels , Map <String , String > orderByColumns ) {
564
+ List <String > columnLabels , Map <String , String > orderByColumns ) throws OrderbyException {
562
565
List <IndexAndOrder > result = getColumnIndexAndOrderList (columnLabels ,
563
566
orderByColumns , false );
564
567
if (result == null ) {
@@ -586,7 +589,7 @@ private Map<Integer, String> getColumnIndexAndOrder(
586
589
*/
587
590
private List <IndexAndOrder > getColumnIndexAndOrderList (
588
591
List <String > columnLabels , Map <String , String > orderByColumns ,
589
- boolean checkForFields ) {
592
+ boolean checkForFields ) throws OrderbyException {
590
593
List <IndexAndOrder > columnIndexAndOrder = new ArrayList <IndexAndOrder >();
591
594
List <Integer > indicesOfOrderByColumns = getIndicesOfOrderByColumns (
592
595
columnLabels , orderByColumns , checkForFields );
@@ -603,7 +606,7 @@ private List<IndexAndOrder> getColumnIndexAndOrderList(
603
606
}
604
607
605
608
private List <Integer > getIndicesOfOrderByColumns (
606
- List <String > columnLabels , Map <String , String > orderByColumns ) {
609
+ List <String > columnLabels , Map <String , String > orderByColumns ) throws OrderbyException {
607
610
return getIndicesOfOrderByColumns (columnLabels , orderByColumns , false );
608
611
}
609
612
@@ -621,7 +624,7 @@ private List<Integer> getIndicesOfOrderByColumns(
621
624
private List <Integer > getIndicesOfOrderByColumns (
622
625
List <String > columnLabels ,
623
626
Map <String , String > orderByColumns ,
624
- boolean checkForFields ) {
627
+ boolean checkForFields ) throws OrderbyException {
625
628
List <Integer > indices = new ArrayList <Integer >();
626
629
for (Map .Entry <String , String > entry : orderByColumns .entrySet ()) {
627
630
String entryKey = entry .getKey ();
@@ -631,10 +634,10 @@ private List<Integer> getIndicesOfOrderByColumns(
631
634
}
632
635
// verify that each order by column is present in the result set by
633
636
// checking columnLabels, which represents the columns in the result set.
634
- // if an order by column is not in the result set, return null.
637
+ // if an order by column is not in the result set, throw OrderbyException
635
638
int index = columnLabels .indexOf (entryKey );
636
639
if (index < 0 ) {
637
- return null ;
640
+ throw new OrderbyException ( "Order by key " + entryKey + " is not projected." ) ;
638
641
}
639
642
indices .add (index );
640
643
}
@@ -832,6 +835,23 @@ private static boolean matchAndCompareAll(String actual, String expected) {
832
835
return true ;
833
836
}
834
837
838
+ public TestStatus verifyText (String expectedOutput ,
839
+ String actualOutput ) throws IOException , VerificationException {
840
+ if (testStatus == TestStatus .EXECUTION_FAILURE
841
+ || testStatus == TestStatus .CANCELED ) {
842
+ return testStatus ;
843
+ }
844
+ String expected = new String (Files .readAllBytes (Paths .get (expectedOutput )));
845
+ String actual = new String (Files .readAllBytes (Paths .get (actualOutput )));
846
+ if (!expected .equals (actual )) {
847
+ StringBuilder sb = new StringBuilder ();
848
+ sb .append ("\n Expected and Actual output are different.\n " );
849
+ throw new VerificationException (sb .toString ());
850
+ } else {
851
+ return TestStatus .PASS ;
852
+ }
853
+ }
854
+
835
855
/**
836
856
* Create a map containing the names of the columns in the order-by clause and
837
857
* whether they are being ordered in ascending or descending order.
@@ -915,4 +935,11 @@ public VerificationException(String message) {
915
935
super (message );
916
936
}
917
937
}
938
+
939
+ public static class OrderbyException extends Exception {
940
+
941
+ public OrderbyException (String message ) {
942
+ super (message );
943
+ }
944
+ }
918
945
}
0 commit comments