@Test public void testGetAnswer() throws IOException { String network = "network"; String snapshot = "snapshot"; String question = "question"; Main.getWorkMgr().initNetwork(network, null); uploadTestSnapshot(network, snapshot, _folder); Answer expectedAnswer = new Answer(); expectedAnswer.addAnswerElement(new StringAnswerElement("foo1")); String expectedAnswerString = BatfishObjectMapper.writeString(expectedAnswer); setupQuestionAndAnswer(network, snapshot, question, null, expectedAnswer); try (Response response = getAnswerTarget(network, question, snapshot).get()) { assertThat(response.getStatus(), equalTo(OK.getStatusCode())); assertThat( BatfishObjectMapper.writeString(response.readEntity(Answer.class)), equalTo(expectedAnswerString)); } }
@GET @Produces(MediaType.APPLICATION_JSON) public Response getAnswer( @Nullable @QueryParam("snapshot") String snapshot, @Nullable @QueryParam("referenceSnapshot") String referenceSnapshot) throws IOException { if (snapshot == null || snapshot.isEmpty()) { return Response.status(Status.BAD_REQUEST) .entity("Snapshot must be specified to fetch question answer") .build(); } if (!Main.getWorkMgr().checkSnapshotExists(_network, snapshot)) { return Response.status(Status.NOT_FOUND) .entity(String.format("Snapshot %s not found in network %s", snapshot, _network)) .build(); } Answer ans = Main.getWorkMgr() .getAnswer(_network, snapshot, _questionName, referenceSnapshot, _analysis); if (ans == null) { return Response.status(Status.NOT_FOUND) .entity( String.format( "Answer not found for question %s on network: %s, snapshot: %s, referenceSnapshot: %s, analysis: %s", _questionName, _network, snapshot, referenceSnapshot, _analysis)) .build(); } return Response.ok().entity(ans).build(); }
AnswerResource { @GET @Produces(MediaType.APPLICATION_JSON) public Response getAnswer( @Nullable @QueryParam("snapshot") String snapshot, @Nullable @QueryParam("referenceSnapshot") String referenceSnapshot) throws IOException { if (snapshot == null || snapshot.isEmpty()) { return Response.status(Status.BAD_REQUEST) .entity("Snapshot must be specified to fetch question answer") .build(); } if (!Main.getWorkMgr().checkSnapshotExists(_network, snapshot)) { return Response.status(Status.NOT_FOUND) .entity(String.format("Snapshot %s not found in network %s", snapshot, _network)) .build(); } Answer ans = Main.getWorkMgr() .getAnswer(_network, snapshot, _questionName, referenceSnapshot, _analysis); if (ans == null) { return Response.status(Status.NOT_FOUND) .entity( String.format( "Answer not found for question %s on network: %s, snapshot: %s, referenceSnapshot: %s, analysis: %s", _questionName, _network, snapshot, referenceSnapshot, _analysis)) .build(); } return Response.ok().entity(ans).build(); } }
AnswerResource { @GET @Produces(MediaType.APPLICATION_JSON) public Response getAnswer( @Nullable @QueryParam("snapshot") String snapshot, @Nullable @QueryParam("referenceSnapshot") String referenceSnapshot) throws IOException { if (snapshot == null || snapshot.isEmpty()) { return Response.status(Status.BAD_REQUEST) .entity("Snapshot must be specified to fetch question answer") .build(); } if (!Main.getWorkMgr().checkSnapshotExists(_network, snapshot)) { return Response.status(Status.NOT_FOUND) .entity(String.format("Snapshot %s not found in network %s", snapshot, _network)) .build(); } Answer ans = Main.getWorkMgr() .getAnswer(_network, snapshot, _questionName, referenceSnapshot, _analysis); if (ans == null) { return Response.status(Status.NOT_FOUND) .entity( String.format( "Answer not found for question %s on network: %s, snapshot: %s, referenceSnapshot: %s, analysis: %s", _questionName, _network, snapshot, referenceSnapshot, _analysis)) .build(); } return Response.ok().entity(ans).build(); } AnswerResource(String network, @Nullable String analysis, String questionName); }
AnswerResource { @GET @Produces(MediaType.APPLICATION_JSON) public Response getAnswer( @Nullable @QueryParam("snapshot") String snapshot, @Nullable @QueryParam("referenceSnapshot") String referenceSnapshot) throws IOException { if (snapshot == null || snapshot.isEmpty()) { return Response.status(Status.BAD_REQUEST) .entity("Snapshot must be specified to fetch question answer") .build(); } if (!Main.getWorkMgr().checkSnapshotExists(_network, snapshot)) { return Response.status(Status.NOT_FOUND) .entity(String.format("Snapshot %s not found in network %s", snapshot, _network)) .build(); } Answer ans = Main.getWorkMgr() .getAnswer(_network, snapshot, _questionName, referenceSnapshot, _analysis); if (ans == null) { return Response.status(Status.NOT_FOUND) .entity( String.format( "Answer not found for question %s on network: %s, snapshot: %s, referenceSnapshot: %s, analysis: %s", _questionName, _network, snapshot, referenceSnapshot, _analysis)) .build(); } return Response.ok().entity(ans).build(); } AnswerResource(String network, @Nullable String analysis, String questionName); @POST @Path(RSC_FILTER) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response filterAnswer(FilterAnswerBean filterAnswerBean); @GET @Produces(MediaType.APPLICATION_JSON) Response getAnswer(
      @Nullable @QueryParam("snapshot") String snapshot,
      @Nullable @QueryParam("referenceSnapshot") String referenceSnapshot); }
AnswerResource { @GET @Produces(MediaType.APPLICATION_JSON) public Response getAnswer( @Nullable @QueryParam("snapshot") String snapshot, @Nullable @QueryParam("referenceSnapshot") String referenceSnapshot) throws IOException { if (snapshot == null || snapshot.isEmpty()) { return Response.status(Status.BAD_REQUEST) .entity("Snapshot must be specified to fetch question answer") .build(); } if (!Main.getWorkMgr().checkSnapshotExists(_network, snapshot)) { return Response.status(Status.NOT_FOUND) .entity(String.format("Snapshot %s not found in network %s", snapshot, _network)) .build(); } Answer ans = Main.getWorkMgr() .getAnswer(_network, snapshot, _questionName, referenceSnapshot, _analysis); if (ans == null) { return Response.status(Status.NOT_FOUND) .entity( String.format( "Answer not found for question %s on network: %s, snapshot: %s, referenceSnapshot: %s, analysis: %s", _questionName, _network, snapshot, referenceSnapshot, _analysis)) .build(); } return Response.ok().entity(ans).build(); } AnswerResource(String network, @Nullable String analysis, String questionName); @POST @Path(RSC_FILTER) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response filterAnswer(FilterAnswerBean filterAnswerBean); @GET @Produces(MediaType.APPLICATION_JSON) Response getAnswer(
      @Nullable @QueryParam("snapshot") String snapshot,
      @Nullable @QueryParam("referenceSnapshot") String referenceSnapshot);  }