How to use testNullValue method of com.consol.citrus.actions.ExecuteSQLQueryActionTest class

Best Citrus code snippet using com.consol.citrus.actions.ExecuteSQLQueryActionTest.testNullValue

Source:ExecuteSQLQueryActionTest.java Github

copy

Full Screen

...163 Assert.assertEquals(context.getVariable("${HEIGHT}"), "0,3");164 }165 166 @Test167 public void testNullValue() {168 String sql = DB_STMT_1;169 reset(jdbcTemplate);170 171 Map<String, Object> resultMap = new HashMap<String, Object>();172 resultMap.put("ORDERTYPE", "small");173 resultMap.put("STATUS", null);174 175 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));176 List<String> stmts = Collections.singletonList(sql);177 executeSQLQueryAction.setStatements(stmts);178 179 executeSQLQueryAction.execute(context);180 Assert.assertNotNull(context.getVariable("${ORDERTYPE}"));181 Assert.assertEquals(context.getVariable("${ORDERTYPE}"), "small");182 Assert.assertNotNull(context.getVariable("${STATUS}"));183 Assert.assertEquals(context.getVariable("${STATUS}"), "NULL");184 }185 186 @Test187 public void testVariableSupport() {188 context.setVariable("orderId", "5");189 190 String sql = "select ORDERTYPE, STATUS from orders where ID=${orderId}";191 reset(jdbcTemplate);192 193 Map<String, Object> resultMap = new HashMap<String, Object>();194 resultMap.put("ORDERTYPE", "small");195 resultMap.put("STATUS", "in_progress");196 197 when(jdbcTemplate.queryForList(DB_STMT_1)).thenReturn(Collections.singletonList(resultMap));198 List<String> stmts = Collections.singletonList(sql);199 executeSQLQueryAction.setStatements(stmts);200 201 executeSQLQueryAction.execute(context);202 Assert.assertNotNull(context.getVariable("${ORDERTYPE}"));203 Assert.assertEquals(context.getVariable("${ORDERTYPE}"), "small");204 Assert.assertNotNull(context.getVariable("${STATUS}"));205 Assert.assertEquals(context.getVariable("${STATUS}"), "in_progress");206 }207 208 @Test209 public void testExtractToVariables() {210 String sql = DB_STMT_1;211 reset(jdbcTemplate);212 213 Map<String, Object> resultMap = new HashMap<String, Object>();214 resultMap.put("ORDERTYPE", "small");215 resultMap.put("STATUS", "in_progress");216 217 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));218 List<String> stmts = Collections.singletonList(sql);219 executeSQLQueryAction.setStatements(stmts);220 221 Map<String, String> extractVariables = new HashMap<String, String>();222 extractVariables.put("STATUS", "orderStatus");223 executeSQLQueryAction.setExtractVariables(extractVariables);224 225 executeSQLQueryAction.execute(context);226 Assert.assertNotNull(context.getVariable("${orderStatus}"));227 Assert.assertEquals(context.getVariable("${orderStatus}"), "in_progress");228 Assert.assertNotNull(context.getVariable("${ORDERTYPE}"));229 Assert.assertEquals(context.getVariable("${ORDERTYPE}"), "small");230 Assert.assertNotNull(context.getVariable("${STATUS}"));231 Assert.assertEquals(context.getVariable("${STATUS}"), "in_progress");232 }233 @Test234 public void testExtractToVariablesLowerCaseColumnNames() {235 String sql = DB_STMT_1;236 reset(jdbcTemplate);237 Map<String, Object> resultMap = new HashMap<String, Object>();238 resultMap.put("ordertype", "small");239 resultMap.put("status", "in_progress");240 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));241 List<String> stmts = Collections.singletonList(sql);242 executeSQLQueryAction.setStatements(stmts);243 Map<String, String> extractVariables = new HashMap<String, String>();244 extractVariables.put("ordertype", "orderType");245 extractVariables.put("STATUS", "orderStatus");246 executeSQLQueryAction.setExtractVariables(extractVariables);247 executeSQLQueryAction.execute(context);248 Assert.assertNotNull(context.getVariable("${orderStatus}"));249 Assert.assertEquals(context.getVariable("${orderStatus}"), "in_progress");250 Assert.assertNotNull(context.getVariable("${ORDERTYPE}"));251 Assert.assertEquals(context.getVariable("${ORDERTYPE}"), "small");252 Assert.assertNotNull(context.getVariable("${orderType}"));253 Assert.assertEquals(context.getVariable("${orderType}"), "small");254 Assert.assertNotNull(context.getVariable("${STATUS}"));255 Assert.assertEquals(context.getVariable("${STATUS}"), "in_progress");256 }257 258 @Test(expectedExceptions = {CitrusRuntimeException.class})259 public void testExtractToVariablesUnknownColumnMapping() {260 String sql = DB_STMT_1;261 reset(jdbcTemplate);262 263 Map<String, Object> resultMap = new HashMap<String, Object>();264 resultMap.put("ORDERTYPE", "small");265 resultMap.put("STATUS", "in_progress");266 267 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));268 List<String> stmts = Collections.singletonList(sql);269 executeSQLQueryAction.setStatements(stmts);270 271 Map<String, String> extractVariables = new HashMap<String, String>();272 extractVariables.put("UNKNOWN_COLUMN", "orderStatus");273 executeSQLQueryAction.setExtractVariables(extractVariables);274 275 executeSQLQueryAction.execute(context);276 }277 278 @Test279 public void testResultSetValidation() {280 String sql = DB_STMT_1;281 reset(jdbcTemplate);282 283 Map<String, Object> resultMap = new HashMap<String, Object>();284 resultMap.put("ORDERTYPE", "small");285 resultMap.put("STATUS", "in_progress");286 287 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));288 List<String> stmts = Collections.singletonList(sql);289 executeSQLQueryAction.setStatements(stmts);290 291 Map<String, List<String>> controlResultSet = new HashMap<String, List<String>>();292 controlResultSet.put("ORDERTYPE", Collections.singletonList("small"));293 controlResultSet.put("STATUS", Collections.singletonList("in_progress"));294 295 executeSQLQueryAction.setControlResultSet(controlResultSet);296 297 executeSQLQueryAction.execute(context);298 299 Assert.assertNotNull(context.getVariable("${ORDERTYPE}"));300 Assert.assertEquals(context.getVariable("${ORDERTYPE}"), "small");301 Assert.assertNotNull(context.getVariable("${STATUS}"));302 Assert.assertEquals(context.getVariable("${STATUS}"), "in_progress");303 }304 @Test305 public void testResultSetValidationLowerCase() {306 String sql = DB_STMT_1;307 reset(jdbcTemplate);308 Map<String, Object> resultMap = new HashMap<String, Object>();309 resultMap.put("ordertype", "small");310 resultMap.put("status", "in_progress");311 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));312 List<String> stmts = Collections.singletonList(sql);313 executeSQLQueryAction.setStatements(stmts);314 Map<String, List<String>> controlResultSet = new HashMap<String, List<String>>();315 controlResultSet.put("ORDERTYPE", Collections.singletonList("small"));316 controlResultSet.put("STATUS", Collections.singletonList("in_progress"));317 executeSQLQueryAction.setControlResultSet(controlResultSet);318 executeSQLQueryAction.execute(context);319 Assert.assertNotNull(context.getVariable("${ORDERTYPE}"));320 Assert.assertEquals(context.getVariable("${ORDERTYPE}"), "small");321 Assert.assertNotNull(context.getVariable("${STATUS}"));322 Assert.assertEquals(context.getVariable("${STATUS}"), "in_progress");323 }324 325 @Test326 public void testResultSetValidationWithAliasNames() {327 String sql = "select ORDERTYPE AS TYPE, STATUS AS STATE from orders where ID=5";328 reset(jdbcTemplate);329 330 Map<String, Object> resultMap = new HashMap<String, Object>();331 resultMap.put("TYPE", "small");332 resultMap.put("STATE", "in_progress");333 334 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));335 List<String> stmts = Collections.singletonList(sql);336 executeSQLQueryAction.setStatements(stmts);337 338 Map<String, List<String>> controlResultSet = new HashMap<String, List<String>>();339 controlResultSet.put("TYPE", Collections.singletonList("small"));340 controlResultSet.put("STATE", Collections.singletonList("in_progress"));341 342 executeSQLQueryAction.setControlResultSet(controlResultSet);343 344 executeSQLQueryAction.execute(context);345 Assert.assertNotNull(context.getVariable("${TYPE}"));346 Assert.assertEquals(context.getVariable("${TYPE}"), "small");347 Assert.assertNotNull(context.getVariable("${STATE}"));348 Assert.assertEquals(context.getVariable("${STATE}"), "in_progress");349 }350 351 @Test352 public void testResultSetValidationError() {353 String sql = DB_STMT_1;354 reset(jdbcTemplate);355 356 Map<String, Object> resultMap = new HashMap<String, Object>();357 resultMap.put("ORDERTYPE", "small");358 resultMap.put("STATUS", "in_progress");359 360 when(jdbcTemplate.queryForList(sql)).thenReturn(Collections.singletonList(resultMap));361 List<String> stmts = Collections.singletonList(sql);362 executeSQLQueryAction.setStatements(stmts);363 364 Map<String, List<String>> controlResultSet = new HashMap<String, List<String>>();365 controlResultSet.put("ORDERTYPE", Collections.singletonList("xxl")); //this is supposed to cause an error366 controlResultSet.put("STATUS", Collections.singletonList("in_progress"));367 368 executeSQLQueryAction.setControlResultSet(controlResultSet);369 370 try {371 executeSQLQueryAction.execute(context);372 } catch (ValidationException e) {373 Assert.assertNull(context.getVariables().get("${ORDERTYPE}"));374 Assert.assertNull(context.getVariables().get("${STATUS}"));375 376 return;377 }378 Assert.fail("Expected test to fail with " + ValidationException.class + " but was successful");379 }380 381 @Test382 public void testResultSetMultipleRowsValidation() {383 String sql = "select ORDERTYPE, STATUS from orders where ID < 5";384 reset(jdbcTemplate);385 386 List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();387 Map<String, Object> resultRow1 = new HashMap<String, Object>();388 Map<String, Object> resultRow2 = new HashMap<String, Object>();389 Map<String, Object> resultRow3 = new HashMap<String, Object>();390 resultRow1.put("ORDERTYPE", "small");391 resultRow1.put("STATUS", "started");392 resultList.add(resultRow1);393 resultRow2.put("ORDERTYPE", "medium");394 resultRow2.put("STATUS", "in_progress");395 resultList.add(resultRow2);396 resultRow3.put("ORDERTYPE", "big");397 resultRow3.put("STATUS", "finished");398 resultList.add(resultRow3);399 400 when(jdbcTemplate.queryForList(sql)).thenReturn(resultList);401 List<String> stmts = Collections.singletonList(sql);402 executeSQLQueryAction.setStatements(stmts);403 404 Map<String, List<String>> controlResultSet = new HashMap<String, List<String>>();405 List<String> ordertypeValues = new ArrayList<String>();406 ordertypeValues.add("small");407 ordertypeValues.add("medium");408 ordertypeValues.add("big");409 controlResultSet.put("ORDERTYPE", ordertypeValues);410 411 List<String> statusValues = new ArrayList<String>();412 statusValues.add("started");413 statusValues.add("in_progress");414 statusValues.add("finished");415 controlResultSet.put("STATUS", statusValues);416 417 executeSQLQueryAction.setControlResultSet(controlResultSet);418 419 executeSQLQueryAction.execute(context);420 Assert.assertNotNull(context.getVariable("ORDERTYPE"));421 Assert.assertEquals(context.getVariable("ORDERTYPE"), "small");422 Assert.assertNotNull(context.getVariable("STATUS"));423 Assert.assertEquals(context.getVariable("STATUS"), "started");424 }425 426 @Test427 public void testNullValuesInMultipleRowsValidation() {428 String sql = "select ORDERTYPE, STATUS from orders where ID < 5";429 reset(jdbcTemplate);430 431 List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();432 Map<String, Object> resultRow1 = new HashMap<String, Object>();433 Map<String, Object> resultRow2 = new HashMap<String, Object>();434 Map<String, Object> resultRow3 = new HashMap<String, Object>();435 resultRow1.put("ORDERTYPE", "small");436 resultRow1.put("STATUS", null);437 resultList.add(resultRow1);438 resultRow2.put("ORDERTYPE", "medium");439 resultRow2.put("STATUS", "in_progress");440 resultList.add(resultRow2);441 resultRow3.put("ORDERTYPE", null);...

Full Screen

Full Screen

testNullValue

Using AI Code Generation

copy

Full Screen

1public class ExecuteSQLQueryActionTest {2 public void testNullValue() {3 final ExecuteSQLQueryAction action = new ExecuteSQLQueryAction();4 action.setDataSource(new DriverManagerDataSource("jdbc:hsqldb:mem:mydb", "sa", ""));5 action.setSqlResourcePath("classpath:com/consol/citrus/actions/query.sql");6 action.setResultSet(new ResultSet() {7 public boolean next() throws SQLException {8 return true;9 }10 public void close() throws SQLException {11 }12 public boolean wasNull() throws SQLException {13 return true;14 }15 public String getString(int columnIndex) throws SQLException {16 return null;17 }18 public boolean getBoolean(int columnIndex) throws SQLException {19 return false;20 }21 public byte getByte(int columnIndex) throws SQLException {22 return 0;23 }24 public short getShort(int columnIndex) throws SQLException {25 return 0;26 }27 public int getInt(int columnIndex) throws SQLException {28 return 0;29 }30 public long getLong(int columnIndex) throws SQLException {31 return 0;32 }33 public float getFloat(int columnIndex) throws SQLException {34 return 0;35 }36 public double getDouble(int columnIndex) throws SQLException {37 return 0;38 }39 public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {40 return null;41 }42 public byte[] getBytes(int columnIndex) throws SQLException {43 return new byte[0];44 }45 public Date getDate(int columnIndex) throws SQLException {46 return null;47 }48 public Time getTime(int columnIndex) throws SQLException {49 return null;50 }51 public Timestamp getTimestamp(int columnIndex) throws SQLException {52 return null;53 }54 public InputStream getAsciiStream(int columnIndex) throws SQLException {55 return null;56 }57 public InputStream getUnicodeStream(int columnIndex) throws SQLException {58 return null;59 }60 public InputStream getBinaryStream(int columnIndex) throws SQLException {61 return null;62 }63 public String getString(String columnLabel) throws SQLException

Full Screen

Full Screen

testNullValue

Using AI Code Generation

copy

Full Screen

1public class ExecuteSQLQueryActionTest {2 public void testNullValue() {3 }4}5package com.consol.citrus.actions;6import com.consol.citrus.testng.AbstractTestNGUnitTest;7import org.testng.annotations.Test;8public class ExecuteSQLQueryActionTest extends AbstractTestNGUnitTest {9 public void testNullValue() {10 }11}12package com.consol.citrus.actions;13import com.consol.citrus.testng.AbstractTestNGUnitTest;14import org.testng.annotations.Test;15public class ExecuteSQLQueryActionTest extends AbstractTestNGUnitTest {16 public void testNullValue() {17 }18}19package com.consol.citrus.actions;20import com.consol.citrus.testng.AbstractTestNGUnitTest;21import org.testng.annotations.Test;22public class ExecuteSQLQueryActionTest extends AbstractTestNGUnitTest {23 public void testNullValue() {24 }25}26package com.consol.citrus.actions;27import com.consol.citrus.testng.AbstractTestNGUnitTest;28import org.testng.annotations.Test;29public class ExecuteSQLQueryActionTest extends AbstractTestNGUnitTest {

Full Screen

Full Screen

testNullValue

Using AI Code Generation

copy

Full Screen

1public class ExecuteSQLQueryActionTest {2 public void testNullValue() {3 }4}5public void testNullValue() {6}7public void testNullValue() {8}9public void testNullValue() {10}11public void testNullValue() {12}13public void testNullValue() {14}

Full Screen

Full Screen

testNullValue

Using AI Code Generation

copy

Full Screen

1 public void testNullValue() {2 variable("sqlQuery", "SELECT * FROM CUSTOMER WHERE ID = 1");3 variable("sqlResult", "com.consol.citrus.actions.ExecuteSQLQueryActionTest$Customer");4 $(sql(dataSource)5 .statement("${sqlQuery}")6 .validate("${sqlResult}", new AbstractSqlResultSetValidator() {7 public void validate(ResultSet resultSet, TestContext context) throws SQLException {8 Assert.assertEquals(resultSet.getString("NAME"), "foo");9 Assert.assertEquals(resultSet.getString("ADDRESS"), null);10 }11 }));12 }13 public static class Customer {14 private String name;15 private String address;16 public String getName() {17 return name;18 }19 public void setName(String name) {20 this.name = name;21 }22 public String getAddress() {23 return address;24 }25 public void setAddress(String address) {26 this.address = address;27 }28 }29 public void validate(ResultSet resultSet, TestContext context) throws SQLException {30 Assert.assertEquals(resultSet.getString("NAME"), "foo");31 Assert.assertEquals(resultSet.getObject("ADDRESS"), null);32 }

Full Screen

Full Screen

testNullValue

Using AI Code Generation

copy

Full Screen

1public void testNullValue() throws Exception {2 final ExecuteSQLQueryAction executeSQLQueryAction = new ExecuteSQLQueryAction();3 executeSQLQueryAction.setDataSource(dataSource);4 executeSQLQueryAction.setSqlResource(new ClassPathResource("sql/testNullValue.sql"));5 executeSQLQueryAction.setRowMapper(new RowMapper<Map<String, Object>>() {6 public Map<String, Object> mapRow(ResultSet resultSet, int i) throws SQLException {7 final Map<String, Object> row = new HashMap<String, Object>();8 row.put("name", resultSet.getString("name"));9 row.put("age", resultSet.getInt("age"));10 return row;11 }12 });13 executeSQLQueryAction.execute(context);14 assertThat(executeSQLQueryAction.getQueryResult()).as("queryResult").isNotNull();15 assertThat(executeSQLQueryAction.getQueryResult().size()).as("queryResult.size()").isEqualTo(1);16 assertThat(executeSQLQueryAction.getQueryResult().get(0).get("name")).as("queryResult[0].get(\"name\")").isEqualTo("John");17 assertThat(executeSQLQueryAction.getQueryResult().get(0).get("age")).as("queryResult[0].get(\"age\")").isNull();18}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful