Skip to content

Commit

Permalink
- Improved 404 reporting in GET
Browse files Browse the repository at this point in the history
 - Added test for health and metrics

Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>
  • Loading branch information
spericas committed Jun 26, 2020
1 parent 55fd7e4 commit 077ad5d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public class PokemonResource {
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
public Pokemon getPokemonById(@PathParam("id") String id) {
try {
return entityManager.find(Pokemon.class, Integer.valueOf(id));
} catch (IllegalArgumentException e) {
Pokemon pokemon = entityManager.find(Pokemon.class, Integer.valueOf(id));
if (pokemon == null) {
throw new NotFoundException("Unable to find pokemon with ID " + id);
}
return pokemon;
}

@DELETE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ class MainTest {
assertThat(getPokemonCount(), is(6));
}

@Test
void testHealthMetrics() {
Response response = client.target(getConnectionString("/health"))
.request()
.get();
assertThat(response.getStatus(), is(200));
response = client.target(getConnectionString("/metrics"))
.request()
.get();
assertThat(response.getStatus(), is(200));
}

private int getPokemonCount() {
JsonArray pokemons = client.target(getConnectionString("/pokemon"))
.request()
Expand Down

0 comments on commit 077ad5d

Please sign in to comment.