-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from six42/emptyRs
Fix #39 Empty SQLCommand result ends in IndexOutOfBoundsException
- Loading branch information
Showing
7 changed files
with
158 additions
and
80 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
FitNesseRoot/PlugIns/JdbcSlim/UserGuide/6OutputOptions/ExceptionHandling.wiki
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
Test | ||
--- | ||
#Copyright (C) 2015-202 by six42, All rights reserved. Contact the author via http://github.com/six42 | ||
# | ||
1 Empty result sets are displayed correctly | ||
2 An exception during execution is displayed with raw result information | ||
!include -c .FitNesse.SuiteAcceptanceTests.SuiteSlimTests.SetUp | ||
|
||
!define TestPageName {TestPage} | ||
|
||
!| script | | ||
|given Jdbc Slim test page|${TestPageName}| | ||
|and test content is |!- | ||
|
||
1 | ||
|
||
!|SQLCommand|TestDatabase|select ID,Name from TestData where Name in('notThere', 'unknown')|SORT | | ||
|ID?|NAME?>| | ||
|1|notThere| | ||
|2|unknown| | ||
|
||
2 | ||
|
||
!|SQLCommand|TestDatabase|select ID,Name from TestData where Name in('notThere', 'unknown')|SORT dbOnlyRowCount=RowCount dbPerf=ProcessingTime| | ||
|ID?|NAME?>| | ||
|1|notThere| | ||
|2|unknown| | ||
|
||
-! | | ||
|when page|${TestPageName}| is tested and HTML is extracted| | ||
|then |\d | assertions pass, | 5| fail, | 0| are ignored | 1 | exceptions thrown| | ||
|and cell |\[-\]notThere | has result | fail| | ||
|and cell |The actual result has no column with the same name as expected column: 1.Result: \[\[RowCount, ProcessingTime\], \[0, 0.0..\]\]| has result | error| | ||
|show Symbol |$HTML_Input| | ||
|show Symbol |$HTML_Result| | ||
|get collapsed executon log for page|${TestPageName}| | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
!include -c .FitNesse.SuiteAcceptanceTests.TearDown |
22 changes: 22 additions & 0 deletions
22
FitNesseRoot/PlugIns/JdbcSlim/UserGuide/6OutputOptions/Sorting/EmptyResults.wiki
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
Test | ||
--- | ||
#Copyright (C) 2020 by six42, All rights reserved. Contact the author via http://github.com/six42 | ||
# | ||
|
||
!3 A query can only return a header and no data in a script | ||
|
||
!|script:SQLCommand|TestDatabase| | ||
|run| select ID,Name from TestData where Name in('notThere', 'unknown')| | ||
|check| raw result|[[ID, NAME]]| | ||
|check| result sheet|[[ID, NAME]]| | ||
|check|getRowCount|0| | ||
|
||
!3 A query can only return a header and no data in a decision table | ||
|
||
!|SQLCommand|TestDatabase|select ID,Name from TestData where Name in('notThere', 'unknown')|SORT| | ||
|ID?|NAME?>| | ||
|=~/\A\z/|=~/\A\z/| | ||
|
||
!contents -R2 -g -p -f -h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 72 additions & 68 deletions
140
src/main/java/six42/fitnesse/jdbcslim/StringListComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,86 @@ | ||
// Copyright (C) 2015 by six42, All rights reserved. Contact the author via http://github.com/six42 | ||
// Copyright (C) 2015-2020 by six42, All rights reserved. Contact the author via http://github.com/six42 | ||
package six42.fitnesse.jdbcslim; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.ArrayList; | ||
|
||
|
||
public class StringListComparator implements Comparator<List<String>> { | ||
|
||
private List<HeaderCell> _SortKeys1; | ||
private List<HeaderCell> _SortKeys2; | ||
|
||
public StringListComparator(){ | ||
_SortKeys1 = new ArrayList<HeaderCell>(); | ||
_SortKeys2 = new ArrayList<HeaderCell>(); | ||
} | ||
public StringListComparator(List<HeaderCell> SortKeys){ | ||
_SortKeys1 = SortKeys; | ||
_SortKeys2 = SortKeys; | ||
} | ||
public StringListComparator(List<HeaderCell> SortKeys1, List<HeaderCell> SortKeys2){ | ||
_SortKeys1 = SortKeys1; | ||
_SortKeys2 = SortKeys2; | ||
} | ||
private List<HeaderCell> _SortKeys1; | ||
private List<HeaderCell> _SortKeys2; | ||
|
||
@Override | ||
public int compare(List<String> a1, List<String> a2) { | ||
int r =0; | ||
for (int i=0; i < _SortKeys1.size(); i++){ | ||
String aStr1 = a1.get(_SortKeys1.get(i).getSortIndex()-1); | ||
String aStr2 = a2.get(_SortKeys2.get(i).getSortIndex()-1); | ||
int sortDirection = _SortKeys1.get(i).getSortDirection(); | ||
// treat two null as equal | ||
if (aStr1 == null && aStr2 == null){ | ||
r=0; | ||
continue; | ||
} | ||
// One side null | ||
if(aStr1 == null){ | ||
r=-1*sortDirection; | ||
break; | ||
} | ||
if(aStr2 == null){ | ||
r=1*sortDirection; | ||
break; | ||
} | ||
if ("d".equalsIgnoreCase(_SortKeys1.get(i).getSortType())){ | ||
try{ | ||
Long aL1 = Long.parseLong(aStr1); | ||
Long aL2 = Long.parseLong(aStr2); | ||
r= aL1.compareTo(aL2); | ||
}catch (NumberFormatException e){ | ||
System.out.println("Failed to convert to Long: '" + aStr1 + "' '" + aStr2 + "'"); | ||
e.printStackTrace(); | ||
r= aStr1.compareTo(aStr2); | ||
} | ||
} | ||
else if ("f".equalsIgnoreCase(_SortKeys1.get(i).getSortType())){ | ||
try{ | ||
Double aD1 = Double.parseDouble(aStr1); | ||
Double aD2 = Double.parseDouble(aStr2); | ||
r= aD1.compareTo(aD2); | ||
}catch (NumberFormatException e){ | ||
System.out.println("Failed to convert to Double: '" + aStr1 + "' '" + aStr2 + "'"); | ||
e.printStackTrace(); | ||
r= aStr1.compareTo(aStr2); | ||
} | ||
public StringListComparator() { | ||
_SortKeys1 = new ArrayList<HeaderCell>(); | ||
_SortKeys2 = new ArrayList<HeaderCell>(); | ||
} | ||
|
||
public StringListComparator(List<HeaderCell> SortKeys) { | ||
_SortKeys1 = SortKeys; | ||
_SortKeys2 = SortKeys; | ||
} | ||
|
||
public StringListComparator(List<HeaderCell> SortKeys1, | ||
List<HeaderCell> SortKeys2) { | ||
_SortKeys1 = SortKeys1; | ||
_SortKeys2 = SortKeys2; | ||
} | ||
|
||
@Override | ||
public int compare(List<String> a1, List<String> a2) { | ||
int r = 0; | ||
for (int i = 0; i < _SortKeys1.size(); i++) { | ||
int sortIndex1 = _SortKeys1.get(i).getSortIndex() - 1; | ||
int sortIndex2 = _SortKeys2.get(i).getSortIndex() - 1; | ||
String aStr1 = sortIndex1 < a1.size() ? a1.get(sortIndex1) : null; | ||
String aStr2 = sortIndex2 < a2.size() ? a2.get(sortIndex2) : null; | ||
int sortDirection = _SortKeys1.get(i).getSortDirection(); | ||
// treat two null as equal | ||
if (aStr1 == null && aStr2 == null) { | ||
r = 0; | ||
continue; | ||
} | ||
// One side null | ||
if (aStr1 == null) { | ||
r = -1 * sortDirection; | ||
break; | ||
} | ||
if (aStr2 == null) { | ||
r = 1 * sortDirection; | ||
break; | ||
} | ||
if ("d".equalsIgnoreCase(_SortKeys1.get(i).getSortType())) { | ||
try { | ||
Long aL1 = Long.parseLong(aStr1); | ||
Long aL2 = Long.parseLong(aStr2); | ||
r = aL1.compareTo(aL2); | ||
} catch (NumberFormatException e) { | ||
System.out.println("Failed to convert to Long: '" + aStr1 + "' '" | ||
+ aStr2 + "'"); | ||
e.printStackTrace(); | ||
r = aStr1.compareTo(aStr2); | ||
} | ||
else{ | ||
r= aStr1.compareTo(aStr2); | ||
} else if ("f".equalsIgnoreCase(_SortKeys1.get(i).getSortType())) { | ||
try { | ||
Double aD1 = Double.parseDouble(aStr1); | ||
Double aD2 = Double.parseDouble(aStr2); | ||
r = aD1.compareTo(aD2); | ||
} catch (NumberFormatException e) { | ||
System.out.println("Failed to convert to Double: '" + aStr1 + "' '" | ||
+ aStr2 + "'"); | ||
e.printStackTrace(); | ||
r = aStr1.compareTo(aStr2); | ||
} | ||
} else { | ||
r = aStr1.compareTo(aStr2); | ||
} | ||
|
||
r = r*sortDirection; | ||
r = r * sortDirection; | ||
|
||
if (r != 0){ | ||
break; | ||
} | ||
} | ||
return r; | ||
} | ||
if (r != 0) { | ||
break; | ||
} | ||
} | ||
return r; | ||
} | ||
} |
1867dd2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dear six42,
I'm currently also in the proces of setting up a FitNesse instance together with your JdbcSlim solution for database testing. However I'm getting stuck on the installation page at the end, as you state: "!2 To build your own test pages 1. include this page on the root page of your suite 2. include the SuiteSetup page or a page with similar content in the setup of your suite" What page do you mean at point 1, with 'this page'? And do you have an example (screenshot or something alike) of both point 1 and 2, the root page and the SuiteSetup page regarding the content needed?
Thanks in advance!
You can always reach me on: [email protected]
Regards,
Michael Klijn
1867dd2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @michaelklijn, you commented on a (closed) pull request. Can you please open an issue to get help from there?