Skip to content

Commit

Permalink
(#29) Improved Demo and E2E-Test
Browse files Browse the repository at this point in the history
  • Loading branch information
svettwer committed Feb 5, 2019
1 parent d7472e0 commit d9811f5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -75,11 +78,11 @@ String addNewProjects (@RequestParam final String names) {
@GetMapping(path="/findId")
public @ResponseBody Iterable<City> 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<String, Object> call = jdbcTemplate.call(createCallableStatement(name), createParameters());
final ArrayList<LinkedCaseInsensitiveMap> resultSet = (ArrayList<LinkedCaseInsensitiveMap>) 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }]"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());


Expand Down

0 comments on commit d9811f5

Please sign in to comment.