CommitRest { @GET @Path("{sourceId}/difference") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves the Difference of the two specified Commits.") public Response getDifference(@PathParam("sourceId") String sourceId, @QueryParam("targetId") String targetId, @DefaultValue("jsonld") @QueryParam("format") String rdfFormat) { long start = System.currentTimeMillis(); try { checkStringParam(sourceId, "Source commit is required"); if (StringUtils.isBlank(targetId)) { Optional<Commit> optCommit = catalogManager.getCommit(vf.createIRI(sourceId)); if (optCommit.isPresent()) { return createCommitResponse(optCommit.get(), catalogManager.getCommitDifference(optCommit.get().getResource()), rdfFormat, transformer, bNodeService); } else { return Response.status(Response.Status.NOT_FOUND).build(); } } else { Difference diff = catalogManager.getDifference(vf.createIRI(sourceId), vf.createIRI(targetId)); return Response.ok(getDifferenceJsonString(diff, rdfFormat, transformer, bNodeService), MediaType.APPLICATION_JSON).build(); } } catch (IllegalArgumentException ex) { throw ErrorUtils.sendError(ex, ex.getMessage(), Response.Status.BAD_REQUEST); } catch (IllegalStateException | MobiException ex) { throw ErrorUtils.sendError(ex, ex.getMessage(), Response.Status.INTERNAL_SERVER_ERROR); } finally { logger.trace("getDifference 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 getDifferenceTest() { Response response = target().path("commits/" + encode(COMMIT_IRIS[1]) + "/difference") .queryParam("targetId", encode(COMMIT_IRIS[0])).request().get(); assertEquals(response.getStatus(), 200); verify(catalogManager).getDifference(vf.createIRI(COMMIT_IRIS[1]), vf.createIRI(COMMIT_IRIS[0])); try { JSONObject result = JSONObject.fromObject(response.readEntity(String.class)); assertTrue(result.containsKey("additions")); assertTrue(result.containsKey("deletions")); } catch (Exception e) { fail("Expected no exception, but got: " + e.getMessage()); } }
@Test public void getDifferenceWithErrorTest() { doThrow(new IllegalArgumentException()).when(catalogManager).getDifference(vf.createIRI(ERROR_IRI), vf.createIRI(COMMIT_IRIS[0])); Response response = target().path("commits/" + encode(ERROR_IRI) + "/difference") .queryParam("targetId", encode(COMMIT_IRIS[0])).request().get(); assertEquals(response.getStatus(), 400); doThrow(new MobiException()).when(catalogManager).getDifference(vf.createIRI(COMMIT_IRIS[1]), vf.createIRI(COMMIT_IRIS[0])); response = target().path("commits/" + encode(COMMIT_IRIS[1]) + "/difference") .queryParam("targetId", encode(COMMIT_IRIS[0])).request().get(); assertEquals(response.getStatus(), 500); doThrow(new IllegalStateException()).when(catalogManager).getDifference(vf.createIRI(COMMIT_IRIS[1]), vf.createIRI(COMMIT_IRIS[0])); response = target().path("commits/" + encode(COMMIT_IRIS[1]) + "/difference") .queryParam("targetId", encode(COMMIT_IRIS[0])).request().get(); assertEquals(response.getStatus(), 500); }