+ assertThat(graphEventResponseHandler.hasPolicyViolations(envelope)).isTrue();
+ }
+
+ @Test
+ public void testHandleVertexResponse() throws Exception {
+ String graphEvent = TestUtil.getFileAsString("event/graph-vertex-event.json");
+ String champResult = TestUtil.getFileAsString("event/champ-vertex-event.json");
+ Gson gson = new Gson();
+ GraphEvent event = gson.fromJson(graphEvent, GraphEvent.class);
+ GraphEventEnvelope result = gson.fromJson(champResult, GraphEventEnvelope.class);
+
+ GraphEventResponseHandler graphEventResponseHandler = new GraphEventResponseHandler();
+ String response = graphEventResponseHandler.handleVertexResponse("v13", event, result);
+
+ assertThat(new JsonParser().parse(response).getAsJsonObject().get("url").getAsString())
+ .isEqualTo("services/inventory/v13/pserver/890c8b3f-892f-48e3-85cd-748ebf0426a5");
+ }
+
+ @Test
+ public void testHandleVertexResponseWithError() throws Exception {
+ expectedException.expect(CrudException.class);
+ expectedException.expectMessage("test error");
+
+ String graphEvent = TestUtil.getFileAsString("event/graph-vertex-event.json");
+ String champResult = TestUtil.getFileAsString("event/champ-vertex-event-error.json");
+ Gson gson = new Gson();
+ GraphEvent event = gson.fromJson(graphEvent, GraphEvent.class);
+ GraphEventEnvelope result = gson.fromJson(champResult, GraphEventEnvelope.class);
+
+ GraphEventResponseHandler graphEventResponseHandler = new GraphEventResponseHandler();
+ graphEventResponseHandler.handleVertexResponse("v13", event, result);
+ }
+
+ @Test(expected = CrudException.class)
+ public void testHandleVertexResponseWithViolations() throws Exception {
+
+ String graphEvent = TestUtil.getFileAsString("event/graph-vertex-event.json");
+ String champResult = TestUtil.getFileAsString("event/champ-vertex-event-violations.json");
+ Gson gson = new Gson();
+ GraphEvent event = gson.fromJson(graphEvent, GraphEvent.class);
+ GraphEventEnvelope result = gson.fromJson(champResult, GraphEventEnvelope.class);
+
+ GraphEventResponseHandler graphEventResponseHandler = new GraphEventResponseHandler();
+ graphEventResponseHandler.handleVertexResponse("v13", event, result);
+ }
+
+ @Test
+ public void testHandleEdgeResponse() throws Exception {
+ String graphEvent = TestUtil.getFileAsString("event/graph-edge-event.json");
+ String champResult = TestUtil.getFileAsString("event/champ-edge-event.json");
+ Gson gson = new Gson();
+ GraphEvent event = gson.fromJson(graphEvent, GraphEvent.class);
+ GraphEventEnvelope result = gson.fromJson(champResult, GraphEventEnvelope.class);
+
+ GraphEventResponseHandler graphEventResponseHandler = new GraphEventResponseHandler();
+ String response = graphEventResponseHandler.handleEdgeResponse("v10", event, result);
+
+ String id = new JsonParser().parse(response).getAsJsonObject().get("id").getAsString();
+ assertThat(id).isEqualTo("test-key");
+ }
+
+ @Test
+ public void testHandleDeletionResponse() throws Exception {
+ GraphEventResponseHandler graphEventResponseHandler = new GraphEventResponseHandler();
+ GraphEvent event = GraphEvent.builder(GraphEventOperation.DELETE).build();
+ String response = graphEventResponseHandler.handleDeletionResponse(event, new GraphEventEnvelope(event));
+ assertThat(response).isEqualTo("");
+ }
+
+ @Test
+ public void testHandleBulkEventResponse() throws Exception {
+ GraphEventResponseHandler graphEventResponseHandler = new GraphEventResponseHandler();
+ GraphEvent event = GraphEvent.builder(GraphEventOperation.CREATE).build();
+ graphEventResponseHandler.handleBulkEventResponse(event, new GraphEventEnvelope(event));