summaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/crud/event/response/GraphEventResponseHandlerTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/onap/crud/event/response/GraphEventResponseHandlerTest.java')
-rw-r--r--src/test/java/org/onap/crud/event/response/GraphEventResponseHandlerTest.java166
1 files changed, 84 insertions, 82 deletions
diff --git a/src/test/java/org/onap/crud/event/response/GraphEventResponseHandlerTest.java b/src/test/java/org/onap/crud/event/response/GraphEventResponseHandlerTest.java
index 5f9194f..6fc390e 100644
--- a/src/test/java/org/onap/crud/event/response/GraphEventResponseHandlerTest.java
+++ b/src/test/java/org/onap/crud/event/response/GraphEventResponseHandlerTest.java
@@ -19,11 +19,16 @@
* ============LICENSE_END=========================================================
*/
package org.onap.crud.event.response;
-import static org.assertj.core.api.Assertions.assertThat;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonParser;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.crud.OXMModelLoaderSetup;
import org.onap.crud.event.GraphEvent;
import org.onap.crud.event.GraphEvent.GraphEventOperation;
import org.onap.crud.event.envelope.GraphEventEnvelope;
@@ -31,82 +36,79 @@ import org.onap.crud.exception.CrudException;
import org.onap.crud.util.TestUtil;
import org.onap.schema.EdgeRulesLoader;
import org.onap.schema.OxmModelLoader;
-import com.google.gson.Gson;
-import com.google.gson.JsonParser;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.crud.OXMModelLoaderSetup;
+import static org.assertj.core.api.Assertions.assertThat;
@RunWith(MockitoJUnitRunner.Silent.class)
public class GraphEventResponseHandlerTest extends OXMModelLoaderSetup {
private static boolean setUpIsNotDone = true;
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
+ @Before
+ public void setUpOnce() throws CrudException {
+ if (setUpIsNotDone) {
+ System.setProperty("CONFIG_HOME", "src/test/resources");
+ System.setProperty("AJSC_HOME", ".");
+ System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
- @Before
- public void setUpOnce() throws Exception {
- if (setUpIsNotDone) {
- System.setProperty("CONFIG_HOME", "src/test/resources");
- System.setProperty("AJSC_HOME", ".");
- System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
+ OxmModelLoader.loadModels();
+ EdgeRulesLoader.loadModels();
- OxmModelLoader.loadModels();
- EdgeRulesLoader.loadModels();
- setUpIsNotDone = false;
+ setUpIsNotDone = false;
+ }
}
- }
- @Test
- public void testPolicyViolationsNotDetected() throws Exception {
- String expectedEnvelope = TestUtil.getFileAsString("event/event-envelope-sentinel-no-violations.json");
- Gson gson = new Gson();
- GraphEventEnvelope envelope = gson.fromJson(expectedEnvelope, GraphEventEnvelope.class);
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
- GraphEventResponseHandler graphEventResponseHandler = new GraphEventResponseHandler();
- assertThat(graphEventResponseHandler.hasPolicyViolations(envelope)).isFalse();
- }
+ @Test
+ public void testPolicyViolationsNotDetected() throws Exception {
+ String expectedEnvelope = TestUtil.getFileAsString("event/event-envelope-sentinel-no-violations.json");
+ Gson gson = new Gson();
+ GraphEventEnvelope envelope = gson.fromJson(expectedEnvelope, GraphEventEnvelope.class);
- @Test
- public void testPolicyViolationsDetected() throws Exception {
- String expectedEnvelope = TestUtil.getFileAsString("event/event-envelope-sentinel.json");
- Gson gson = new Gson();
- GraphEventEnvelope envelope = gson.fromJson(expectedEnvelope, GraphEventEnvelope.class);
+ GraphEventResponseHandler graphEventResponseHandler = new GraphEventResponseHandler();
+ assertThat(graphEventResponseHandler.hasPolicyViolations(envelope)).isFalse();
+ }
- GraphEventResponseHandler graphEventResponseHandler = new GraphEventResponseHandler();
- assertThat(graphEventResponseHandler.hasPolicyViolations(envelope)).isTrue();
- }
+ @Test
+ public void testPolicyViolationsDetected() throws Exception {
+ String expectedEnvelope = TestUtil.getFileAsString("event/event-envelope-sentinel.json");
+ Gson gson = new Gson();
+ GraphEventEnvelope envelope = gson.fromJson(expectedEnvelope, GraphEventEnvelope.class);
- @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();
+ assertThat(graphEventResponseHandler.hasPolicyViolations(envelope)).isTrue();
+ }
- GraphEventResponseHandler graphEventResponseHandler = new GraphEventResponseHandler();
- String response = graphEventResponseHandler.handleVertexResponse("v13", event, result);
+ @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);
- assertThat(new JsonParser().parse(response).getAsJsonObject().get("url").getAsString())
+ 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");
+ @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);
+ 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);
- }
+ GraphEventResponseHandler graphEventResponseHandler = new GraphEventResponseHandler();
+ graphEventResponseHandler.handleVertexResponse("v13", event, result);
+ }
@Test(expected = CrudException.class)
public void testHandleVertexResponseWithViolations() throws Exception {
@@ -121,33 +123,33 @@ public class GraphEventResponseHandlerTest extends OXMModelLoaderSetup {
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);
+ @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);
+ 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");
- }
+ 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 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));
- }
+ @Test
+ public void testHandleBulkEventResponse() throws Exception {
+ GraphEventResponseHandler graphEventResponseHandler = new GraphEventResponseHandler();
+ GraphEvent event = GraphEvent.builder(GraphEventOperation.CREATE).build();
+ graphEventResponseHandler.handleBulkEventResponse(event, new GraphEventEnvelope(event));
+ }
}