From d9811f51d400eae0d11812120aa0cb09bd66f5ed Mon Sep 17 00:00:00 2001 From: Sven Hettwer Date: Tue, 5 Feb 2019 10:20:07 +0100 Subject: [PATCH] (#29) Improved Demo and E2E-Test --- .../citrus/demo/controller/CityController.java | 13 ++++++++----- .../com/consol/citrus/demo/DemoApplicationIT.java | 2 +- .../java/com/consol/citrus/demo/DemoJdbcServer.java | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/demo/src/main/java/com/consol/citrus/demo/controller/CityController.java b/demo/src/main/java/com/consol/citrus/demo/controller/CityController.java index b117d93..9c12967 100644 --- a/demo/src/main/java/com/consol/citrus/demo/controller/CityController.java +++ b/demo/src/main/java/com/consol/citrus/demo/controller/CityController.java @@ -8,15 +8,18 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.SqlParameter; import org.springframework.stereotype.Controller; +import org.springframework.util.LinkedCaseInsensitiveMap; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import java.sql.CallableStatement; import java.sql.JDBCType; import java.sql.Types; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** @@ -75,11 +78,11 @@ String addNewProjects (@RequestParam final String names) { @GetMapping(path="/findId") public @ResponseBody Iterable findCityByName(@RequestParam(defaultValue = "") final String name) { if (StringUtils.hasText(name)) { - return jdbcTemplate.call(createCallableStatement(name), createParameters()) - .values() - .stream() - .map(o -> (City) o ) - .collect(Collectors.toList()); + final Map call = jdbcTemplate.call(createCallableStatement(name), createParameters()); + final ArrayList resultSet = (ArrayList) call.get("#result-set-1"); + return resultSet.stream().map(linkedCaseInsensitiveMap -> + new City(Long.valueOf((Integer) linkedCaseInsensitiveMap.get("id")), (String) linkedCaseInsensitiveMap.get("name")) + ).collect(Collectors.toList()); } return Collections.emptyList(); diff --git a/demo/src/test/java/com/consol/citrus/demo/DemoApplicationIT.java b/demo/src/test/java/com/consol/citrus/demo/DemoApplicationIT.java index 5209dfa..ee12f67 100644 --- a/demo/src/test/java/com/consol/citrus/demo/DemoApplicationIT.java +++ b/demo/src/test/java/com/consol/citrus/demo/DemoApplicationIT.java @@ -92,6 +92,6 @@ public void testGetIdByCityName() { http(action -> action.client(httpClient) .receive() .response(HttpStatus.OK) - .payload("{ \"name\": \"Munich\", \"id\": 1 }")); + .payload("[{ \"name\": \"Munich\", \"id\": 1 }]")); } } \ No newline at end of file diff --git a/demo/src/test/java/com/consol/citrus/demo/DemoJdbcServer.java b/demo/src/test/java/com/consol/citrus/demo/DemoJdbcServer.java index a6af59d..3b8ae4d 100644 --- a/demo/src/test/java/com/consol/citrus/demo/DemoJdbcServer.java +++ b/demo/src/test/java/com/consol/citrus/demo/DemoJdbcServer.java @@ -43,7 +43,7 @@ public static void main(final String[] args) throws IOException, SQLException { dbServer.when() .statement() - .execute(Pattern.compile("CALL findCityByName \\(Munich, .*")) + .execute(Pattern.compile("CALL findCityByName\\(\\?,\\?\\) - \\(\\?,Munich\\)")) .thenReturn(new JsonDataSetProducer("[{ \"name\": \"Munich\", \"id\": 1 }]").produce());