Skip to content

Commit 0a12fea

Browse files
updated db validation to support context value
1 parent 832a77f commit 0a12fea

File tree

5 files changed

+91
-1
lines changed

5 files changed

+91
-1
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,22 @@ Auth token can be passed from maven command line as well as config file. If the
268268
#Execute select query from file to validate data does not exist in DB
269269
#Then validate data does not exist for select query from file "<sql query>"
270270
Then validate data does not exist for select query from file "/DbOps/scenario11/SelQuery.sql"
271+
272+
#Execute select query to validate data exist in DB with context
273+
Then validate data exist for select query '<sql query>' and where condition as a context value '<context value>'
274+
Then validate data exist for select query 'select * from users where name = ' and where condition as a context value 'name'
275+
276+
#Execute select query to validate data exist in DB with context
277+
Then validate data not exist for select query '<sql query>' and where condition as a context value '<context value>'
278+
Then validate data not exist for select query 'select * from users where name = ' and where condition as a context value 'name'
279+
280+
#Execute select query from file to validate data exist in DB
281+
Then validate data exist for select query from file "<sql query>" and context value '<context value>'
282+
Then validate data exist for select query from file "/DbOps/scenario18/SelQuery.sql" and context value 'name'
283+
284+
#Execute select query from file to validate data does not exist in DB
285+
Then validate data not exist for select query from file "<sql query>" and context value '<context value>'
286+
Then validate data not exist for select query from file "/DbOps/scenario17/SelQuery.sql" and context value 'name'
271287
272288
```
273289

src/test/java/testSuit/stepDef/DBOpsStepDef.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import testSuit.utils.DataSourceFactory;
1515
import testSuit.utils.DbOpsUtil;
1616
import testSuit.utils.ReporterFactory;
17+
import testSuit.utils.TestContext;
1718

1819
import javax.sql.DataSource;
1920
import java.net.URL;
@@ -27,6 +28,9 @@ public class DBOpsStepDef {
2728

2829
private DataSource dataSource = DataSourceFactory.getDataSource();
2930

31+
@Inject
32+
TestContext testContext;
33+
3034
@Inject
3135
DbOpsUtil dbOpsUtil;
3236

@@ -133,4 +137,32 @@ public void validate_data_does_not_exist_for_select_query_from_file_string(Strin
133137
new String(Files.readAllBytes(Paths.get(System.getProperty("user.dir")+"/src/test/resources/testData"+filePath)));
134138
dbOpsUtil.executeSelQueryForDataNotExist(dataSource, sqlStatement);
135139
}
140+
141+
@SneakyThrows
142+
@Then("validate data exist for select query {string} and where condition as a context value {string}")
143+
public void validate_data_exist_for_select_query_string_and_where_condition_as_a_context_value_string(String sqlStatement, String contextKey) {
144+
dbOpsUtil.executeSelQueryForDataExist(dataSource, sqlStatement + "'" + testContext.getContextValues().get(contextKey) + "'");
145+
}
146+
147+
@SneakyThrows
148+
@Then("validate data not exist for select query {string} and where condition as a context value {string}")
149+
public void validate_data_not_exist_for_select_query_string_and_where_condition_as_a_context_value_string(String sqlStatement, String contextKey) {
150+
dbOpsUtil.executeSelQueryForDataNotExist(dataSource, sqlStatement + "'" + testContext.getContextValues().get(contextKey) + "'");
151+
}
152+
153+
@SneakyThrows
154+
@Then("validate data exist for select query from file {string} and context value {string}")
155+
public void validate_data_exist_for_select_query_from_file_string_and_context_value_string(String filePath, String contextKey) {
156+
String sqlStatement =
157+
new String(Files.readAllBytes(Paths.get(System.getProperty("user.dir")+"/src/test/resources/testData"+filePath)));
158+
dbOpsUtil.executeSelQueryForDataExist(dataSource, sqlStatement + "'" + testContext.getContextValues().get(contextKey) + "'");
159+
}
160+
161+
@SneakyThrows
162+
@Then("validate data not exist for select query from file {string} and context value {string}")
163+
public void validate_data_not_exist_for_select_query_from_file_string_and_context_value_string(String filePath, String contextKey) {
164+
String sqlStatement =
165+
new String(Files.readAllBytes(Paths.get(System.getProperty("user.dir")+"/src/test/resources/testData"+filePath)));
166+
dbOpsUtil.executeSelQueryForDataNotExist(dataSource, sqlStatement + "'" + testContext.getContextValues().get(contextKey) + "'");
167+
}
136168
}

src/test/resources/features/dbFeatures/DbOps.feature

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,44 @@ Feature: DB operations
5757

5858
@DbOps12 @DBParallel @DbOpsAll
5959
Scenario: 12 Use select query to validate DB table from file - return 1 row - Fail
60-
Then validate data does not exist for select query from file "/DbOps/scenario12/SelQuery.sql"
60+
Then validate data does not exist for select query from file "/DbOps/scenario12/SelQuery.sql"
61+
62+
@DbOps13 @DBParallel @DbOpsAll
63+
Scenario: 13 Use select query and context value to validate DB table - return 1 row - Success
64+
* put 'abhishek kadavil' in context value 'name'
65+
Then validate data exist for select query 'select * from users where name = ' and where condition as a context value 'name'
66+
67+
@DbOps14 @DBParallel @DbOpsAll
68+
Scenario: 14 Use select query and context value to validate DB table - return 0 row - Fail
69+
* put 'abhishek kadavil1' in context value 'name'
70+
Then validate data exist for select query 'select * from users where name = ' and where condition as a context value 'name'
71+
72+
@DbOps15 @DBParallel @DbOpsAll
73+
Scenario: 15 Use select query and context value to validate DB table - return 0 row - Success
74+
* put 'abhishek kadavil1' in context value 'name'
75+
Then validate data not exist for select query 'select * from users where name = ' and where condition as a context value 'name'
76+
77+
@DbOps16 @DBParallel @DbOpsAll
78+
Scenario: 16 Use select query and context value to validate DB table - return 1 row - Fail
79+
* put 'abhishek kadavil' in context value 'name'
80+
Then validate data not exist for select query 'select * from users where name = ' and where condition as a context value 'name'
81+
82+
@DbOps17 @DBParallel @DbOpsAll
83+
Scenario: 17 Use select query from file and context value to validate DB table - return 1 row - Success
84+
* put 'abhishek kadavil' in context value 'name'
85+
Then validate data exist for select query from file "/DbOps/scenario17/SelQuery.sql" and context value 'name'
86+
87+
@DbOps18 @DBParallel @DbOpsAll
88+
Scenario: 18 Use select query from file and context value to validate DB table - return 0 row - fail
89+
* put 'abhishek kadavil1' in context value 'name'
90+
Then validate data exist for select query from file "/DbOps/scenario18/SelQuery.sql" and context value 'name'
91+
92+
@DbOps19 @DBParallel @DbOpsAll
93+
Scenario: 19 Use select query from file and context value to validate DB table - return 0 row - Success
94+
* put 'abhishek kadavil1' in context value 'name'
95+
Then validate data not exist for select query from file "/DbOps/scenario17/SelQuery.sql" and context value 'name'
96+
97+
@DbOps20 @DBParallel @DbOpsAll
98+
Scenario: 20 Use select query from file and context value to validate DB table - return 1 row - fail
99+
* put 'abhishek kadavil' in context value 'name'
100+
Then validate data not exist for select query from file "/DbOps/scenario18/SelQuery.sql" and context value 'name'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
select * from users where name =
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
select * from users where name =

0 commit comments

Comments
 (0)