-
Notifications
You must be signed in to change notification settings - Fork 11
/
JdbcSlim.htm
5342 lines (5313 loc) · 153 KB
/
JdbcSlim.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>JdbcSim Documentation</title>
<link rel="shortcut icon" type="image/png" href="http://fitnesse.org/files/fitnesse/images/favicon.png">
<link rel="stylesheet" type="text/css" href="http://fitnesse.org/files/fitnesse/css/fitnesse_wiki.css" />
<link rel="stylesheet" type="text/css" href="http://fitnesse.org/files/fitnesse/css/fitnesse_pages.css" />
<link rel="stylesheet" type="text/css" href="http://fitnesse.org/files/fitnesse/wysiwyg/wysiwyg.css" media="screen"/>
<link rel="stylesheet" type="text/css" href="http://fitnesse.org/files/fitnesse/bootstrap/css/fitnesse-bootstrap.css">
<link rel="stylesheet" type="text/css" href="http://fitnesse.org/files/fitnesse/question.mark/question.mark.css" />
<script src="http://fitnesse.org/files/fitnesse/javascript/jquery-1.11.3.min.js" type="text/javascript"></script>
<script src="http://fitnesse.org/files/fitnesse/javascript/fitnesse.js" type="text/javascript"></script>
<script src="http://fitnesse.org/files/fitnesse/bootstrap/js/bootstrap.js" type="text/javascript"></script>
<script src="http://fitnesse.org/files/fitnesse/bootstrap/js/respond.js" type="text/javascript"></script>
</head>
<body class="testPage">
<article>
<div class="alternating_block"><br><h1 id="test-summaries">Jdbc Slim</h1>
<br><a href="#JdbcSlim">JdbcSlim</a> is the framework to easily integrate database queries and commands into Slim <span class="fitnesse">FitNesse</span> testing.<br>The design focuses to keep configuration data, test data and SQL code separate. <br>This ensures that requirements are written independent of the implementation and understandable by business users.<br><br>The framework can be used by Developers, Testers and Business Users with SQL knowledge. <br><br><a href="#JdbcSlim">JdbcSlim</a> is agnostic of database system specifics and has no code special to any database system. <br>Such things should be handled by the jdbc driver. <br>Nevertheless
the jdbc code is segregated from the slim code and adding any driver
specific requirements can be done by simply changing a single class.<br><br><div class="contents">
<b>Contents:</b>
<ul class="toc1">
<li>
<a href="#JdbcSlim.Installation" class="static">Installation</a>
</li>
<li>
<a href="#JdbcSlim.UserGuide" class="test">User Guide +</a>
<ul class="toc2">
<li>
<a href="#JdbcSlim.UserGuide.1ASimpleExample" class="test">1 A Simple Example +</a>
... </li>
<li>
<a href="#JdbcSlim.UserGuide.2KeyBenefits.1WaitingForAsynchronousResults" class="suite">2 Key Benefits *</a>
<span class="pageHelp">: More examples which showscase the benefit of jdbcSlim</span>
... </li>
<li>
<a href="#JdbcSlim.UserGuide.3HowtoConfigureTheDatabaseConnection" class="test">3 Howto Configure The Database Connection +</a>
... </li>
<li>
<a href="#JdbcSlim.UserGuide.4TheMappingBetweenTestDataAndCommands" class="test">4 The Mapping Between Test Data And Commands +</a>
... </li>
<li>
<a href="#JdbcSlim.UserGuide.5ParametersOfTheSQLCommand" class="test">5 Parameters Of The S Q L Command +</a>
</li>
<li>
<a href="#JdbcSlim.UserGuide.6OutputOptions" class="test">6 Output Options +</a>
... </li>
<li>
<a href="#JdbcSlim.UserGuide.7UsingSqlInScriptsAndScenarios" class="test">7 Using Sql In Scripts And Scenarios +</a>
... </li>
<li>
<a href="#JdbcSlim.UserGuide.9NullTrailingSpacesAndEmptyStrings" class="test">9 Null Trailing Spaces And Empty Strings +</a>
</li>
<li>
<a href="#JdbcSlim.UserGuide.JdbcAuthenticator" class="test">Jdbc Authenticator +</a>
</li>
</ul>
</li>
<li>
<a href="#JdbcSlim.XIReferenceSheet" class="test">X I Reference Sheet +</a>
<span class="pageHelp">: Summary of all flags and commands</span>
</li>
</ul>
</div>
<br><br><div class="collapsible open" id="JdbcSlim.Installation"><ul><li><a href="#" class="expandall">Expand</a></li><li><a href="#" class="collapseall">Collapse</a></li></ul>
<p class="title">Included page: <a href="#JdbcSlim.Installation">>Installation</a> <a href="#JdbcSlim.Installation?edit&redirectToReferer=true&redirectAction=" class="edit"></a></p>
<div><h2>Download the latest Jdbc Slim library from github.com\six42\jdbcslim</h2>
<span class="meta">variable defined: JdbcSlimLib=jdbcslim.jar</span>
<br><br><h2>Installation Path</h2>
Adujust the below path if you installed at a different location<br>This path is relative to the folder in which <span class="fitnesse">FitNesse</span> got started <br><span class="meta">variable defined: LibInstallPath=plugins\jdbcslim\</span>
<br><br>The Jdbc Slim Library - always required<br><span class="meta">classpath: plugins\jdbcslim\jdbcslim.jar</span><br><br><h2>Further dependencies</h2>
This is required to support encryption. It can be downloaded from <a href="https://github.com/dbfit/dbfit/releases/tag/v3.2.0">https://github.com/dbfit/dbfit/releases/tag/v3.2.0</a><br><span class="meta">classpath: plugins\jdbcslim\commons-codec-1.9.jar</span><br><span class="meta">classpath: plugins\jdbcslim\dbfit-core-3.2.0.jar</span><br><br>See the <a href="#JdbcSlim.SuiteSetup">SuiteSetup</a> pages for driver specific setup. <br>JDBC driver used for the samples. Not required if you use a different JDBC driver<br>plugins\jdbcslim\h2-1.4.188.jar<br>plugins\jdbcslim\csvjdbc-1.0-18.jar<br><br><h2>User Manual and Test Suite</h2>
To access the user manual and run the examples copy all Jdbc Slim Fitnesse pages from github to FitNesseRoot\PlugIns<br>Copy from github the folder plugins\jdbcslim\TestDB to plugins\jdbcslim\TestDB in your installation<br><span class="meta">variable defined: TestDbPath=${LibInstallPath}TestDB\</span>
<br><br>Execute the suite on <a href="#JdbcSlim">.PlugIns.JdbcSlim</a><br><br><br><h2>To build your own test pages</h2>
1. include this page on the root page of your suite <br>2. include the <a href="#JdbcSlim.SuiteSetup">SuiteSetup</a> page or a page with similar content in the setup of your suite </div>
</div>
<br><br></div>
<div class="test_output_name">
<h3>
<a id="JdbcSlim.UserGuide" class="test_name">JdbcSlim.UserGuide</a>
</h3>
<a href="#test-summaries" class="top_of_page">Top</a>
</div>
<div class="alternating_block"><br><div class="contents">
<b>Contents:</b>
<ul class="toc1">
<li>
<a href="#JdbcSlim.UserGuide.1ASimpleExample" class="test">1 A Simple Example +</a>
<ul class="toc2">
<li>
<a href="#JdbcSlim.UserGuide.1ASimpleExample.SeparatingSqlCommandsAndRequirements" class="test">Separating Sql Commands And Requirements +</a>
... </li>
<li>
<a href="#JdbcSlim.UserGuide.1ASimpleExample.WritingGenericRequirementsWithAlias" class="test">Writing Generic Requirements With Alias +</a>
<span class="pageHelp">: Requirements without any visible SQL</span>
... </li>
</ul>
</li>
<li>
<a href="#JdbcSlim.UserGuide.2KeyBenefits.1WaitingForAsynchronousResults" class="suite">2 Key Benefits *</a>
<span class="pageHelp">: More examples which showscase the benefit of jdbcSlim</span>
<ul class="toc2">
<li>
<a href="#JdbcSlim.UserGuide.2KeyBenefits.1WaitingForAsynchronousResults" class="test">1 Waiting For Asynchronous Results +</a>
</li>
<li>
<a href="#JdbcSlim.UserGuide.2KeyBenefits.2TestingOnSideEffects" class="test">2 Testing On Side Effects +</a>
</li>
<li>
<a href="#JdbcSlim.UserGuide.2KeyBenefits.3MultiTableStatement" class="test">3 Multi Table Statement +</a>
... </li>
</ul>
</li>
<li>
<a href="#JdbcSlim.UserGuide.3HowtoConfigureTheDatabaseConnection" class="test">3 Howto Configure The Database Connection +</a>
<ul class="toc2">
<li>
<a href="#JdbcSlim.UserGuide.3HowtoConfigureTheDatabaseConnection.ConnectionReuseViaNaming" class="test">Connection Reuse Via Naming +</a>
</li>
<li>
<a href="#JdbcSlim.UserGuide.3HowtoConfigureTheDatabaseConnection.CustomisingTheConnectionWithOwnImplementations" class="test">Customising The Connection With Own Implementations +</a>
</li>
<li>
<a href="#JdbcSlim.UserGuide.3HowtoConfigureTheDatabaseConnection.EncryptingPasswords" class="test">Encrypting Passwords +</a>
</li>
<li>
<a href="#JdbcSlim.UserGuide.3HowtoConfigureTheDatabaseConnection.FeatureOverviewOfPropertyFilesAndTables" class="test">Feature Overview Of Property Files And Tables +</a>
... </li>
<li>
<a href="#JdbcSlim.UserGuide.3HowtoConfigureTheDatabaseConnection.UsingProperties" class="test">Using Properties +</a>
</li>
</ul>
</li>
<li>
<a href="#JdbcSlim.UserGuide.4TheMappingBetweenTestDataAndCommands" class="test">4 The Mapping Between Test Data And Commands +</a>
<ul class="toc2">
<li>
<a href="#JdbcSlim.UserGuide.4TheMappingBetweenTestDataAndCommands.DefaultInputValues" class="test">Default Input Values +</a>
</li>
<li>
<a href="#JdbcSlim.UserGuide.4TheMappingBetweenTestDataAndCommands.EmptyExpectedCellsAreMarkedAsIgnored" class="test">Empty Expected Cells Are Marked As Ignored +</a>
</li>
<li>
<a href="#JdbcSlim.UserGuide.4TheMappingBetweenTestDataAndCommands.InsertUpdateDelete" class="test">Insert Update Delete +</a>
... </li>
<li>
<a href="#JdbcSlim.UserGuide.4TheMappingBetweenTestDataAndCommands.ReplacerStringCanBeAnyName" class="test">Replacer String Can Be Any Name +</a>
</li>
<li>
<a href="#JdbcSlim.UserGuide.4TheMappingBetweenTestDataAndCommands.ResultComparatorsCanBeUsed" class="test">Result Comparators Can Be Used +</a>
</li>
<li>
<a href="#JdbcSlim.UserGuide.4TheMappingBetweenTestDataAndCommands.StoredProcedures" class="test">Stored Procedures +</a>
... </li>
<li>
<a href="#JdbcSlim.UserGuide.4TheMappingBetweenTestDataAndCommands.UnusedInputColumnsAreFlagged" class="test">Unused Input Columns Are Flagged +</a>
</li>
</ul>
</li>
<li>
<a href="#JdbcSlim.UserGuide.5ParametersOfTheSQLCommand" class="test">5 Parameters Of The S Q L Command +</a>
</li>
<li>
<a href="#JdbcSlim.UserGuide.6OutputOptions" class="test">6 Output Options +</a>
<ul class="toc2">
<li>
<a href="#JdbcSlim.UserGuide.6OutputOptions.ColumnAlias" class="test">Column Alias +</a>
</li>
<li>
<a href="#JdbcSlim.UserGuide.6OutputOptions.Sorting" class="test">Sorting +</a>
... </li>
<li>
<a href="#JdbcSlim.UserGuide.6OutputOptions.SubQuery" class="test">Sub Query +</a>
</li>
<li>
<a href="#JdbcSlim.UserGuide.6OutputOptions.TotalOnly" class="test">Total Only +</a>
</li>
</ul>
</li>
<li>
<a href="#JdbcSlim.UserGuide.7UsingSqlInScriptsAndScenarios" class="test">7 Using Sql In Scripts And Scenarios +</a>
<ul class="toc2">
<li>
<a href="#JdbcSlim.UserGuide.7UsingSqlInScriptsAndScenarios.SymbolAssignmentOfResults" class="test">Symbol Assignment Of Results +</a>
</li>
</ul>
</li>
<li>
<a href="#JdbcSlim.UserGuide.9NullTrailingSpacesAndEmptyStrings" class="test">9 Null Trailing Spaces And Empty Strings +</a>
</li>
<li>
<a href="#JdbcSlim.UserGuide.JdbcAuthenticator" class="test">Jdbc Authenticator +</a>
</li>
</ul>
</div>
<br></div>
<div class="test_output_name">
<h3>
<a id="JdbcSlim.UserGuide.1ASimpleExample" class="test_name">JdbcSlim.UserGuide.1ASimpleExample</a>
</h3>
<a href="#test-summaries" class="top_of_page">Top</a>
</div>
<div class="alternating_block"><br>Most Tests require three steps.<br>1. Preparing test data<br>2. Execution some business functions<br>3. Validating the impact on the test data<br><br>Lets
assume we have a database with some information about people and a we
need to test a business function that relocates a person into a new
city. <br><br><h3>1 Preparing test data</h3>
<br>To avoid side effects we execute the test in a transaction<br><table>
<tbody><tr>
<td>Script</td>
<td>SQLCommand</td>
<td>TransactionDatabase</td>
</tr>
<tr>
<td colspan="3">open Connection</td>
</tr>
<tr>
<td>execute</td>
<td colspan="2">begin transaction</td>
</tr>
</tbody></table>
<br>To prepare test data two approaches are possible:<br>1.1 Inserting new data into a database<br>1.2 Finding suitable existing data in the database<br><br><br>In this examples we use the second approach and find the ID of users named Ben and Sarah which should move. <br>We store the Id of the users in a Slim Symbol '$TestID' for future reference.<br><br><table>
<tbody><tr>
<td>SQLCommand</td>
<td>TransactionDatabase</td>
<td>select ID, NAME from TestData where Name ='%NAME%'</td>
</tr>
<tr>
<td>ID?</td>
<td colspan="2">NAME</td>
</tr>
<tr>
<td>$TestID1=</td>
<td colspan="2">Ben</td>
</tr>
<tr>
<td>$TestID2=</td>
<td colspan="2">Sarah</td>
</tr>
</tbody></table>
<br>Before we proceed we validate that Ben and Sarah still live in the old Cities: Denver and Paris<br><br><table>
<tbody><tr>
<td>SQLCommand</td>
<td>TransactionDatabase</td>
<td>select City from TestData where ID ='%ID%'</td>
</tr>
<tr>
<td>ID</td>
<td colspan="2">CITY?</td>
</tr>
<tr>
<td>$TestID1</td>
<td colspan="2">Denver</td>
</tr>
<tr>
<td>$TestID2</td>
<td colspan="2">Paris</td>
</tr>
</tbody></table>
<br><h3>Execution some business functions</h3>
<br>Here calls to your business code will go.<br>A simple update statement which can do the job is given below.<br><table>
<tbody><tr>
<td>SQLCommand</td>
<td>TransactionDatabase</td>
<td>update TestData set City='%NewCITY%' where ID ='%ID%'</td>
<td></td>
</tr>
<tr>
<td>ID</td>
<td>NewCITY</td>
<td colspan="2">Count?</td>
</tr>
<tr>
<td>$TestID1</td>
<td>HongKong</td>
<td colspan="2">1</td>
</tr>
<tr>
<td>$TestID2</td>
<td>Tokyo</td>
<td colspan="2">1</td>
</tr>
</tbody></table>
<br><br><h3>Validating the impact on the test data</h3>
<br>Finally we check that Ben now lives in Hong Kong and Sarah in Tokyo<br><br><table>
<tbody><tr>
<td>SQLCommand</td>
<td>TransactionDatabase</td>
<td>select City from TestData where ID ='%ID%'</td>
</tr>
<tr>
<td>ID</td>
<td colspan="2">CITY?</td>
</tr>
<tr>
<td>$TestID1</td>
<td colspan="2">HongKong</td>
</tr>
<tr>
<td>$TestID2</td>
<td colspan="2">Tokyo</td>
</tr>
</tbody></table>
<br><h3>Rollback the change to not impact future tests</h3>
<br><table>
<tbody><tr>
<td>Script</td>
<td>SQLCommand</td>
<td>TransactionDatabase</td>
</tr>
<tr>
<td colspan="3">open Connection</td>
</tr>
<tr>
<td>execute</td>
<td colspan="2">rollback</td>
</tr>
<tr>
<td colspan="3">close Connection</td>
</tr>
</tbody></table>
<br><h4>Check that the rollback worked</h4>
<table>
<tbody><tr>
<td>SQLCommand</td>
<td>TransactionDatabase</td>
<td>select City from TestData where ID ='%ID%'</td>
</tr>
<tr>
<td>ID</td>
<td colspan="2">CITY?</td>
</tr>
<tr>
<td>$TestID1</td>
<td colspan="2">Denver</td>
</tr>
<tr>
<td>$TestID2</td>
<td colspan="2">Paris</td>
</tr>
</tbody></table>
<br><br><div class="contents">
<b>Contents:</b>
<ul class="toc1">
<li>
<a href="#JdbcSlim.UserGuide.1ASimpleExample.SeparatingSqlCommandsAndRequirements" class="test">Separating Sql Commands And Requirements +</a>
<ul class="toc2">
<li>
<a href="#JdbcSlim.UserGuide.1ASimpleExample.SeparatingSqlCommandsAndRequirements.SqlSetup" class="static">Sql Setup</a>
</li>
<li>
<a href="#JdbcSlim.UserGuide.1ASimpleExample.SeparatingSqlCommandsAndRequirements.SqlTearDown" class="static">Sql Tear Down</a>
</li>
</ul>
</li>
<li>
<a href="#JdbcSlim.UserGuide.1ASimpleExample.WritingGenericRequirementsWithAlias" class="test">Writing Generic Requirements With Alias +</a>
<span class="pageHelp">: Requirements without any visible SQL</span>
<ul class="toc2">
<li>
<a href="#JdbcSlim.UserGuide.1ASimpleExample.WritingGenericRequirementsWithAlias.SqlSetup" class="static">Sql Setup</a>
</li>
<li>
<a href="#JdbcSlim.UserGuide.1ASimpleExample.WritingGenericRequirementsWithAlias.SqlTearDown" class="static">Sql Tear Down</a>
</li>
</ul>
</li>
</ul>
</div>
<br></div>
<div class="test_output_name">
<h3>
<a id="JdbcSlim.UserGuide.1ASimpleExample.SeparatingSqlCommandsAndRequirements" class="test_name">JdbcSlim.UserGuide.1ASimpleExample.SeparatingSqlCommandsAndRequirements</a>
</h3>
<a href="#test-summaries" class="top_of_page">Top</a>
</div>
<div class="alternating_block"><br>Requirements should not contain SQL code:<br><br><ul>
<li>Not everybody understands SQL commands. But you want that the requirements can be understood by anybody.</li>
<li>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.</li>
</ul>
<br>This can be achieved easily with Jdbc Slim.<br><br>Lets rewrite the first example with Ben and Sarah but write it in less technical terms. <br>The SQL Code can be moved into a separate page:<br><br><div class="collapsible closed"><ul><li><a href="#" class="expandall">Expand</a></li><li><a href="#" class="collapseall">Collapse</a></li></ul>
<p class="title">Included page: <a href="#JdbcSlim.UserGuide.1ASimpleExample.SeparatingSqlCommandsAndRequirements.SqlSetUp">>SqlSetUp</a> <a href="#JdbcSlim.UserGuide.1ASimpleExample.SeparatingSqlCommandsAndRequirements.SqlSetUp?edit&redirectToReferer=true&redirectAction=" class="edit"></a></p>
<div><table>
<tbody><tr>
<td>Define Properties</td>
<td>FindTestUserIDs</td>
</tr>
<tr>
<td>key</td>
<td>value</td>
</tr>
<tr>
<td>.include</td>
<td>TransactionDatabase</td>
</tr>
<tr>
<td>cmd</td>
<td>select ID, NAME from TestData where Name ='%NAME%'</td>
</tr>
</tbody></table>
<br><table>
<tbody><tr>
<td>Define Properties</td>
<td>CheckInitalCityOfUsers</td>
</tr>
<tr>
<td>key</td>
<td>value</td>
</tr>
<tr>
<td>.include</td>
<td>TransactionDatabase</td>
</tr>
<tr>
<td>cmd</td>
<td>select City from TestData where ID ='%ID%'</td>
</tr>
</tbody></table>
<br><table>
<tbody><tr>
<td>Define Properties</td>
<td>RelocateUserToNewCity</td>
</tr>
<tr>
<td>key</td>
<td>value</td>
</tr>
<tr>
<td>.include</td>
<td>TransactionDatabase</td>
</tr>
<tr>
<td>cmd</td>
<td>update TestData set City='%NewCITY%' where ID ='%ID%'</td>
</tr>
</tbody></table>
<br><table>
<tbody><tr>
<td>Define Properties</td>
<td>CheckFinalCityOfUsers</td>
</tr>
<tr>
<td>key</td>
<td>value</td>
</tr>
<tr>
<td>.include</td>
<td>TransactionDatabase</td>
</tr>
<tr>
<td>cmd</td>
<td>select City from TestData where ID ='%ID%'</td>
</tr>
</tbody></table>
<br>To avoid side effects we execute the test in a transaction<br><table>
<tbody><tr>
<td>Script</td>
<td>SQLCommand</td>
<td>TransactionDatabase</td>
</tr>
<tr>
<td colspan="3">open Connection</td>
</tr>
<tr>
<td>execute</td>
<td colspan="2">begin transaction</td>
</tr>
</tbody></table>
</div>
</div>
<br><h3>1 Preparing test data</h3>
<br>Find the ID of users named Ben and Sarah which should move. <br>We store the Id of the users in a Slim Symbol '$TestID' for future reference.<br><br><table>
<tbody><tr>
<td>SQLCommand</td>
<td>FindTestUserIDs</td>
</tr>
<tr>
<td>ID?</td>
<td>NAME</td>
</tr>
<tr>
<td>$TestID=</td>
<td>Ben</td>
</tr>
<tr>
<td>$TestID2=</td>
<td>Sarah</td>
</tr>
</tbody></table>
<br>Before we proceed we validate that Ben and Sarah still live in the old Cities: Denver and Paris<br><br><table>
<tbody><tr>
<td>SQLCommand</td>
<td>CheckInitalCityOfUsers</td>
</tr>
<tr>
<td>ID</td>
<td>CITY?</td>
</tr>
<tr>
<td>$TestID</td>
<td>Denver</td>
</tr>
<tr>
<td>$TestID2</td>
<td>Paris</td>
</tr>
</tbody></table>
<br><h3>Execution some business functions</h3>
<br>Here calls to your business code will go.<br>A simple update statement which can do the job is given below.<br><table>
<tbody><tr>
<td>SQLCommand</td>
<td colspan="2">RelocateUserToNewCity</td>
</tr>
<tr>
<td>ID</td>
<td>NewCITY</td>
<td>Count?</td>
</tr>
<tr>
<td>$TestID</td>
<td>HongKong</td>
<td>1</td>
</tr>
<tr>
<td>$TestID2</td>
<td>Tokyo</td>
<td>1</td>
</tr>
</tbody></table>
<br><br><h3>Validating the impact on the test data</h3>
<br>Finally we check that Ben now lives in Hong Kong and Sarah in Tokyo<br><br><table>
<tbody><tr>
<td>SQLCommand</td>
<td>CheckFinalCityOfUsers</td>
</tr>
<tr>
<td>ID</td>
<td>CITY?</td>
</tr>
<tr>
<td>$TestID</td>
<td>HongKong</td>
</tr>
<tr>
<td>$TestID2</td>
<td>Tokyo</td>
</tr>
</tbody></table>
<br><div class="collapsible closed"><ul><li><a href="#" class="expandall">Expand</a></li><li><a href="#" class="collapseall">Collapse</a></li></ul>
<p class="title">Included page: <a href="#JdbcSlim.UserGuide.1ASimpleExample.SeparatingSqlCommandsAndRequirements.SqlTearDown">>SqlTearDown</a> <a href="#JdbcSlim.UserGuide.1ASimpleExample.SeparatingSqlCommandsAndRequirements.SqlTearDown?edit&redirectToReferer=true&redirectAction=" class="edit"></a></p>
<div><h3>Rollback the change to not impact future tests</h3>
<br><table>
<tbody><tr>
<td>Script</td>
<td>SQLCommand</td>
<td>TransactionDatabase</td>
<td>debug</td>
</tr>
<tr>
<td colspan="4">open Connection</td>
</tr>
<tr>
<td>execute</td>
<td colspan="3">rollback</td>
</tr>
<tr>
<td colspan="4">close Connection</td>
</tr>
</tbody></table>
<br><h4>Check that the rollback worked</h4>
<table>
<tbody><tr>
<td>SQLCommand</td>
<td>TransactionDatabase</td>
<td>select City from TestData where ID ='%ID%'</td>
</tr>
<tr>
<td>ID</td>
<td colspan="2">CITY?</td>
</tr>
<tr>
<td>$TestID</td>
<td colspan="2">Denver</td>
</tr>
<tr>
<td>$TestID2</td>
<td colspan="2">Paris</td>
</tr>
</tbody></table>
</div>
</div>
<div class="contents">
<b>Contents:</b>
<ul class="toc1">
<li>
<a href="#JdbcSlim.UserGuide.1ASimpleExample.SeparatingSqlCommandsAndRequirements.SqlSetup" class="static">Sql Setup</a>
</li>
<li>
<a href="#JdbcSlim.UserGuide.1ASimpleExample.SeparatingSqlCommandsAndRequirements.SqlTearDown" class="static">Sql Tear Down</a>
</li>
</ul>
</div>
<br></div>
<script>var existingContent =
document.getElementById("test-system-Example").innerHTML;
document.getElementById("test-system-Example").innerHTML =
existingContent + "<li>\r\n\t<span class=\"results pass\">1 right, 0
wrong, 0 ignored, 0 exceptions</span>\r\n\t<a
href=\"#JdbcSlim.UserGuide.1ASimpleExample.SeparatingSqlCommandsAndRequirements\"
class=\"link\">JdbcSlim.UserGuide.1ASimpleExample.SeparatingSqlCommandsAndRequirements</a>\r\n\t<span
class=\"\">(0,047 seconds)</span>\r\n</li>\r\n";
</script>
<script>document.getElementById("test-summary").innerHTML = "<div
id=\"progressBar\" class=\"pass\"
style=\"width:11.363636%\">Running tests ... (6/44)</div>\r\n";</script>
<div class="test_output_name">
<h3>
<a id="JdbcSlim.UserGuide.1ASimpleExample.WritingGenericRequirementsWithAlias" class="test_name">JdbcSlim.UserGuide.1ASimpleExample.WritingGenericRequirementsWithAlias</a>
</h3>
<a href="#test-summaries" class="top_of_page">Top</a>
</div>
<div class="alternating_block"><br>Requirements should not contain SQL code:<br><br><ul>
<li>Not everybody understands SQL commands. But you want that the requirements can be understood by anybody.</li>
<li>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.</li>
</ul>
<br>This can be achieved easily with JdbcSlim<a title="create page" href="#JdbcSlim.UserGuide.1ASimpleExample.JdbcSlim?edit&nonExistent=true">[?]</a>.<br><br>Lets rewrite the first example with Ben and Sarah but write it in less technical terms. <br>The SQL Code can be moved into a seperate SetUp<a title="create page" href="#JdbcSlim.UserGuide.1ASimpleExample.SetUp?edit&nonExistent=true">[?]</a> page.<br><br><div class="collapsible closed"><ul><li><a href="#" class="expandall">Expand</a></li><li><a href="#" class="collapseall">Collapse</a></li></ul>
<p class="title">Included page: <a href="#JdbcSlim.UserGuide.1ASimpleExample.WritingGenericRequirementsWithAlias.SqlSetUp">>SqlSetUp</a> <a href="#JdbcSlim.UserGuide.1ASimpleExample.WritingGenericRequirementsWithAlias.SqlSetUp?edit&redirectToReferer=true&redirectAction=" class="edit"></a></p>
<div><table>
<tbody><tr>
<td>Define Properties</td>
<td>FindTestUserIDs</td>
</tr>
<tr>
<td>key</td>
<td>value</td>
</tr>
<tr>
<td>.include</td>
<td>TransactionDatabase</td>
</tr>
<tr>
<td>cmd</td>
<td>select ID, NAME from TestData where Name ='%NAME%'</td>
</tr>
</tbody></table>
<br><table>
<tbody><tr>
<td>Define Properties</td>
<td>CheckInitalCityOfUsers</td>
</tr>
<tr>
<td>key</td>
<td>value</td>
</tr>
<tr>
<td>.include</td>
<td>TransactionDatabase</td>
</tr>
<tr>
<td>cmd</td>
<td>select City from TestData where ID ='%ID%'</td>
</tr>
</tbody></table>
<br><table>
<tbody><tr>
<td>Define Properties</td>
<td>RelocateUserToNewCity</td>
</tr>
<tr>
<td>key</td>
<td>value</td>
</tr>
<tr>
<td>.include</td>
<td>TransactionDatabase</td>
</tr>
<tr>
<td>cmd</td>
<td>update TestData set City='%NewCITY%' where ID ='%ID%'</td>
</tr>
</tbody></table>
<br><table>
<tbody><tr>
<td>Define Properties</td>
<td>CheckFinalCityOfUsers</td>
</tr>
<tr>
<td>key</td>
<td>value</td>
</tr>
<tr>
<td>.include</td>
<td>TransactionDatabase</td>
</tr>
<tr>
<td>cmd</td>
<td>select City from TestData where ID ='%ID%'</td>
</tr>
</tbody></table>
<br><br><table>
<tbody><tr>
<td>Script</td>
<td>SQLCommand</td>
<td>FindTestUserIDs</td>
</tr>
<tr>
<td>$FTU=</td>
<td colspan="2">get fixture</td>
</tr>
</tbody></table>
<br><table>
<tbody><tr>
<td colspan="2">Define alias</td>
</tr>
<tr>
<td>find test users</td>
<td>table: $FTU</td>
</tr>
</tbody></table>
<br><table>
<tbody><tr>
<td>Script</td>
<td>SQLCommand</td>
<td>CheckInitalCityOfUsers</td>
</tr>
<tr>
<td>$CICoU=</td>
<td colspan="2">get fixture</td>
</tr>
</tbody></table>
<br><table>
<tbody><tr>
<td colspan="2">Define alias</td>
</tr>
<tr>
<td>check first city of users</td>
<td>table: $CICoU</td>
</tr>
</tbody></table>
<br><table>
<tbody><tr>
<td>Script</td>
<td>SQLCommand</td>
<td>RelocateUserToNewCity</td>
</tr>
<tr>
<td>$RUTNC=</td>
<td colspan="2">get fixture</td>
</tr>
</tbody></table>
<br><table>
<tbody><tr>
<td colspan="2">Define alias</td>
</tr>
<tr>
<td>relocate users</td>
<td>table: $RUTNC</td>
</tr>
</tbody></table>
<br><table>
<tbody><tr>
<td>Script</td>
<td>SQLCommand</td>
<td>CheckFinalCityOfUsers</td>
</tr>
<tr>
<td>$CFCoU=</td>
<td colspan="2">get fixture</td>
</tr>
</tbody></table>
<br><table>
<tbody><tr>
<td colspan="2">Define alias</td>
</tr>
<tr>
<td>Check city after relocation</td>
<td>table: $CFCoU</td>
</tr>
</tbody></table>
<br><br><br>To avoid side effects we execute the test in a transaction<br><table>
<tbody><tr>
<td>Script</td>
<td>SQLCommand</td>
<td>TransactionDatabase</td>
</tr>
<tr>
<td colspan="3">open Connection</td>
</tr>
<tr>
<td>execute</td>
<td colspan="2">begin transaction</td>
</tr>
</tbody></table>
</div>
</div>
<br><br><h3>1 Preparing test data</h3>
<br>Find the ID of users named Ben and Sarah which should move. <br>We store the Id of the users in a Slim Symbol '$TestID' for future reference.<br><br><br><table>
<tbody><tr>
<td colspan="2">find test users</td>
</tr>
<tr>
<td>ID?</td>
<td>NAME</td>
</tr>
<tr>
<td>$TestID=</td>
<td>Ben</td>
</tr>
<tr>
<td>$TestID2=</td>
<td>Sarah</td>
</tr>
</tbody></table>
<br>Before we proceed we validate that Ben and Sarah still live in the old Cities: Denver and Paris<br><br><table>
<tbody><tr>
<td colspan="2">check first city of users</td>
</tr>
<tr>
<td>ID</td>
<td>CITY?</td>
</tr>
<tr>
<td>$TestID</td>
<td>Denver</td>
</tr>
<tr>
<td>$TestID2</td>
<td>Paris</td>
</tr>
</tbody></table>
<br><br><h3>2 Execution some business functions</h3>
<br>Here calls to your business code will go.<br>A simple update statement which can do the job is given below.<br><table>
<tbody><tr>
<td colspan="3">relocate users</td>
</tr>
<tr>
<td>ID</td>
<td>NewCITY</td>
<td>Count?</td>
</tr>
<tr>
<td>$TestID</td>
<td>HongKong</td>
<td>1</td>
</tr>
<tr>
<td>$TestID2</td>
<td>Tokyo</td>
<td>1</td>
</tr>
</tbody></table>
<br><br><h3>3 Validating the impact on the test data</h3>
<br>Finally we check that Ben now lives in Hong Kong and Sarah in Tokyo<br><br><table>
<tbody><tr>
<td colspan="2">Check city after relocation</td>
</tr>
<tr>
<td>ID</td>
<td>CITY?</td>
</tr>
<tr>
<td>$TestID</td>
<td>HongKong</td>
</tr>
<tr>
<td>$TestID2</td>
<td>Tokyo</td>
</tr>
</tbody></table>
<br><div class="collapsible closed"><ul><li><a href="#" class="expandall">Expand</a></li><li><a href="#" class="collapseall">Collapse</a></li></ul>
<p class="title">Included page: <a href="#JdbcSlim.UserGuide.1ASimpleExample.WritingGenericRequirementsWithAlias.SqlTearDown">>SqlTearDown</a> <a href="#JdbcSlim.UserGuide.1ASimpleExample.WritingGenericRequirementsWithAlias.SqlTearDown?edit&redirectToReferer=true&redirectAction=" class="edit"></a></p>
<div><h3>Rollback the change to not impact future tests</h3>
<br><table>
<tbody><tr>
<td>Script</td>
<td>SQLCommand</td>
<td>TransactionDatabase</td>
<td>debug</td>
</tr>
<tr>
<td colspan="4">open Connection</td>
</tr>
<tr>
<td>execute</td>
<td colspan="3">rollback</td>
</tr>
<tr>
<td colspan="4">close Connection</td>
</tr>
</tbody></table>
<br><h4>Check that the rollback worked</h4>
<table>
<tbody><tr>
<td>SQLCommand</td>
<td>TransactionDatabase</td>
<td>select City from TestData where ID ='%ID%'</td>
</tr>
<tr>
<td>ID</td>
<td colspan="2">CITY?</td>
</tr>
<tr>
<td>$TestID</td>
<td colspan="2">Denver</td>
</tr>
<tr>
<td>$TestID2</td>
<td colspan="2">Paris</td>
</tr>
</tbody></table>
</div>
</div>
<br><div class="contents">
<b>Contents:</b>
<ul class="toc1">
<li>
<a href="#JdbcSlim.UserGuide.1ASimpleExample.WritingGenericRequirementsWithAlias.SqlSetup" class="static">Sql Setup</a>
</li>
<li>
<a href="#JdbcSlim.UserGuide.1ASimpleExample.WritingGenericRequirementsWithAlias.SqlTearDown" class="static">Sql Tear Down</a>
</li>
</ul>
</div>
<br></div>
<script>var existingContent =
document.getElementById("test-system-Example").innerHTML;
document.getElementById("test-system-Example").innerHTML =
existingContent + "<li>\r\n\t<span class=\"results pass\">1 right, 0
wrong, 0 ignored, 0 exceptions</span>\r\n\t<a
href=\"#JdbcSlim.UserGuide.1ASimpleExample.WritingGenericRequirementsWithAlias\"
class=\"link\">JdbcSlim.UserGuide.1ASimpleExample.WritingGenericRequirementsWithAlias</a>\r\n\t<span
class=\"\">(0,047 seconds)</span>\r\n</li>\r\n";
</script>
<script>document.getElementById("test-summary").innerHTML = "<div
id=\"progressBar\" class=\"pass\"
style=\"width:13.636364%\">Running tests ... (7/44)</div>\r\n";</script>
<div class="test_output_name">
<h3>
<a id="JdbcSlim.UserGuide.2KeyBenefits.1WaitingForAsynchronousResults" class="test_name">JdbcSlim.UserGuide.2KeyBenefits.1WaitingForAsynchronousResults</a>
</h3>
<a href="#test-summaries" class="top_of_page">Top</a>
</div>
<div class="alternating_block"><br><br><h3>Given</h3>
<table>
<tbody><tr>
<td>SQLCommand</td>
<td>TestDatabase</td>
<td>select ID, City from TestData where ID ='%ID%'</td>
</tr>
<tr>
<td>ID</td>
<td colspan="2">City?</td>
</tr>
<tr>
<td>1</td>
<td colspan="2">Berlin</td>
</tr>
</tbody></table>
<br><br><table>
<tbody><tr>
<td>Define Properties</td>
<td>Dummy</td>
</tr>
<tr>
<td>key</td>
<td>value</td>
</tr>
<tr>
<td>CMD</td>
<td></td>
</tr>
</tbody></table>
<br><table>
<tbody><tr>
<td colspan="5">Script</td>
</tr>
<tr>
<td colspan="5"># Your code here to create a Connection Object</td>
</tr>
<tr>
<td>start</td>
<td>SQLCommand</td>
<td colspan="3">Dummy</td>
</tr>
<tr>
<td>$Cnn=</td>
<td>testHomeMadeConnection;</td>
<td>jdbc:h2:mem:h2db;DB_CLOSE_DELAY=-1</td>