Skip to content

Commit

Permalink
Added Example with ALIAS usage
Browse files Browse the repository at this point in the history
  • Loading branch information
six42 committed Sep 28, 2015
1 parent c3c4191 commit 1208aca
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#Copyright (C) 2015 by six42, All rights reserved. Contact the author via http://github.com/six42
#
!|Define Properties|FindTestUserIDs |
|key |value |
|.include |TransactionDatabase |
|cmd |select ID, NAME from TestData where Name ='%NAME%'|

!|Define Properties|CheckInitalCityOfUsers |
|key |value |
|.include |TransactionDatabase |
|cmd |select City from TestData where ID ='%ID%'|

!|Define Properties|RelocateUserToNewCity |
|key |value |
|.include |TransactionDatabase |
|cmd |update TestData set City='%NewCITY%' where ID ='%ID%'|

!|Define Properties|CheckFinalCityOfUsers |
|key |value |
|.include |TransactionDatabase |
|cmd |select City from TestData where ID ='%ID%'|


!|Script|SQLCommand|FindTestUserIDs|
|$FTU= |get fixture |

!|Define alias |
|find test users|table: $FTU|

!|Script|SQLCommand|CheckInitalCityOfUsers|
|$CICoU=|get fixture |

!|Define alias |
|check first city of users|table: $CICoU|

!|Script|SQLCommand|RelocateUserToNewCity|
|$RUTNC=|get fixture |

!|Define alias |
|relocate users|table: $RUTNC|

!|Script|SQLCommand|CheckFinalCityOfUsers|
|$CFCoU=|get fixture |

!|Define alias |
|Check city after relocation|table: $CFCoU|



To avoid side effects we execute the test in a transaction
!|Script|SQLCommand|TransactionDatabase|
|open Connection |
|execute|begin transaction |
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<properties>
<Edit>true</Edit>
<Files>true</Files>
<LastModifyingUser>six42</LastModifyingUser>
<Properties>true</Properties>
<RecentChanges>true</RecentChanges>
<Refactor>true</Refactor>
<Search>true</Search>
<Versions>true</Versions>
<WhereUsed>true</WhereUsed>
</properties>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#Copyright (C) 2015 by six42, All rights reserved. Contact the author via http://github.com/six42
#
!3 Rollback the change to not impact future tests

!|Script|SQLCommand|TransactionDatabase|debug|
|open Connection |
|execute|rollback |
|close Connection |

!4 Check that the rollback worked
!| SQLCommand|TransactionDatabase|select City from TestData where ID ='%ID%'|
|ID |CITY? |
|$TestID |Denver |
|$TestID2 |Paris |
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<properties>
<Edit>true</Edit>
<Files>true</Files>
<Help/>
<Properties>true</Properties>
<RecentChanges>true</RecentChanges>
<Refactor>true</Refactor>
<Search>true</Search>
<Suites/>
<Versions>true</Versions>
<WhereUsed>true</WhereUsed>
</properties>
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,50 @@ Requirements should not contain SQL code:

This can be achieved easily with JdbcSlim.

Lets rewrite the first example with Tom and Sarah but write it in less technical terms.
Lets rewrite the first example with Ben and Sarah but write it in less technical terms.
The SQL Code can be moved into a seperate SetUp page.

!include -c >SqlSetUp


!3 1 Preparing test data

Find the ID of users named Ben and Sarah which should move.
We store the Id of the users in a Slim Symbol '$TestID' for future reference.

!|Script|SQLCommand|CheckInitalCityOfUsers|
|$CICoU=|get fixture |

!|Define alias |
|Check First City Of Users|$CICoU|


!| SQLCommand|FindTestUserIDs|
|ID? |NAME |
|$TestID= |Ben |
|$TestID2= |Sarah |
!|find test users|
|ID? |NAME |
|$TestID= |Ben |
|$TestID2= |Sarah|

Before we proceed we validate that Ben and Sarah still live in the old Cities: Denver and Paris

!| Check First City Of Users|
|ID |CITY? |
|$TestID |Denver |
|$TestID2 |Paris |
!|check first city of users|
|ID |CITY? |
|$TestID |Denver |
|$TestID2 |Paris |

!| SQLCommand|CheckInitalCityOfUsers|
|ID |CITY? |
|$TestID |Denver |
|$TestID2 |Paris |

!3 Execution some business functions
!3 2 Execution some business functions

Here calls to your business code will go.
A simple update statement which can do the job is given below.
!| SQLCommand|RelocateUserToNewCity|
|ID |NewCITY |
|$TestID |HongKong |
|$TestID2 |Tokyo |
!|relocate users |
|ID |NewCITY |Count?|
|$TestID |HongKong|1 |
|$TestID2|Tokyo |1 |


!3 Validating the impact on the test data
!3 3 Validating the impact on the test data

Finally we check that Ben now lives in Hong Kong and Sarah in Tokyo

!| SQLCommand|CheckFinalCityOfUsers|
|ID |CITY? |
|$TestID |HongKong |
|$TestID2 |Tokyo |
!|Check city after relocation|
|ID |CITY? |
|$TestID |HongKong |
|$TestID2 |Tokyo |

!include -c >SqlTearDown

!contents -R2 -g -p -f -h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
<properties>
<Edit/>
<Files/>
<Help>TODO</Help>
<Help>Requirements without any visible SQL</Help>
<LastModifyingUser>six42</LastModifyingUser>
<Properties/>
<Prune/>
<RecentChanges/>
<Refactor/>
<Search/>
Expand Down

0 comments on commit 1208aca

Please sign in to comment.