Skip to content

Commit

Permalink
Add Inline Parameters as new features
Browse files Browse the repository at this point in the history
  • Loading branch information
six42 committed Apr 24, 2017
1 parent 00be4cc commit 822d26a
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,23 @@ The values are separated with a ":".
|c |i:2:4 |

!4 Link this definition to the query with the '''dbQueryParameters''' key
To avoid that the input columns are flageed red (as they are not used in string command replacements) add also the flag '''outputFlagUnusedInputColumns=false'''

!| SQLCommand|TransactionDatabase|select SQRT(?) as root|dbQueryParameters=inParameters outputFlagUnusedInputColumns=false|
!| SQLCommand|TransactionDatabase|select SQRT(?) as root|dbQueryParameters=inParameters|
|No |root? |
|9.0 |3.0 |
|16.0 |4.0 |

!| SQLCommand|TransactionDatabase|select LPAD(?, ?, ?) as myString|dbQueryParameters=inParameters outputFlagUnusedInputColumns=false|
!| SQLCommand|TransactionDatabase|select LPAD(?, ?, ?) as myString|dbQueryParameters=inParameters|
|inStr |c |FILL |myString? |
|xYz |7 |* |****xYz |
|ABC |5 |- |--ABC |

|
!4 Or define the parameters inline in the cmd

!| SQLCommand|TransactionDatabase|select LPAD(?{inStr:12}, ?{c:4}, ?{FILL:12}) as myString|
|inStr |c |FILL |myString? |
|xYz |7 |* |****xYz |
|ABC |5 |- |--ABC |

!*> Rollback the change to not impact future tests

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ For H2 it is better to use select and not call.
|3 |Tom |4567890 |Seoul |Milkman |
|4 |Till |332211 |Berlin |Senator |
|5 |Sarah |999999 |Paris |Hero |
|6 |James |5432 |London |Butler |
|6 |James |#null# |London |Butler |
|7 |Bert |432 |Washington|President |
|8 |Kim |1 |New York |Banker |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
!| SQLCommand|StoredProcedures|
|No |root? |
|16 |4.0 |
|64 |8.0 |


!*> Rollback the change to not impact future tests
Expand All @@ -39,7 +40,7 @@
|3 |Tom |4567890 |Seoul |Milkman |
|4 |Till |332211 |Berlin |Senator |
|5 |Sarah |999999 |Paris |Hero |
|6 |James |#null# |London |Butler |
|6 |James |#null# |London |Butler |
|7 |Bert |432 |Washington|President |
|8 |Kim |1 |New York |Banker |

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
#Copyright (C) 2015 by six42, All rights reserved. Contact the author via http://github.com/six42
#
Unused Input column names like [AGE] below are flagged as fail.
In such a case either the command should be adjusted or the column should be removed.
In such a case either
* the command should be adjusted or
* the column should be removed.
* To avoid that the input columns are flagged red add the flag '''outputFlagUnusedInputColumns=false'''

!include -c .FitNesse.SuiteAcceptanceTests.SuiteSlimTests.SetUp

#!include -c .FitNesse.SuiteAcceptanceTests.SuiteSlimTests.SetUp?raw nix

#!include -h .PlugIns.JdbcSlim.ScenarioLibrary
#!include -raw .PlugIns.JdbcSlim.ScenarioLibrary


#!define SLIM_FLAGS {-v}
!define TestPageName {TestPage}

!| script |
Expand All @@ -32,6 +28,14 @@ In such a case either the command should be adjusted or the column should be rem
|show Symbol |$HTML_Result|
|get collapsed executon log for page|${TestPageName}|

If you must keep the column for any reason
* To avoid that the input columns are flagged red add the flag '''outputFlagUnusedInputColumns=false'''

!|SQLCommand|TestDatabase|select Profession from TestData where NAME= '%NAME%' and CITY= '%CITY%'|outputFlagUnusedInputColumns=false|
|NAME |CITY |AGE |PROFESSION? |
|James |London |43 | |
|Bert |Washington |50 | |
|Kim |New York |60 | |


!include -c .FitNesse.SuiteAcceptanceTests.TearDown
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ To insert leading and trailing Spaces use the '''!-!- Denver -!''''''-!''' synta

!|SQLCommand|TestDatabase|!-insert into TestData
values (DEFAULT, ?, '%Phone%', '%City%', '%Profession%')-!|!-dbgetgeneratedkeys
dbQueryParameters=inParameters
outputFlagUnusedInputColumns=false-!|
dbQueryParameters=inParameters-!|
|SCOPE_IDENTITY()?|City |Name|Phone|Profession|Count?|
|$ID1= |Berlin|#null#|12345| |1 |
|$ID2= |!- Denver-!|!-Bob -! |6789 | |1 |
Expand Down Expand Up @@ -42,8 +41,7 @@ if you must insert the string #null# in the database you can define a different
|City |I:2:12:0 |

!|SQLCommand|TestDatabase|update TestData set Name = ?, City = ? where ID ='%ID%'| !-inputNullString=--null--
dbQueryParameters=inParameters
outputFlagUnusedInputColumns=false-!|
dbQueryParameters=inParameters-!|
|ID|City|Name|Count?|
|$ID1 |--null--|#null#|1|

Expand Down
7 changes: 7 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<include name="csvjdbc-1.0-18.jar"/>
<include name="fitnesse-standalone.jar"/>
<include name="dbfit-core-3.2.0.jar"/>
<include name="junit-4.12.jar"/>
</fileset>
</path>

Expand Down Expand Up @@ -81,6 +82,12 @@
<arg value="PlugIns.JdbcSlim.UserGuide?suite&amp;format=xml" />
</java>
</target>
<target name="acceptance_tests_html" depends="jar">
<java jar="${dist.dir}/fitnesse-standalone.jar" failonerror="true" fork="true" output="fitnesse-results.html">
<arg value="-c" />
<arg value="PlugIns.JdbcSlim.UserGuide?suite&amp;format=html" />
</java>
</target>
<target name="set-version-if-not-manualy-set" unless="version">
<tstamp />
<property name="version" value="${DSTAMP}" />
Expand Down
46 changes: 25 additions & 21 deletions src/main/java/six42/fitnesse/jdbcslim/HeaderLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
package six42.fitnesse.jdbcslim;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -102,25 +104,29 @@ static public boolean hasHeaderParameters(List<String> Header){
}

static public List<String> formatHeader(List<String> originalExpectedHeader, List<String> resultHeader) {
return formatHeader(originalExpectedHeader, resultHeader, "", "", "", null);
return formatHeader(originalExpectedHeader, resultHeader,
new HashSet<String>(), "", null);

}

