CommitRest { @GET @Path("{commitId}") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves the Commit specified by the provided ID.") public Response getCommit(@PathParam("commitId") String commitId, @DefaultValue("jsonld") @QueryParam("format") String format) { long start = System.currentTimeMillis(); try { Optional<Commit> optCommit = catalogManager.getCommit(vf.createIRI(commitId)); if (optCommit.isPresent()) { return createCommitResponse(optCommit.get(), transformer, bNodeService); } else { return Response.status(Response.Status.NOT_FOUND).build(); } } finally { logger.trace("getCommit took {}ms", System.currentTimeMillis() - start); } }  @GET @Path("{commitId}") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves the Commit specified by the provided ID.") Response getCommit(@PathParam("commitId") String commitId,
                       @DefaultValue("jsonld") @QueryParam("format") String format); @GET @Path("{commitId}/history") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves the Commit history specified by the provided ID.") Response getCommitHistory(@Context UriInfo uriInfo,
                              @PathParam("commitId") String commitId,
                              @QueryParam("targetId") String targetId,
                              @QueryParam("entityId") String entityId,
                              @QueryParam("offset") int offset,
                              @QueryParam("limit") int limit); @GET @Path("{commitId}/resource") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves the Commit specified by the provided ID.") Response getCompiledResource(@PathParam("commitId") String commitId,
                                 @QueryParam("entityId") String entityId); @GET @Path("{sourceId}/difference") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves the Difference of the two specified Commits.") Response getDifference(@PathParam("sourceId") String sourceId,
                                  @QueryParam("targetId") String targetId,
                                  @DefaultValue("jsonld") @QueryParam("format") String rdfFormat);  }
@Test public void getCommitTest() { Response response = target().path("commits/" + encode(COMMIT_IRIS[1])) .request().get(); assertEquals(response.getStatus(), 200); verify(catalogManager).getCommit(vf.createIRI(COMMIT_IRIS[1])); try { JSONObject result = JSONObject.fromObject(response.readEntity(String.class)); assertFalse(result.containsKey("commit")); assertFalse(result.containsKey("additions")); assertFalse(result.containsKey("deletions")); assertTrue(result.containsKey("@id")); assertEquals(result.getString("@id"), COMMIT_IRIS[1]); } catch (Exception e) { fail("Expected no exception, but got: " + e.getMessage()); } }
@Test public void getCommitWithNoResults() { when(catalogManager.getCommit(any())).thenReturn(Optional.empty()); Response response = target().path("commits/" + encode(COMMIT_IRIS[1])) .request().get(); assertEquals(response.getStatus(), 404); verify(catalogManager).getCommit(vf.createIRI(COMMIT_IRIS[1])); }
@Test public void getCommitWithErrorTest() { when(catalogManager.getCommit(vf.createIRI(ERROR_IRI))).thenThrow(new IllegalArgumentException()); Response response = target().path("commits/" + encode(ERROR_IRI)) .request().get(); assertEquals(response.getStatus(), 500); }
@Test public void getDifferenceWithoutTargetTest() { Response response = target().path("commits/" + encode(COMMIT_IRIS[1]) + "/difference").request().get(); assertEquals(response.getStatus(), 200); verify(catalogManager).getCommit(vf.createIRI(COMMIT_IRIS[1])); try { JSONObject result = JSONObject.fromObject(response.readEntity(String.class)); assertTrue(result.containsKey("commit")); assertTrue(result.containsKey("additions")); assertTrue(result.containsKey("deletions")); JSONObject commit = result.getJSONObject("commit"); assertTrue(commit.containsKey("@id")); assertEquals(commit.getString("@id"), COMMIT_IRIS[1]); } catch (Exception e) { fail("Expected no exception, but got: " + e.getMessage()); } }
@Test public void getDifferenceWithMissingSourceNoTarget() { when(catalogManager.getCommit(any())).thenReturn(Optional.empty()); Response response = target().path("commits/" + encode(COMMIT_IRIS[1]) + "/difference") .request().get(); assertEquals(response.getStatus(), 404); verify(catalogManager).getCommit(vf.createIRI(COMMIT_IRIS[1])); }