Skip to content

Commit

Permalink
Fixed different output in DbClient SE archetype (helidon-io#2703)
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Kraus <Tomas.Kraus@oracle.com>
  • Loading branch information
Tomas-Kraus authored Feb 1, 2021
1 parent 32cc140 commit 8feb893
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class PokemonService implements Service {
.execute())
.thenAccept(maybeRow -> maybeRow
.ifPresentOrElse(
row -> sendRow(row, response),
row -> response.send(row.as(Pokemon.class)),
() -> sendNotFound(response, "Pokemon " + pokemonId + " not found")))
.exceptionally(throwable -> sendError(throwable, response));
} catch (NumberFormatException ex) {
Expand All @@ -85,13 +85,10 @@ public class PokemonService implements Service {
private void getPokemonByName(ServerRequest request, ServerResponse response) {
String pokemonName = request.path().param("name");
dbClient.execute(exec -> exec.namedGet("select-pokemon-by-name", pokemonName))
.thenAccept(it -> {
if (it.isEmpty()) {
sendNotFound(response, "Pokemon " + pokemonName + " not found");
} else {
sendRow(it.get(), response);
}
})
.thenAccept(maybeRow -> maybeRow
.ifPresentOrElse(
row -> response.send(row.as(Pokemon.class)),
() -> sendNotFound(response, "Pokemon " + pokemonName + " not found")))
.exceptionally(throwable -> sendError(throwable, response));
}

Expand Down Expand Up @@ -123,10 +120,6 @@ public class PokemonService implements Service {
response.send(message);
}

private void sendRow(DbRow row, ServerResponse response) {
response.send(row.as(javax.json.JsonObject.class));
}

/**
* Send a 500 response code and a few details.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ public class MainTest {
webClient.get()
.path("/pokemon/1")
.request(JsonObject.class)
.thenAccept(pokemon -> assertThat(pokemon.getString("NAME"), is("Bulbasaur")))
.thenAccept(pokemon -> assertThat(pokemon.getString("name"), is("Bulbasaur")))
.toCompletableFuture()
.get();
webClient.get()
.path("/pokemon/name/Charmander")
.request(JsonObject.class)
.thenAccept(pokemon -> assertThat(pokemon.getJsonNumber("ID_TYPE").intValue(), is(10)))
.thenAccept(pokemon -> assertThat(pokemon.getJsonNumber("idType").intValue(), is(10)))
.toCompletableFuture()
.get();
Expand Down

0 comments on commit 8feb893

Please sign in to comment.