/***
* Checks that each parameter given in the header exists in the command, flag them as fail if not
* Marks all Header columns which are new in the actual and don't exist in the expected
* Mark Input Columns green if they have been used
*
/***
* Checks that each parameter given in the header exists in the command, flag
* them as fail if not Marks all Header columns which are new in the actual
* and don't exist in the expected Mark Input Columns green if they have been
* used
*
* TODO check also that the order of the Header columns is matching the output
*
* @param originalExpectedHeader
* @param resultHeader
* @param rawCommand
* @param pre_fix
* @param post_fix
* @param properties
* @return
*/
static public List<String> formatHeader(List<String> originalExpectedHeader, List<String> resultHeader, String rawCommand, String pre_fix, String post_fix, PropertiesInterface properties) {
* @param resultHeader
* @param usedHeaderColumns
* @param rawCommand
* @param properties
* @return
*/
public static List<String> formatHeader(List<String> originalExpectedHeader,
List<String> resultHeader, Set<String> usedHeaderColumns,
String rawCommand, PropertiesInterface properties) {


List<String> result = new ArrayList<String>();
Expand All @@ -140,12 +146,12 @@ static public List<String> formatHeader(List<String> originalExpectedHeader, Lis
}
else if (isOutputColumn(resultHeader.get(p)) || isCommentColumn(resultHeader.get(p))|| rawCommand.isEmpty()){
Cell = "report:" + resultHeader.get(p);

}
else if(flagUnused && !rawCommand.contains(pre_fix + resultHeader.get(p) + post_fix)){
Cell = "fail:" + resultHeader.get(p);
} else if (usedHeaderColumns.contains(HeaderLine.plainColumnName(
resultHeader.get(p)).toLowerCase())) {
Cell = "pass:" + resultHeader.get(p);
}else{
Cell = "pass:" + resultHeader.get(p);
Cell = flagUnused ? "fail:" : "ignore:";
Cell = Cell + resultHeader.get(p);
}
result.add( Cell);
}
Expand Down Expand Up @@ -186,6 +192,4 @@ static public int[] mapActualHeaderToExpectedHeader(List<String> expected, List<
}
return result;
}


}
9 changes: 7 additions & 2 deletions src/main/java/six42/fitnesse/jdbcslim/JdbcAuthenticator.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
Expand Down Expand Up @@ -162,8 +163,12 @@ public Response makeResponse(FitNesseContext context, Request request) {
page.addTitles("401 Unauthorized");
page.put("resource", request.getResource());
page.setMainTemplate("unauthorized.vm");
response.setContent(page.html());

try {
response.setContent(page.html());
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return response;
}
}
Expand Down
27 changes: 18 additions & 9 deletions src/main/java/six42/fitnesse/jdbcslim/PropertiesLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ private boolean checkKeyForCommandAndExecute(String key, String value,
crypto = null;
}else{
crypto = CryptoFactories.getCryptoServiceFactory().getCryptoService(CryptoFactories.getCryptoKeyStoreFactory().newInstance(new File(value)));
System.out.println("New Key Store Location " + value);
if (isDebug())
System.out.println("New Key Store Location " + value);
}
return true;
}
Expand Down Expand Up @@ -354,7 +355,8 @@ public Properties toProperties() {
* @param propertyName
* @return
*/
public String getSecretProperty(String propertyName) {
@Override
public String getSecretProperty(String propertyName) {

String result = getPropertyOrDefault(secretTag+propertyName, null);
if (result == null){
Expand All @@ -363,37 +365,44 @@ public String getSecretProperty(String propertyName) {
return result;
}

public String getSecretProperty(ConfigurationParameters dbpassword){
@Override
public String getSecretProperty(ConfigurationParameters dbpassword){
return getSecretProperty(dbpassword.toString());
}

public String getProperty(String propertyName) {
@Override
public String getProperty(String propertyName) {
return getPropertyOrDefault(propertyName, null);
}

public String getProperty(ConfigurationParameters propertyName){
@Override
public String getProperty(ConfigurationParameters propertyName){
return getProperty(propertyName.toString());
}

public String getPropertyOrDefault(String propertyName, String defaultValue) {
@Override
public String getPropertyOrDefault(String propertyName, String defaultValue) {
String propertyValue = myProperties.get(propertyName.toLowerCase());
if (propertyValue == null) propertyValue =defaultValue;
return propertyValue;
}

public String getPropertyOrDefault(ConfigurationParameters propertyName, String defaultValue) {
@Override
public String getPropertyOrDefault(ConfigurationParameters propertyName, String defaultValue) {
return getPropertyOrDefault(propertyName.toString(), defaultValue);
}

public boolean isDebug(){
@Override
public boolean isDebug(){
return debugFlag;
}

private void setDebugFromProperties(){
debugFlag = getBooleanPropertyOrDefault(ConfigurationParameters.DEBUG, false);
}

public PropertiesLoader getSubProperties(String subPropertyName){
@Override
public PropertiesLoader getSubProperties(String subPropertyName){
PropertiesLoader subParameters = null;
subParameters = new PropertiesLoader();
try {
Expand Down
Loading

0 comments on commit 822d26a

Please sign in to comment.