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

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

Source:ExecuteSQLQueryActionTest.java Github

copy

Full Screen

...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);...

Full Screen

Full Screen

testExtractToVariables

Using AI Code Generation

copy

Full Screen

1public void testExtractToVariables() {2 reset(dataSource);3 when(dataSource.getConnection()).thenReturn(connection);4 when(connection.createStatement()).thenReturn(statement);5 when(statement.executeQuery(anyString())).thenReturn(resultSet);6 when(resultSet.next()).thenReturn(true).thenReturn(false);7 when(resultSet.getString(1)).thenReturn("foo");8 when(resultSet.getString(2)).thenReturn("bar");9 citrus.run(new TestCase()10 .actions(new ExecuteSQLQueryAction.Builder()11 .dataSource(dataSource)12 .sqlQuery("SELECT * FROM test")13 .extractToVariables("id", "name")14 .build()));15 assertThat(citrus.getCitrusContext().getVariable("id"), is("foo"));16 assertThat(citrus.getCitrusContext().getVariable("name"), is("bar"));17}

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