PlugIns JdbcSlim UserGuide 1ASimpleExample
Requirements should not contain SQL code:
- Not everybody understands SQL commands. But you want that the requirements can be understood by anybody.
- The SQL Code can change if a different implementation is chosen. But the requirements should not change in this case. They should be independent of the implementation.
This can be achieved easily with JdbcSlim[?].
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.
Included page: >SqlSetUp
| 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 | |
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.
| 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 |
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.
| relocate users | ||
| ID | NewCITY | Count? |
| $TestID | HongKong | 1 |
| $TestID2 | Tokyo | 1 |
3 Validating the impact on the test data
Finally we check that Ben now lives in Hong Kong and Sarah in Tokyo
| Check city after relocation | |
| ID | CITY? |
| $TestID | HongKong |
| $TestID2 | Tokyo |
Included page: >SqlTearDown
Rollback the change to not impact future tests
| Script | SQLCommand | TransactionDatabase | debug |
| open Connection | |||
| execute | rollback | ||
| close Connection | |||
Check that the rollback worked
| SQLCommand | TransactionDatabase | select City from TestData where ID ='%ID%' |
| ID | CITY? | |
| $TestID | Denver | |
| $TestID2 | Paris | |
Contents: