How to use getControlResultSet method of com.consol.citrus.actions.ExecuteSQLQueryAction class

Best Citrus code snippet using com.consol.citrus.actions.ExecuteSQLQueryAction.getControlResultSet

Source:ExecuteSQLQueryTestRunnerTest.java Github

copy

Full Screen

...73 74 ExecuteSQLQueryAction action = (ExecuteSQLQueryAction)test.getActions().get(0);75 76 Assert.assertEquals(action.getName(), "sql-query");77 Assert.assertEquals(action.getControlResultSet().size(), 2);78 Set<Map.Entry<String, List<String>>> rows = action.getControlResultSet().entrySet();79 Assert.assertEquals(getRow("NAME", rows).toString(), "NAME=[Leonard]");80 Assert.assertEquals(getRow("CNT_EPISODES", rows).toString(), "CNT_EPISODES=[100000]");81 Assert.assertEquals(action.getExtractVariables().size(), 1);82 Assert.assertEquals(action.getExtractVariables().entrySet().iterator().next().toString(), "NAME=actorName");83 Assert.assertNull(action.getScriptValidationContext());84 Assert.assertEquals(action.getJdbcTemplate(), jdbcTemplate);85 Assert.assertEquals(action.getStatements().size(), 2);86 Assert.assertNull(action.getSqlResourcePath());87 Assert.assertNull(action.getValidator());88 }89 90 @Test91 public void testExecuteSQLQueryWithStatements() {92 List<Map<String, Object>> results = new ArrayList<>();93 results.add(Collections.<String, Object>singletonMap("NAME", "Penny"));94 results.add(Collections.<String, Object>singletonMap("NAME", "Sheldon"));95 reset(jdbcTemplate);96 when(jdbcTemplate.queryForList("SELECT NAME FROM ACTORS")).thenReturn(results);97 when(jdbcTemplate.queryForList("SELECT COUNT(*) as CNT_EPISODES FROM EPISODES")).thenReturn(Collections.singletonList(Collections.<String, Object>singletonMap("CNT_EPISODES", "9999")));98 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {99 @Override100 public void execute() {101 query(builder -> builder.jdbcTemplate(jdbcTemplate)102 .statement("SELECT NAME FROM ACTORS")103 .statement("SELECT COUNT(*) as CNT_EPISODES FROM EPISODES")104 .validate("NAME", "Penny", "Sheldon")105 .validate("CNT_EPISODES", "9999")106 .extract("CNT_EPISODES", "cntEpisodes"));107 }108 };109 TestContext context = builder.getTestContext();110 Assert.assertNotNull(context.getVariable("NAME"));111 Assert.assertNotNull(context.getVariable("CNT_EPISODES"));112 Assert.assertNotNull(context.getVariable("cntEpisodes"));113 Assert.assertEquals(context.getVariable("NAME"), "Penny");114 Assert.assertEquals(context.getVariable("CNT_EPISODES"), "9999");115 Assert.assertEquals(context.getVariable("cntEpisodes"), "9999");116 TestCase test = builder.getTestCase();117 Assert.assertEquals(test.getActionCount(), 1);118 Assert.assertEquals(test.getActions().get(0).getClass(), ExecuteSQLQueryAction.class);119 120 ExecuteSQLQueryAction action = (ExecuteSQLQueryAction)test.getActions().get(0);121 122 Assert.assertEquals(action.getName(), "sql-query");123 Assert.assertEquals(action.getControlResultSet().size(), 2);124 Set<Map.Entry<String, List<String>>> rows = action.getControlResultSet().entrySet();125 Assert.assertEquals(getRow("NAME", rows).toString(), "NAME=[Penny, Sheldon]");126 Assert.assertEquals(getRow("CNT_EPISODES", rows).toString(), "CNT_EPISODES=[9999]");127 Assert.assertEquals(action.getExtractVariables().size(), 1);128 Assert.assertEquals(action.getExtractVariables().entrySet().iterator().next().toString(), "CNT_EPISODES=cntEpisodes");129 Assert.assertEquals(action.getStatements().size(), 2);130 Assert.assertEquals(action.getStatements().toString(), "[SELECT NAME FROM ACTORS, SELECT COUNT(*) as CNT_EPISODES FROM EPISODES]");131 Assert.assertNull(action.getScriptValidationContext());132 Assert.assertEquals(action.getJdbcTemplate(), jdbcTemplate);133 Assert.assertNull(action.getValidator());134 }135 @Test136 public void testExecuteSQLQueryWithTransaction() {137 List<Map<String, Object>> results = new ArrayList<>();138 results.add(Collections.<String, Object>singletonMap("NAME", "Penny"));139 results.add(Collections.<String, Object>singletonMap("NAME", "Sheldon"));140 reset(jdbcTemplate, transactionManager);141 when(jdbcTemplate.queryForList("SELECT NAME FROM ACTORS")).thenReturn(results);142 when(jdbcTemplate.queryForList("SELECT COUNT(*) as CNT_EPISODES FROM EPISODES")).thenReturn(Collections.singletonList(Collections.<String, Object>singletonMap("CNT_EPISODES", "9999")));143 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {144 @Override145 public void execute() {146 query(builder -> builder.jdbcTemplate(jdbcTemplate)147 .transactionManager(transactionManager)148 .transactionTimeout(5000)149 .transactionIsolationLevel("ISOLATION_READ_COMMITTED")150 .statement("SELECT NAME FROM ACTORS")151 .statement("SELECT COUNT(*) as CNT_EPISODES FROM EPISODES")152 .validate("NAME", "Penny", "Sheldon")153 .validate("CNT_EPISODES", "9999")154 .extract("CNT_EPISODES", "cntEpisodes"));155 }156 };157 TestContext context = builder.getTestContext();158 Assert.assertNotNull(context.getVariable("NAME"));159 Assert.assertNotNull(context.getVariable("CNT_EPISODES"));160 Assert.assertNotNull(context.getVariable("cntEpisodes"));161 Assert.assertEquals(context.getVariable("NAME"), "Penny");162 Assert.assertEquals(context.getVariable("CNT_EPISODES"), "9999");163 Assert.assertEquals(context.getVariable("cntEpisodes"), "9999");164 TestCase test = builder.getTestCase();165 Assert.assertEquals(test.getActionCount(), 1);166 Assert.assertEquals(test.getActions().get(0).getClass(), ExecuteSQLQueryAction.class);167 ExecuteSQLQueryAction action = (ExecuteSQLQueryAction)test.getActions().get(0);168 Assert.assertEquals(action.getName(), "sql-query");169 Assert.assertEquals(action.getControlResultSet().size(), 2);170 Set<Map.Entry<String, List<String>>> rows = action.getControlResultSet().entrySet();171 Assert.assertEquals(getRow("NAME", rows).toString(), "NAME=[Penny, Sheldon]");172 Assert.assertEquals(getRow("CNT_EPISODES", rows).toString(), "CNT_EPISODES=[9999]");173 Assert.assertEquals(action.getExtractVariables().size(), 1);174 Assert.assertEquals(action.getExtractVariables().entrySet().iterator().next().toString(), "CNT_EPISODES=cntEpisodes");175 Assert.assertEquals(action.getStatements().size(), 2);176 Assert.assertEquals(action.getStatements().toString(), "[SELECT NAME FROM ACTORS, SELECT COUNT(*) as CNT_EPISODES FROM EPISODES]");177 Assert.assertNull(action.getScriptValidationContext());178 Assert.assertEquals(action.getJdbcTemplate(), jdbcTemplate);179 Assert.assertEquals(action.getTransactionManager(), transactionManager);180 Assert.assertEquals(action.getTransactionTimeout(), "5000");181 Assert.assertEquals(action.getTransactionIsolationLevel(), "ISOLATION_READ_COMMITTED");182 Assert.assertNull(action.getValidator());183 }184 @Test185 public void testValidationScript() {186 List<Map<String, Object>> results = new ArrayList<>();187 results.add(Collections.<String, Object>singletonMap("NAME", "Penny"));188 results.add(Collections.<String, Object>singletonMap("NAME", "Sheldon"));189 reset(jdbcTemplate);190 when(jdbcTemplate.queryForList("SELECT NAME FROM ACTORS")).thenReturn(results);191 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {192 @Override193 public void execute() {194 query(builder -> builder.jdbcTemplate(jdbcTemplate)195 .statement("SELECT NAME FROM ACTORS")196 .validateScript("assert rows[0].NAME == 'Penny'\n" +197 "assert rows[1].NAME == 'Sheldon'", ScriptTypes.GROOVY));198 }199 };200 TestCase test = builder.getTestCase();201 Assert.assertEquals(test.getActionCount(), 1);202 Assert.assertEquals(test.getActions().get(0).getClass(), ExecuteSQLQueryAction.class);203 204 ExecuteSQLQueryAction action = (ExecuteSQLQueryAction)test.getActions().get(0);205 206 Assert.assertEquals(action.getName(), "sql-query");207 Assert.assertEquals(action.getControlResultSet().size(), 0);208 Assert.assertEquals(action.getExtractVariables().size(), 0);209 Assert.assertNotNull(action.getScriptValidationContext());210 Assert.assertTrue(action.getScriptValidationContext().getValidationScript().startsWith("assert rows[0].NAME == 'Penny'"));211 Assert.assertNull(action.getScriptValidationContext().getValidationScriptResourcePath());212 Assert.assertEquals(action.getStatements().size(), 1);213 Assert.assertEquals(action.getStatements().toString(), "[SELECT NAME FROM ACTORS]");214 Assert.assertEquals(action.getJdbcTemplate(), jdbcTemplate);215 }216 217 @Test218 public void testValidationScriptResource() throws IOException {219 List<Map<String, Object>> results = new ArrayList<>();220 results.add(Collections.<String, Object>singletonMap("NAME", "Radj"));221 reset(jdbcTemplate, resource);222 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("assert rows[0].NAME == 'Radj'".getBytes()));223 when(jdbcTemplate.queryForList("SELECT NAME FROM ACTORS")).thenReturn(results);224 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {225 @Override226 public void execute() {227 query(builder -> builder.jdbcTemplate(jdbcTemplate)228 .statement("SELECT NAME FROM ACTORS")229 .validateScript(resource, ScriptTypes.GROOVY));230 }231 };232 TestCase test = builder.getTestCase();233 Assert.assertEquals(test.getActionCount(), 1);234 Assert.assertEquals(test.getActions().get(0).getClass(), ExecuteSQLQueryAction.class);235 236 ExecuteSQLQueryAction action = (ExecuteSQLQueryAction)test.getActions().get(0);237 238 Assert.assertEquals(action.getName(), "sql-query");239 Assert.assertEquals(action.getControlResultSet().size(), 0);240 Assert.assertEquals(action.getExtractVariables().size(), 0);241 Assert.assertNotNull(action.getScriptValidationContext());242 Assert.assertEquals(action.getScriptValidationContext().getValidationScript(), "assert rows[0].NAME == 'Radj'");243 Assert.assertNull(action.getScriptValidationContext().getValidationScriptResourcePath());244 Assert.assertEquals(action.getStatements().size(), 1);245 Assert.assertEquals(action.getStatements().toString(), "[SELECT NAME FROM ACTORS]");246 Assert.assertEquals(action.getJdbcTemplate(), jdbcTemplate);247 }248 249 @Test250 public void testGroovyValidationScript() {251 List<Map<String, Object>> results = new ArrayList<>();252 results.add(Collections.<String, Object>singletonMap("NAME", "Howard"));253 results.add(Collections.<String, Object>singletonMap("NAME", "Sheldon"));254 reset(jdbcTemplate);255 when(jdbcTemplate.queryForList("SELECT NAME FROM ACTORS")).thenReturn(results);256 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {257 @Override258 public void execute() {259 query(builder -> builder.jdbcTemplate(jdbcTemplate)260 .statement("SELECT NAME FROM ACTORS")261 .groovy("assert rows[0].NAME == 'Howard'"));262 }263 };264 TestCase test = builder.getTestCase();265 Assert.assertEquals(test.getActionCount(), 1);266 Assert.assertEquals(test.getActions().get(0).getClass(), ExecuteSQLQueryAction.class);267 268 ExecuteSQLQueryAction action = (ExecuteSQLQueryAction)test.getActions().get(0);269 270 Assert.assertEquals(action.getName(), "sql-query");271 Assert.assertEquals(action.getControlResultSet().size(), 0);272 Assert.assertEquals(action.getExtractVariables().size(), 0);273 Assert.assertNotNull(action.getScriptValidationContext());274 Assert.assertEquals(action.getScriptValidationContext().getValidationScript(), "assert rows[0].NAME == 'Howard'");275 Assert.assertNull(action.getScriptValidationContext().getValidationScriptResourcePath());276 Assert.assertEquals(action.getStatements().size(), 1);277 Assert.assertEquals(action.getStatements().toString(), "[SELECT NAME FROM ACTORS]");278 Assert.assertEquals(action.getJdbcTemplate(), jdbcTemplate);279 }280 281 @Test282 public void testGroovyValidationScriptResource() throws IOException {283 List<Map<String, Object>> results = new ArrayList<>();284 results.add(Collections.<String, Object>singletonMap("NAME", "Penny"));285 results.add(Collections.<String, Object>singletonMap("NAME", "Howard"));286 results.add(Collections.<String, Object>singletonMap("NAME", "Sheldon"));287 reset(jdbcTemplate, resource);288 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("assert rows[1].NAME == 'Howard'".getBytes()));289 when(jdbcTemplate.queryForList("SELECT NAME FROM ACTORS")).thenReturn(results);290 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {291 @Override292 public void execute() {293 query(builder -> builder.jdbcTemplate(jdbcTemplate)294 .statement("SELECT NAME FROM ACTORS")295 .groovy(resource));296 }297 };298 299 TestCase test = builder.getTestCase();300 Assert.assertEquals(test.getActionCount(), 1);301 Assert.assertEquals(test.getActions().get(0).getClass(), ExecuteSQLQueryAction.class);302 303 ExecuteSQLQueryAction action = (ExecuteSQLQueryAction)test.getActions().get(0);304 305 Assert.assertEquals(action.getName(), "sql-query");306 Assert.assertEquals(action.getControlResultSet().size(), 0);307 Assert.assertEquals(action.getExtractVariables().size(), 0);308 Assert.assertNotNull(action.getScriptValidationContext());309 Assert.assertEquals(action.getScriptValidationContext().getValidationScript(), "assert rows[1].NAME == 'Howard'");310 Assert.assertNull(action.getScriptValidationContext().getValidationScriptResourcePath());311 Assert.assertEquals(action.getStatements().size(), 1);312 Assert.assertEquals(action.getStatements().toString(), "[SELECT NAME FROM ACTORS]");313 Assert.assertEquals(action.getJdbcTemplate(), jdbcTemplate);314 }315 @Test316 public void testCustomScriptValidator() {317 List<Map<String, Object>> results = new ArrayList<>();318 results.add(Collections.<String, Object>singletonMap("NAME", "Howard"));319 results.add(Collections.<String, Object>singletonMap("NAME", "Penny"));320 results.add(Collections.<String, Object>singletonMap("NAME", "Sheldon"));321 reset(jdbcTemplate, validator);322 when(jdbcTemplate.queryForList("SELECT NAME FROM ACTORS")).thenReturn(results);323 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {324 @Override325 public void execute() {326 query(builder -> builder.jdbcTemplate(jdbcTemplate)327 .statement("SELECT NAME FROM ACTORS")328 .groovy("assert rows[0].NAME == 'Howard'")329 .validator(validator));330 }331 };332 TestCase test = builder.getTestCase();333 Assert.assertEquals(test.getActionCount(), 1);334 Assert.assertEquals(test.getActions().get(0).getClass(), ExecuteSQLQueryAction.class);335 ExecuteSQLQueryAction action = (ExecuteSQLQueryAction)test.getActions().get(0);336 Assert.assertEquals(action.getName(), "sql-query");337 Assert.assertEquals(action.getControlResultSet().size(), 0);338 Assert.assertEquals(action.getExtractVariables().size(), 0);339 Assert.assertNotNull(action.getScriptValidationContext());340 Assert.assertEquals(action.getScriptValidationContext().getValidationScript(), "assert rows[0].NAME == 'Howard'");341 Assert.assertNull(action.getScriptValidationContext().getValidationScriptResourcePath());342 Assert.assertEquals(action.getStatements().size(), 1);343 Assert.assertEquals(action.getStatements().toString(), "[SELECT NAME FROM ACTORS]");344 Assert.assertEquals(action.getJdbcTemplate(), jdbcTemplate);345 Assert.assertEquals(action.getValidator(), validator);346 verify(validator).validateSqlResultSet(any(List.class), any(ScriptValidationContext.class), any(TestContext.class));347 }348 /**349 * Gets row from result set with given column name.350 * @param columnName351 * @param rows...

Full Screen

Full Screen

Source:ExecuteSQLQueryTestDesignerTest.java Github

copy

Full Screen

...60 61 ExecuteSQLQueryAction action = (ExecuteSQLQueryAction)test.getActions().get(0);62 63 Assert.assertEquals(action.getName(), "sql-query");64 Assert.assertEquals(action.getControlResultSet().size(), 1);65 Assert.assertEquals(action.getControlResultSet().entrySet().iterator().next().toString(), "COLUMN=[value]");66 Assert.assertEquals(action.getExtractVariables().size(), 1);67 Assert.assertEquals(action.getExtractVariables().entrySet().iterator().next().toString(), "COLUMN=variable");68 Assert.assertNull(action.getScriptValidationContext());69 Assert.assertEquals(action.getDataSource(), dataSource);70 Assert.assertEquals(action.getStatements().size(), 1);71 Assert.assertEquals(action.getStatements().get(0), "SELECT * FROM DUAL;");72 Assert.assertNull(action.getSqlResourcePath());73 Assert.assertNull(action.getValidator());74 }75 76 @Test77 public void testExecuteSQLQueryWithStatements() {78 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {79 @Override80 public void configure() {81 query(dataSource)82 .statement("stmt1")83 .statement("stmt2")84 .statement("stmt3")85 .validate("COLUMN", "value1", "value2")86 .extract("COLUMN", "variable");87 }88 };89 builder.configure();90 TestCase test = builder.getTestCase();91 Assert.assertEquals(test.getActionCount(), 1);92 Assert.assertEquals(test.getActions().get(0).getClass(), ExecuteSQLQueryAction.class);93 94 ExecuteSQLQueryAction action = (ExecuteSQLQueryAction)test.getActions().get(0);95 96 Assert.assertEquals(action.getName(), "sql-query");97 Assert.assertEquals(action.getControlResultSet().size(), 1);98 Assert.assertEquals(action.getControlResultSet().entrySet().iterator().next().toString(), "COLUMN=[value1, value2]");99 Assert.assertEquals(action.getExtractVariables().size(), 1);100 Assert.assertEquals(action.getExtractVariables().entrySet().iterator().next().toString(), "COLUMN=variable");101 Assert.assertEquals(action.getStatements().size(), 3);102 Assert.assertEquals(action.getStatements().toString(), "[stmt1, stmt2, stmt3]");103 Assert.assertNull(action.getScriptValidationContext());104 Assert.assertEquals(action.getDataSource(), dataSource);105 Assert.assertNull(action.getValidator());106 }107 @Test108 public void testExecuteSQLQueryWithTransaction() {109 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {110 @Override111 public void configure() {112 query(dataSource)113 .transactionManager(transactionManager)114 .transactionTimeout(5000)115 .transactionIsolationLevel("ISOLATION_READ_COMMITTED")116 .statement("stmt1")117 .statement("stmt2")118 .statement("stmt3")119 .validate("COLUMN", "value1", "value2")120 .extract("COLUMN", "variable");121 }122 };123 builder.configure();124 TestCase test = builder.getTestCase();125 Assert.assertEquals(test.getActionCount(), 1);126 Assert.assertEquals(test.getActions().get(0).getClass(), ExecuteSQLQueryAction.class);127 ExecuteSQLQueryAction action = (ExecuteSQLQueryAction)test.getActions().get(0);128 Assert.assertEquals(action.getName(), "sql-query");129 Assert.assertEquals(action.getControlResultSet().size(), 1);130 Assert.assertEquals(action.getControlResultSet().entrySet().iterator().next().toString(), "COLUMN=[value1, value2]");131 Assert.assertEquals(action.getExtractVariables().size(), 1);132 Assert.assertEquals(action.getExtractVariables().entrySet().iterator().next().toString(), "COLUMN=variable");133 Assert.assertEquals(action.getStatements().size(), 3);134 Assert.assertEquals(action.getStatements().toString(), "[stmt1, stmt2, stmt3]");135 Assert.assertNull(action.getScriptValidationContext());136 Assert.assertEquals(action.getDataSource(), dataSource);137 Assert.assertNull(action.getValidator());138 Assert.assertEquals(action.getTransactionManager(), transactionManager);139 Assert.assertEquals(action.getTransactionTimeout(), "5000");140 Assert.assertEquals(action.getTransactionIsolationLevel(), "ISOLATION_READ_COMMITTED");141 }142 143 @Test144 public void testValidationScript() {145 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {146 @Override147 public void configure() {148 query(dataSource)149 .statement("stmt")150 .validateScript("assert rows[0].COLUMN == 'value1'", ScriptTypes.GROOVY);151 }152 };153 builder.configure();154 TestCase test = builder.getTestCase();155 Assert.assertEquals(test.getActionCount(), 1);156 Assert.assertEquals(test.getActions().get(0).getClass(), ExecuteSQLQueryAction.class);157 158 ExecuteSQLQueryAction action = (ExecuteSQLQueryAction)test.getActions().get(0);159 160 Assert.assertEquals(action.getName(), "sql-query");161 Assert.assertEquals(action.getControlResultSet().size(), 0);162 Assert.assertEquals(action.getExtractVariables().size(), 0);163 Assert.assertNotNull(action.getScriptValidationContext());164 Assert.assertEquals(action.getScriptValidationContext().getValidationScript(), "assert rows[0].COLUMN == 'value1'");165 Assert.assertNull(action.getScriptValidationContext().getValidationScriptResourcePath());166 Assert.assertEquals(action.getStatements().size(), 1);167 Assert.assertEquals(action.getStatements().toString(), "[stmt]");168 Assert.assertEquals(action.getDataSource(), dataSource);169 }170 171 @Test172 public void testValidationScriptResource() throws IOException {173 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {174 @Override175 public void configure() {176 query(dataSource)177 .statement("stmt")178 .validateScript(resource, ScriptTypes.GROOVY);179 }180 };181 182 reset(resource);183 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("someScript".getBytes()));184 builder.configure();185 TestCase test = builder.getTestCase();186 Assert.assertEquals(test.getActionCount(), 1);187 Assert.assertEquals(test.getActions().get(0).getClass(), ExecuteSQLQueryAction.class);188 189 ExecuteSQLQueryAction action = (ExecuteSQLQueryAction)test.getActions().get(0);190 191 Assert.assertEquals(action.getName(), "sql-query");192 Assert.assertEquals(action.getControlResultSet().size(), 0);193 Assert.assertEquals(action.getExtractVariables().size(), 0);194 Assert.assertNotNull(action.getScriptValidationContext());195 Assert.assertEquals(action.getScriptValidationContext().getValidationScript(), "someScript");196 Assert.assertNull(action.getScriptValidationContext().getValidationScriptResourcePath());197 Assert.assertEquals(action.getStatements().size(), 1);198 Assert.assertEquals(action.getStatements().toString(), "[stmt]");199 Assert.assertEquals(action.getDataSource(), dataSource);200 }201 202 @Test203 public void testGroovyValidationScript() {204 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {205 @Override206 public void configure() {207 query(dataSource)208 .statement("stmt")209 .groovy("assert rows[0].COLUMN == 'value1'");210 }211 };212 builder.configure();213 TestCase test = builder.getTestCase();214 Assert.assertEquals(test.getActionCount(), 1);215 Assert.assertEquals(test.getActions().get(0).getClass(), ExecuteSQLQueryAction.class);216 217 ExecuteSQLQueryAction action = (ExecuteSQLQueryAction)test.getActions().get(0);218 219 Assert.assertEquals(action.getName(), "sql-query");220 Assert.assertEquals(action.getControlResultSet().size(), 0);221 Assert.assertEquals(action.getExtractVariables().size(), 0);222 Assert.assertNotNull(action.getScriptValidationContext());223 Assert.assertEquals(action.getScriptValidationContext().getValidationScript(), "assert rows[0].COLUMN == 'value1'");224 Assert.assertNull(action.getScriptValidationContext().getValidationScriptResourcePath());225 Assert.assertEquals(action.getStatements().size(), 1);226 Assert.assertEquals(action.getStatements().toString(), "[stmt]");227 Assert.assertEquals(action.getDataSource(), dataSource);228 }229 230 @Test231 public void testGroovyValidationScriptResource() throws IOException {232 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {233 @Override234 public void configure() {235 query(dataSource)236 .statement("stmt")237 .groovy(resource);238 }239 };240 241 reset(resource);242 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("someScript".getBytes()));243 builder.configure();244 TestCase test = builder.getTestCase();245 Assert.assertEquals(test.getActionCount(), 1);246 Assert.assertEquals(test.getActions().get(0).getClass(), ExecuteSQLQueryAction.class);247 248 ExecuteSQLQueryAction action = (ExecuteSQLQueryAction)test.getActions().get(0);249 250 Assert.assertEquals(action.getName(), "sql-query");251 Assert.assertEquals(action.getControlResultSet().size(), 0);252 Assert.assertEquals(action.getExtractVariables().size(), 0);253 Assert.assertNotNull(action.getScriptValidationContext());254 Assert.assertEquals(action.getScriptValidationContext().getValidationScript(), "someScript");255 Assert.assertNull(action.getScriptValidationContext().getValidationScriptResourcePath());256 Assert.assertEquals(action.getStatements().size(), 1);257 Assert.assertEquals(action.getStatements().toString(), "[stmt]");258 Assert.assertEquals(action.getDataSource(), dataSource);259 }260 @Test261 public void testCustomScriptValidator() {262 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {263 @Override264 public void configure() {265 query(dataSource)266 .statement("stmt")267 .validateScript("assert something", ScriptTypes.GROOVY)268 .validator(validator);269 }270 };271 builder.configure();272 TestCase test = builder.getTestCase();273 Assert.assertEquals(test.getActionCount(), 1);274 Assert.assertEquals(test.getActions().get(0).getClass(), ExecuteSQLQueryAction.class);275 ExecuteSQLQueryAction action = (ExecuteSQLQueryAction)test.getActions().get(0);276 Assert.assertEquals(action.getName(), "sql-query");277 Assert.assertEquals(action.getControlResultSet().size(), 0);278 Assert.assertEquals(action.getExtractVariables().size(), 0);279 Assert.assertNotNull(action.getScriptValidationContext());280 Assert.assertEquals(action.getScriptValidationContext().getValidationScript(), "assert something");281 Assert.assertNull(action.getScriptValidationContext().getValidationScriptResourcePath());282 Assert.assertEquals(action.getStatements().size(), 1);283 Assert.assertEquals(action.getStatements().toString(), "[stmt]");284 Assert.assertEquals(action.getDataSource(), dataSource);285 Assert.assertEquals(action.getValidator(), validator);286 }287}...

Full Screen

Full Screen

Source:ExecuteSQLQueryActionParserTest.java Github

copy

Full Screen

...35 Assert.assertNull(action.getSqlResourcePath());36 Assert.assertEquals(action.getStatements().size(), 2);37 Assert.assertEquals(action.getStatements().get(0), "select A, B, C from D where E='${id}'");38 Assert.assertEquals(action.getStatements().get(1), "select COUNT(F) as cnt_f from G");39 Assert.assertEquals(action.getControlResultSet().size(), 4);40 Assert.assertEquals(action.getControlResultSet().get("A").size(), 1);41 Assert.assertEquals(action.getControlResultSet().get("A").get(0), "a");42 Assert.assertEquals(action.getControlResultSet().get("B").size(), 1);43 Assert.assertEquals(action.getControlResultSet().get("B").get(0), "b");44 Assert.assertEquals(action.getControlResultSet().get("C").size(), 1);45 Assert.assertEquals(action.getControlResultSet().get("C").get(0), "NULL");46 Assert.assertEquals(action.getControlResultSet().get("CNT_F").get(0), "${count}");47 Assert.assertNull(action.getTransactionManager());48 Assert.assertEquals(action.getTransactionTimeout(), "-1");49 Assert.assertEquals(action.getTransactionIsolationLevel(), "ISOLATION_DEFAULT");50 Assert.assertNull(action.getScriptValidationContext());51 Assert.assertEquals(action.getExtractVariables().size(), 0);52 53 // 2nd action54 action = getNextTestActionFromTest();55 Assert.assertNotNull(action.getDataSource());56 Assert.assertNotNull(action.getSqlResourcePath());57 Assert.assertEquals(action.getSqlResourcePath(), "classpath:com/consol/citrus/actions/test-sql-query-statements.sql");58 Assert.assertEquals(action.getStatements().size(), 0);59 Assert.assertEquals(action.getControlResultSet().size(), 1);60 Assert.assertEquals(action.getControlResultSet().get("foo").get(0), "1");61 Assert.assertNotNull(action.getTransactionManager());62 Assert.assertEquals(action.getTransactionManager(), beanDefinitionContext.getBean("testTransactionManager", PlatformTransactionManager.class));63 Assert.assertEquals(action.getTransactionTimeout(), "5000");64 Assert.assertEquals(action.getTransactionIsolationLevel(), "ISOLATION_READ_COMMITTED");65 Assert.assertNull(action.getScriptValidationContext());66 Assert.assertEquals(action.getExtractVariables().size(), 0);67 68 // 3rd action69 action = getNextTestActionFromTest();70 Assert.assertNotNull(action.getDataSource());71 Assert.assertNull(action.getSqlResourcePath());72 Assert.assertEquals(action.getStatements().size(), 1);73 Assert.assertEquals(action.getStatements().get(0), "select A as A_COLUMN, B as B_COLUMN from C");74 Assert.assertEquals(action.getControlResultSet().size(), 2);75 Assert.assertEquals(action.getControlResultSet().get("A_COLUMN").size(), 2);76 Assert.assertEquals(action.getControlResultSet().get("A_COLUMN").get(0), "a");77 Assert.assertEquals(action.getControlResultSet().get("A_COLUMN").get(1), "@ignore@");78 Assert.assertEquals(action.getControlResultSet().get("B_COLUMN").size(), 2);79 Assert.assertEquals(action.getControlResultSet().get("B_COLUMN").get(0), "b");80 Assert.assertEquals(action.getControlResultSet().get("B_COLUMN").get(1), "NULL");81 Assert.assertNull(action.getScriptValidationContext());82 Assert.assertEquals(action.getExtractVariables().size(), 2);83 Assert.assertEquals(action.getExtractVariables().get("A_COLUMN"), "a_values");84 Assert.assertEquals(action.getExtractVariables().get("B_COLUMN"), "b_values");85 // 4th action86 action = getNextTestActionFromTest();87 Assert.assertNotNull(action.getDataSource());88 Assert.assertNull(action.getSqlResourcePath());89 Assert.assertEquals(action.getStatements().size(), 1);90 Assert.assertEquals(action.getStatements().get(0), "select A as A_COLUMN, B as B_COLUMN from C");91 Assert.assertEquals(action.getControlResultSet().size(), 0);92 Assert.assertEquals(action.getExtractVariables().size(), 0);93 94 Assert.assertNotNull(action.getScriptValidationContext());95 Assert.assertNull(action.getScriptValidationContext().getValidationScriptResourcePath());96 Assert.assertEquals(action.getScriptValidationContext().getValidationScript().trim(), "assert rows.size == 2");97 98 // 5th action99 action = getNextTestActionFromTest();100 Assert.assertNotNull(action.getDataSource());101 Assert.assertNull(action.getSqlResourcePath());102 Assert.assertEquals(action.getStatements().size(), 1);103 Assert.assertEquals(action.getStatements().get(0), "select A as A_COLUMN, B as B_COLUMN from C");104 Assert.assertEquals(action.getControlResultSet().size(), 0);105 Assert.assertEquals(action.getExtractVariables().size(), 0);106 107 Assert.assertNotNull(action.getScriptValidationContext());108 Assert.assertNotNull(action.getScriptValidationContext().getValidationScriptResourcePath());109 Assert.assertEquals(action.getScriptValidationContext().getValidationScriptResourcePath(), "classpath:com/consol/citrus/script/example.groovy");110 Assert.assertEquals(action.getScriptValidationContext().getValidationScript(), "");111 }112 113 @Test114 public void testMissingDataSourceBeanRef() {115 try {116 createApplicationContext("failed");117 Assert.fail("Missing bean creation exception due to invalid data source");118 } catch (BeanDefinitionStoreException e) {...

Full Screen

Full Screen

getControlResultSet

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import com.consol.citrus.actions.ExecuteSQLQueryAction;3import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;4import org.testng.annotations.Test;5public class ExecuteSQLQueryActionTest extends TestNGCitrusTestDesigner {6 public void test() {7 variable("SQLQuery", "select * from test_table");8 ExecuteSQLQueryAction.Builder builder = new ExecuteSQLQueryAction.Builder();9 builder.query("${SQLQuery}");10 builder.dataSource("dataSource");11 builder.validationCallback(new SqlQueryValidationCallback() {12 public void validate(ResultSet rs) throws SQLException {13 }14 });15 builder.build().execute(context);16 }17}18package com.consol.citrus;19import com.consol.citrus.actions.ExecuteSQLQueryAction;20import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;21import org.testng.annotations.Test;22public class ExecuteSQLQueryActionTest extends TestNGCitrusTestDesigner {23 public void test() {24 variable("SQLQuery", "select * from test_table");25 ExecuteSQLQueryAction.Builder builder = new ExecuteSQLQueryAction.Builder();26 builder.query("${SQLQuery}");27 builder.dataSource("dataSource");28 builder.validationCallback(new SqlQueryValidationCallback() {29 public void validate(ResultSet rs) throws SQLException {30 }31 });32 builder.build().execute(context);33 }34}35package com.consol.citrus;36import com.consol.citrus.actions.ExecuteSQLQueryAction;37import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;38import org.testng.annotations.Test;39public class ExecuteSQLQueryActionTest extends TestNGCitrusTestDesigner {40 public void test() {41 variable("SQLQuery", "select * from test_table");42 ExecuteSQLQueryAction.Builder builder = new ExecuteSQLQueryAction.Builder();43 builder.query("${SQLQuery}");44 builder.dataSource("dataSource");45 builder.validationCallback(new SqlQueryValidationCallback() {

Full Screen

Full Screen

getControlResultSet

Using AI Code Generation

copy

Full Screen

1package org.citrusframework.demo;2import org.springframework.context.support.ClassPathXmlApplicationContext;3import org.testng.annotations.Test;4import com.consol.citrus.annotations.CitrusTest;5import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;6public class 4 extends TestNGCitrusTestDesigner {7 public void 4() {8 description("4");9 echo("4");10 ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");11 ExecuteSQLQueryAction sqlQuery = ctx.getBean(ExecuteSQLQueryAction.class);12 sqlQuery.setDataSource(ctx.getBean(DataSource.class));13 sqlQuery.setSqlResource(new ClassPathResource("sql/4.sql"));14 sqlQuery.getControlResultSet().addRow("1");15 sqlQuery.getControlResultSet().addRow("2");16 sqlQuery.getControlResultSet().addRow("3");17 sqlQuery.getControlResultSet().addRow("4");18 sqlQuery.getControlResultSet().addRow("5");19 sqlQuery.getControlResultSet().addRow("6");20 sqlQuery.getControlResultSet().addRow("7");21 sqlQuery.getControlResultSet().addRow("8");22 sqlQuery.getControlResultSet().addRow("9");23 sqlQuery.getControlResultSet().addRow("10");24 sqlQuery.getControlResultSet().addRow("11");25 sqlQuery.getControlResultSet().addRow("12");26 sqlQuery.getControlResultSet().addRow("13");27 sqlQuery.getControlResultSet().addRow("14");28 sqlQuery.getControlResultSet().addRow("15");29 sqlQuery.getControlResultSet().addRow("16");30 sqlQuery.getControlResultSet().addRow("17");31 sqlQuery.getControlResultSet().addRow("18");32 sqlQuery.getControlResultSet().addRow("19");33 sqlQuery.getControlResultSet().addRow("20");34 sqlQuery.getControlResultSet().addRow("21");35 sqlQuery.getControlResultSet().addRow("22");36 sqlQuery.getControlResultSet().addRow("23");37 sqlQuery.getControlResultSet().addRow("24");38 sqlQuery.getControlResultSet().addRow("25");39 sqlQuery.getControlResultSet().addRow("26");40 sqlQuery.getControlResultSet().addRow("27");41 sqlQuery.getControlResultSet().addRow("28");42 sqlQuery.getControlResultSet().addRow("

Full Screen

Full Screen

getControlResultSet

Using AI Code Generation

copy

Full Screen

1public class 4.java {2 public static void main(String[] args) {3 ExecuteSQLQueryAction executeSQLQueryAction1 = new ExecuteSQLQueryAction();4 executeSQLQueryAction1.setDataSource(new DriverManagerDataSource("jdbc:h2:mem:testdb", "sa", ""));5 executeSQLQueryAction1.setSqlResource(new ClassPathResource("sql/4.sql"));6 executeSQLQueryAction1.getControlResultSet();7 }8}9public class 5.java {10 public static void main(String[] args) {11 ExecuteSQLQueryAction executeSQLQueryAction1 = new ExecuteSQLQueryAction();12 executeSQLQueryAction1.setDataSource(new DriverManagerDataSource("jdbc:h2:mem:testdb", "sa", ""));13 executeSQLQueryAction1.setSqlResource(new ClassPathResource("sql/5.sql"));14 executeSQLQueryAction1.setControlResult(new ArrayList<Map<String, Object>>());15 }16}17public class 6.java {18 public static void main(String[] args) {19 ExecuteSQLQueryAction executeSQLQueryAction1 = new ExecuteSQLQueryAction();20 executeSQLQueryAction1.setDataSource(new DriverManagerDataSource("jdbc:h2:mem:testdb", "sa", ""));21 executeSQLQueryAction1.setSqlResource(new ClassPathResource("sql/6.sql"));22 executeSQLQueryAction1.getControlResult();23 }24}25public class 7.java {26 public static void main(String[] args) {27 ExecuteSQLQueryAction executeSQLQueryAction1 = new ExecuteSQLQueryAction();28 executeSQLQueryAction1.setDataSource(new DriverManagerDataSource("jdbc:h2:mem:testdb", "sa", ""));29 executeSQLQueryAction1.setSqlResource(new ClassPathResource("sql/7.sql"));30 executeSQLQueryAction1.setIgnoreErrors(true);31 }32}33public class 8.java {34 public static void main(String[] args) {

Full Screen

Full Screen

getControlResultSet

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.runner;2import org.testng.annotations.Test;3import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;4public class ExecuteSQLQueryAction extends TestNGCitrusTestRunner {5public void executeSQLQueryAction() {6variable("query", "select * from employee");7variable("controlResultSet", "select * from employee");8executeSQLQuery()9.query("${query}")10.getControlResultSet("${controlResultSet}")11.validateResultSet()12.rows()13.row(0)14.column(0, "1")15.column(1, "John")16.column(2, "Doe")17.column(3, "

Full Screen

Full Screen

getControlResultSet

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;4import org.springframework.beans.factory.annotation.Autowired;5import org.springframework.jdbc.core.JdbcTemplate;6import org.testng.annotations.Test;7import javax.sql.DataSource;8public class ExecuteSQLQueryActionJavaIT extends TestNGCitrusTestDesigner {9 private DataSource dataSource;10 public void executeSQLQueryActionJavaIT() {11 description("ExecuteSQLQueryAction sample");12 variable("query", "SELECT * FROM ACTOR");13 echo("Executing query: ${query}");14 executeSQLQuery(dataSource)15 .statement("${query}")16 .validate("ACTOR_ID", "1")17 .validate("FIRST_NAME", "PENELOPE")18 .validate("LAST_NAME", "GUINESS")19 .validate("LAST_UPDATE", "2006-02-15 04:34:33.0");20 echo("Query executed successfully");21 }22}23package com.consol.citrus.samples;24import com.consol.citrus.annotations.CitrusTest;25import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;26import org.springframework.beans.factory.annotation.Autowired;27import org.springframework.jdbc.core.JdbcTemplate;28import org.testng.annotations.Test;29import javax.sql.DataSource;30public class ExecuteSQLQueryActionJavaIT extends TestNGCitrusTestDesigner {31 private DataSource dataSource;32 public void executeSQLQueryActionJavaIT() {33 description("ExecuteSQLQueryAction sample");34 variable("query", "SELECT * FROM ACTOR");35 echo("Executing query: ${query}");36 executeSQLQuery(dataSource)37 .statement("${query}")38 .validate("ACTOR_ID", "1")39 .validate("FIRST_NAME", "PENELOPE")40 .validate("LAST_NAME", "GUINESS")41 .validate("LAST_UPDATE", "2006-02-15 04:34:33.0");42 echo("Query executed successfully");43 }44}

Full Screen

Full Screen

getControlResultSet

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import java.io.File;3import java.io.IOException;4import java.util.ArrayList;5import java.util.List;6import javax.sql.DataSource;7import org.springframework.context.support.ClassPathXmlApplicationContext;8import org.springframework.core.io.FileSystemResource;9import org.springframework.jdbc.core.JdbcTemplate;10import com.consol.citrus.actions.ExecuteSQLQueryAction;11import com.consol.citrus.context.TestContext;12import com.consol.citrus.db.driver.JdbcResultSet;13import com.consol.citrus.db.server.JdbcServer;14import com.consol.citrus.db.server.JdbcServerConfiguration;15import com.consol.citrus.db.server.JdbcServerConfigurationBuilder;16import com.consol.citrus.db.server.JdbcServerControl;17import com.consol.citrus.db.server.controller.JdbcServerController;18import com.consol.citrus.db.server.controller.JdbcServerControllerImpl;19import com.consol.citrus.db.server.controller.JdbcServerControllerImpl.JdbcServerControllerImplBuilder;20import com.consol.citrus.db.server.controller.JdbcServerControllerImpl.JdbcServerControllerImplBuilder.JdbcServerControllerImplBuilderImpl;21import com.consol.citrus.db.server.controller.JdbcServerControllerImpl.JdbcServerControllerImplBuilder.JdbcServerControllerImplBuilderImpl.JdbcServerControllerImplBuilderImplBuilder;22import com.consol.citrus.db.server.controller.JdbcServerControllerImpl.JdbcServerControllerImplBuilder.JdbcServerControllerImplBuilderImpl.JdbcServerControllerImplBuilderImplBuilder.JdbcServerControllerImplBuilderImplBuilderImpl;23import com.consol.citrus.db.server.controller.JdbcServerControllerImpl.JdbcServerControllerImplBuilder.JdbcServerControllerImplBuilderImpl.JdbcServerControllerImplBuilderImplBuilder.JdbcServerControllerImplBuilderImplBuilderImpl.JdbcServerControllerImplBuilderImplBuilderImplBuilder;24import com.consol.citrus.db.server.controller.JdbcServerControllerImpl.JdbcServerControllerImplBuilder.JdbcServerControllerImplBuilderImpl.JdbcServerControllerImplBuilderImplBuilder.JdbcServerControllerImplBuilderImplBuilderImpl.JdbcServerControllerImplBuilderImplBuilderImplBuilder.JdbcServerControllerImplBuilderImplBuilderImplBuilderImpl;25import com.consol.citrus.db.server.controller.JdbcServerControllerImpl.JdbcServerControllerImplBuilder.JdbcServerControllerImplBuilderImpl.JdbcServerControllerImplBuilderImplBuilder.JdbcServerControllerImplBuilderImplBuilderImpl.Jdbc

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