PlugIns.JdbcSlim.UserGuide.1ASimpleExample.SeparatingSqlCommandsAndRequirements

PlugIns JdbcSlim UserGuide 1ASimpleExample



Requirements should not contain SQL code:


This can be achieved easily with Jdbc Slim.

Lets rewrite the first example with Ben and Sarah but write it in less technical terms.
The SQL Code can be moved into a separate 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%'

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.

SQLCommand FindTestUserIDs
ID? NAME
$TestID= Ben
$TestID2= Sarah

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

SQLCommand CheckInitalCityOfUsers
ID CITY?
$TestID Denver
$TestID2 Paris

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 Count?
$TestID HongKong 1
$TestID2 Tokyo 1


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

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: