aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/crud/service
diff options
context:
space:
mode:
authorsblimkie <steven.blimkie@amdocs.com>2018-03-15 13:53:15 -0400
committersblimkie <steven.blimkie@amdocs.com>2018-03-15 13:53:15 -0400
commitd41ef90610aadb5aa3372d5922155e4fc4e0a407 (patch)
tree14e2a48d3d8aa4b1bce5c49c052fcd9e93e69227 /src/test/java/org/onap/crud/service
parentb6ec637f5ee03c573855431e65fcb6ab0f321851 (diff)
Add junit tests
Add junit tests Change-Id: Iaa22b0faa206114ef39648d451a5275205d14d9a Issue-ID: AAI-885 Signed-off-by: sblimkie <steven.blimkie@amdocs.com>
Diffstat (limited to 'src/test/java/org/onap/crud/service')
-rw-r--r--src/test/java/org/onap/crud/service/AaiResourceServiceTest.java216
-rw-r--r--src/test/java/org/onap/crud/service/BulkPayloadTest.java73
-rw-r--r--src/test/java/org/onap/crud/service/CrudRestServiceTest.java241
-rw-r--r--src/test/java/org/onap/crud/service/TestDao.java194
-rw-r--r--src/test/java/org/onap/crud/service/TestHeaders.java91
-rw-r--r--src/test/java/org/onap/crud/service/TestRequest.java459
-rw-r--r--src/test/java/org/onap/crud/service/TestUriInfo.java148
7 files changed, 1422 insertions, 0 deletions
diff --git a/src/test/java/org/onap/crud/service/AaiResourceServiceTest.java b/src/test/java/org/onap/crud/service/AaiResourceServiceTest.java
new file mode 100644
index 0000000..5eb8a68
--- /dev/null
+++ b/src/test/java/org/onap/crud/service/AaiResourceServiceTest.java
@@ -0,0 +1,216 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.crud.service;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.aai.exceptions.AAIException;
+import org.onap.aai.serialization.db.EdgeProperty;
+import org.onap.aai.serialization.db.EdgeRule;
+import org.onap.aai.serialization.db.EdgeRules;
+import org.onap.aai.serialization.db.EdgeType;
+import org.onap.crud.exception.CrudException;
+import org.onap.crud.service.EdgePayload;
+
+import com.google.gson.JsonElement;
+
+public class AaiResourceServiceTest {
+
+ public AaiResourceService aaiResSvc = null;
+
+
+ @Before
+ public void setup() {
+ System.setProperty("AJSC_HOME", ".");
+ System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
+
+ aaiResSvc = new AaiResourceService();
+ }
+
+
+ /**
+ * This test validates that we can apply db edge rules against an edge request
+ * payload and have the properties defined in the edge rules merged into the
+ * payload.
+ *
+ * @throws CrudException
+ * @throws AAIException
+ */
+ @Test
+ public void applyEdgeRulesToPayloadTest() throws CrudException, AAIException {
+
+ String content = "{" +
+ "\"source\": \"services/inventory/v8/l-interface/369553424\", " +
+ "\"target\": \"services/inventory/v8/logical-link/573444128\"," +
+ "\"properties\": {" +
+ "}" +
+ "}";
+
+ // Convert our simulated payload to an EdgePayload object.
+ EdgePayload payload = EdgePayload.fromJson(content);
+
+ // Now, apply the db edge rules against our edge payload.
+ EdgePayload payloadAfterEdgeRules = aaiResSvc.applyEdgeRulesToPayload(payload);
+
+ EdgeRules rules = EdgeRules.getInstance();
+ EdgeRule rule = rules.getEdgeRule(EdgeType.COUSIN, "l-interface", "logical-link");
+ Map<EdgeProperty, String> edgeProps = rule.getEdgeProperties();
+
+ // Validate that the properties defined in the DB edge rules show up in our
+ // final payload.
+ for(EdgeProperty key : edgeProps.keySet()) {
+ assertTrue(payloadAfterEdgeRules.toString().contains(key.toString()));
+ }
+ }
+
+
+ /**
+ * This test validates that trying to apply edge rules where there is no
+ * db edge rules entry for the supplied source and target vertex types
+ * produces an exception.
+ *
+ * @throws CrudException
+ */
+ @Test
+ public void noRuleForEdgeTest() throws CrudException {
+
+ String content = "{" +
+ "\"source\": \"services/inventory/v8/commodore-64/12345\", " +
+ "\"target\": \"services/inventory/v8/jumpman/67890\"," +
+ "\"properties\": {" +
+ "}" +
+ "}";
+
+ // Convert our simulated payload to an EdgePayload object.
+ EdgePayload payload = EdgePayload.fromJson(content);
+
+ // Now, apply the db edge rules against our edge payload.
+ try {
+ aaiResSvc.applyEdgeRulesToPayload(payload);
+
+ } catch (CrudException e) {
+
+ // We expected an exception since there is no rule for our made up vertices..
+ assertTrue(e.getMessage().contains("No edge rules for"));
+ return;
+ }
+
+ // If we're here then something unexpected happened...
+ fail();
+ }
+
+
+ /**
+ * This test validates that it is possible to merge client supplied and edge rule
+ * supplied properties into one edge property list.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void mergeEdgePropertiesTest() throws Exception {
+
+ String content = "{" +
+ "\"source\": \"services/inventory/v8/l-interface/369553424\", " +
+ "\"target\": \"services/inventory/v8/logical-link/573444128\"," +
+ "\"properties\": {" +
+ "\"multiplicity\": \"many\"," +
+ "\"is-parent\": true," +
+ "\"uses-resource\": \"true\"," +
+ "\"has-del-target\": \"true\"" +
+ "}" +
+ "}";
+
+ EdgePayload payload = EdgePayload.fromJson(content);
+ EdgeRules rules = EdgeRules.getInstance();
+ EdgeRule rule = rules.getEdgeRule(EdgeType.COUSIN, "l-interface", "logical-link");
+ Map<EdgeProperty, String> edgeProps = rule.getEdgeProperties();
+
+ // Merge the client supplied properties with the properties defined in the DB edge rules.
+ JsonElement mergedProperties =
+ aaiResSvc.mergeProperties(payload.getProperties(), rule.getEdgeProperties());
+
+ // Now, validate that the resulting set of properties contains both the client and edge
+ // rule supplied properties.
+ String mergedPropertiesString = mergedProperties.toString();
+ assertTrue("Client supplied property 'multiplicity' is missing from merged properties set",
+ mergedPropertiesString.contains("multiplicity"));
+ assertTrue("Client supplied property 'is-parent' is missing from merged properties set",
+ mergedPropertiesString.contains("is-parent"));
+ assertTrue("Client supplied property 'uses-resource' is missing from merged properties set",
+ mergedPropertiesString.contains("uses-resource"));
+ assertTrue("Client supplied property 'has-del-target' is missing from merged properties set",
+ mergedPropertiesString.contains("has-del-target"));
+
+ for(EdgeProperty key : edgeProps.keySet()) {
+ assertTrue("Edge rule supplied property '" + key.toString() + "' is missing from merged properties set",
+ mergedPropertiesString.contains(key.toString()));
+ }
+ }
+
+ /**
+ * This test validates that if we try to merge client supplied edge properties
+ * with the properties defined in the db edge rules, and there is a conflict,
+ * then the merge will fail.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void mergeEdgePropertiesConflictTest() throws Exception {
+
+ String content = "{" +
+ "\"source\": \"services/inventory/v8/l-interface/369553424\", " +
+ "\"target\": \"services/inventory/v8/logical-link/573444128\"," +
+ "\"properties\": {" +
+ "\"contains-other-v\": \"OUT\"" +
+ "}" +
+ "}";
+
+ EdgePayload payload = EdgePayload.fromJson(content);
+ EdgeRules rules = EdgeRules.getInstance();
+ EdgeRule rule = rules.getEdgeRule(EdgeType.COUSIN, "l-interface", "logical-link");
+
+ try {
+
+ // Try to merge our client supplied properties with the properties defined
+ // in the db edge rules.
+ aaiResSvc.mergeProperties(payload.getProperties(), rule.getEdgeProperties());
+
+ } catch (CrudException e) {
+
+ // We should have gotten an exception because we are trying to set a parameter which is
+ // already defined in the db edge rules, so if we're here then we are good.
+ return;
+ }
+
+ // If we made it here then we were allowed to set a property that is already defined
+ // in the db edge rules, which we should not have...
+ fail();
+ }
+
+
+
+
+}
diff --git a/src/test/java/org/onap/crud/service/BulkPayloadTest.java b/src/test/java/org/onap/crud/service/BulkPayloadTest.java
new file mode 100644
index 0000000..89c2269
--- /dev/null
+++ b/src/test/java/org/onap/crud/service/BulkPayloadTest.java
@@ -0,0 +1,73 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.crud.service;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+
+public class BulkPayloadTest {
+
+ @Test
+ public void testBulkPayload() throws Exception {
+ BulkPayload p = new BulkPayload();
+ JsonObject root = new JsonObject();
+ JsonArray vertices = new JsonArray();
+ JsonObject v1 = new JsonObject();
+ JsonObject v2 = new JsonObject();
+ JsonObject prop = new JsonObject();
+
+ prop.addProperty("p1", "value1");
+ prop.addProperty("p2", "value2");
+ v1.add("v1", prop);
+ v2.add("v2", prop);
+
+ vertices.add(v1);
+ vertices.add(v2);
+
+ root.add("objects", vertices);
+
+ String s = "{\"objects\":[{\"v1\":{\"p1\":\"value1\",\"p2\":\"value2\"}},{\"v2\":{\"p1\":\"value1\",\"p2\":\"value2\"}}]}";
+
+ p = BulkPayload.fromJson(s);
+
+ List<JsonElement> po = p.getObjects();
+ List<String> ids = new ArrayList<String>();
+ for (JsonElement e : po) {
+ Set<Map.Entry<String, JsonElement>> entries = e.getAsJsonObject().entrySet();
+
+ for (Map.Entry<String, JsonElement> entry : entries) {
+ ids.add(entry.getKey());
+ }
+ }
+
+ System.out.println("root: " + root.toString());
+ System.out.println("payload ids: " + ids.toString());
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/crud/service/CrudRestServiceTest.java b/src/test/java/org/onap/crud/service/CrudRestServiceTest.java
new file mode 100644
index 0000000..029fd52
--- /dev/null
+++ b/src/test/java/org/onap/crud/service/CrudRestServiceTest.java
@@ -0,0 +1,241 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.crud.service;
+
+import static org.junit.Assert.*;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.crud.exception.CrudException;
+import org.onap.schema.RelationshipSchemaLoader;
+
+
+
+public class CrudRestServiceTest {
+ private final String putVertexPayload = "{" +
+ "\"id\": \"test-uuid\"," +
+ "\"type\": \"pserver\"," +
+ "\"properties\": {" +
+ "\"fqdn\": \"myhost.onap.com\"," +
+ "\"hostname\": \"myhost\" } }";
+
+ private final String postVertexPayload = "{" +
+ "\"type\": \"pserver\"," +
+ "\"properties\": {" +
+ "\"fqdn\": \"myhost.onap.com\"," +
+ "\"hostname\": \"myhost\" } }";
+
+ private final String postMissingPropVertexPayload = "{" +
+ "\"type\": \"pserver\"," +
+ "\"properties\": {" +
+ "\"fqdn\": \"myhost.onap.com\"," +
+ "\"equip-type\": \"box\" } }";
+
+ private final String postEdgePayload = "{" +
+ "\"type\": \"tosca.relationships.HostedOn\"," +
+ "\"source\": \"services/inventory/v12/vserver/50bdab41-ad1c-4d00-952c-a0aa5d827811\"," +
+ "\"target\": \"services/inventory/v12/pserver/1d326bc7-b985-492b-9604-0d5d1f06f908\"," +
+ "\"properties\": {" +
+ "\"prevent-delete\": \"NONE\" } }";
+
+
+ private CrudRestService mockService;
+
+ @Before
+ public void init() throws Exception {
+ ClassLoader classLoader = getClass().getClassLoader();
+ File dir = new File(classLoader.getResource("model").getFile());
+ System.setProperty("CONFIG_HOME", dir.getParent());
+ RelationshipSchemaLoader.resetVersionContextMap();
+
+ CrudGraphDataService service = new CrudGraphDataService(new TestDao());
+ CrudRestService restService = new CrudRestService(service, null);
+ mockService = Mockito.spy(restService);
+
+ Mockito.doReturn(true).when(mockService).validateRequest(Mockito.any(HttpServletRequest.class),
+ Mockito.anyString(), Mockito.anyString(), Mockito.any(CrudRestService.Action.class), Mockito.anyString(),
+ Mockito.any(HttpHeaders.class));
+ }
+
+ @Test
+ public void testDelete() throws CrudException {
+ Response response;
+
+ response = mockService.deleteVertex("", "v11", "pserver", "872dd5df-0be9-4167-95e9-2cf4b21165ed",
+ "services/inventory/v11", new TestHeaders(), null, new TestRequest());
+ assertTrue(response.getStatus() == 200);
+
+ response = mockService.deleteEdge("", "v11", "tosca.relationships.HostedOn", "872dd5df-0be9-4167-95e9-2cf4b21165ed",
+ "services/inventory/v11", new TestHeaders(), null, new TestRequest());
+ assertTrue(response.getStatus() == 200);
+ }
+
+ @Test
+ public void testAddVertex() throws CrudException {
+ Response response;
+
+ response = mockService.addVertex(postMissingPropVertexPayload, "v11", "services/inventory/v11",
+ new TestHeaders(), null, new TestRequest());
+ System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString());
+ assertTrue(response.getStatus() == 400);
+
+ response = mockService.addVertex(postVertexPayload, "v11", "services/inventory/v11",
+ new TestHeaders(), null, new TestRequest());
+ System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString());
+ assertTrue(response.getStatus() == 201);
+
+ response = mockService.addVertex(postMissingPropVertexPayload, "v11", "pserver", "services/inventory/v11",
+ new TestHeaders(), null, new TestRequest());
+ System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString());
+ assertTrue(response.getStatus() == 400);
+
+ response = mockService.addVertex(postVertexPayload, "v11", "pserver", "services/inventory/v11",
+ new TestHeaders(), null, new TestRequest());
+ System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString());
+ assertTrue(response.getStatus() == 201);
+ }
+
+ @Test
+ public void testAddEdge() throws CrudException {
+ Response response;
+
+ response = mockService.addEdge(postEdgePayload, "v11", "services/inventory/v11",
+ new TestHeaders(), null, new TestRequest());
+ System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString());
+ assertTrue(response.getStatus() == 201);
+
+ response = mockService.addEdge(postEdgePayload, "v11", "tosca.relationships.HostedOn", "services/inventory/v11",
+ new TestHeaders(), null, new TestRequest());
+ System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString());
+ assertTrue(response.getStatus() == 201);
+ }
+
+ @Test
+ public void testUpdateVertex() throws CrudException {
+ Response response;
+
+ // Test ID mismatch
+ response = mockService.updateVertex(putVertexPayload, "v11", "pserver", "bad-id",
+ "services/inventory/v11", new TestHeaders(), null, new TestRequest());
+ System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString());
+ assertTrue(response.getStatus() == 400);
+
+ // Success case
+ response = mockService.updateVertex(putVertexPayload, "v11", "pserver", "test-uuid",
+ "services/inventory/v11", new TestHeaders(), null, new TestRequest());
+ System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString());
+ assertTrue(response.getStatus() == 200);
+
+ // Patch
+ response = mockService.patchVertex(putVertexPayload, "v11", "pserver", "test-uuid",
+ "services/inventory/v11", new TestHeaders(), null, new TestRequest());
+ System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString());
+ assertTrue(response.getStatus() == 200);
+ }
+
+ @Test
+ public void testUpdateEdge() throws CrudException {
+ Response response;
+
+ response = mockService.updateEdge(postEdgePayload, "v11", "tosca.relationships.HostedOn", "my-uuid",
+ "services/inventory/v11", new TestHeaders(), null, new TestRequest());
+ System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString());
+ assertTrue(response.getStatus() == 200);
+
+ // Patch
+ response = mockService.patchEdge(postEdgePayload, "v11", "tosca.relationships.HostedOn", "my-uuid",
+ "services/inventory/v11", new TestHeaders(), null, new TestRequest());
+ System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString());
+ assertTrue(response.getStatus() == 200);
+ }
+
+ @Test
+ public void testGet() throws CrudException {
+ Response response;
+
+ response = mockService.getVertex("", "v11", "pserver", "872dd5df-0be9-4167-95e9-2cf4b21165ed",
+ "services/inventory/v11", new TestHeaders(), new TestUriInfo(), new TestRequest());
+ System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString());
+ assertTrue(response.getStatus() == 200);
+
+ response = mockService.getEdge("", "v11", "tosca.relationships.HostedOn", "872dd5df-0be9-4167-95e9-2cf4b21165ed",
+ "services/inventory/v11", new TestHeaders(), new TestUriInfo(), new TestRequest());
+ System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString());
+ assertTrue(response.getStatus() == 200);
+
+ response = mockService.getVertices("", "v11", "pserver",
+ "services/inventory/v11", new TestHeaders(), new TestUriInfo(), new TestRequest());
+ System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString());
+ assertTrue(response.getStatus() == 200);
+
+ response = mockService.getEdges("", "v11", "tosca.relationships.HostedOn",
+ "services/inventory/v11", new TestHeaders(), new TestUriInfo(), new TestRequest());
+ System.out.println("Response: " + response.getStatus() + "\n" + response.getEntity().toString());
+ assertTrue(response.getStatus() == 200);
+ }
+
+ @Test
+ public void testBulk() throws CrudException, IOException {
+ Response response;
+
+ File bulkFile = new File("src/test/resources/payloads/bulk.json");
+ String payloadStr = readFileToString(bulkFile);
+ System.out.println(payloadStr);
+
+ response = mockService.addBulk(payloadStr, "v11", "",
+ "services/inventory/v11", new TestHeaders(), null, new TestRequest());
+ System.out.println("Bulk Response: " + response.getStatus() + "\n" + response.getEntity().toString());
+ assertTrue(response.getStatus() == 200);
+ }
+
+ public static String readFileToString(File aFile) throws IOException {
+
+ BufferedReader br = new BufferedReader(new FileReader(aFile));
+ try {
+ StringBuilder sb = new StringBuilder();
+ String line = br.readLine();
+
+ while (line != null) {
+ sb.append(line);
+ line = br.readLine();
+ }
+
+ return sb.toString().replaceAll("\\s+", "");
+ } finally {
+ try {
+ br.close();
+ } catch (IOException e) {
+ fail("Unexpected IOException: " + e.getMessage());
+ }
+ }
+ }
+
+}
diff --git a/src/test/java/org/onap/crud/service/TestDao.java b/src/test/java/org/onap/crud/service/TestDao.java
new file mode 100644
index 0000000..5af85f0
--- /dev/null
+++ b/src/test/java/org/onap/crud/service/TestDao.java
@@ -0,0 +1,194 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.crud.service;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+
+import org.onap.crud.dao.GraphDao;
+import org.onap.crud.entity.Edge;
+import org.onap.crud.entity.Vertex;
+import org.onap.crud.exception.CrudException;
+
+public class TestDao implements GraphDao {
+
+ private final String champVertex = "{" +
+ "\"key\": \"test-uuid\"," +
+ "\"type\": \"pserver\"," +
+ "\"properties\": {" +
+ "\"fqdn\": \"myhost.onap.com\"," +
+ "\"hostname\": \"myhost\" } }";
+
+ private final String champEdge = "{" +
+ "\"key\": \"test-uuid\"," +
+ "\"type\": \"tosca.relationships.HostedOn\"," +
+ "\"properties\": {" +
+ "\"prevent-delete\": \"NONE\" }," +
+ "\"source\": {" +
+ "\"key\": \"50bdab41-ad1c-4d00-952c-a0aa5d827811\", \"type\": \"vserver\"}," +
+ "\"target\": {" +
+ "\"key\": \"1d326bc7-b985-492b-9604-0d5d1f06f908\", \"type\": \"pserver\"}" +
+ " }";
+
+ @Override
+ public Vertex getVertex(String id, String version) throws CrudException {
+ return Vertex.fromJson(champVertex, "v11");
+ }
+
+ @Override
+ public Vertex getVertex(String id, String type, String version, Map<String, String> queryParams)
+ throws CrudException {
+ return Vertex.fromJson(champVertex, "v11");
+ }
+
+ @Override
+ public List<Edge> getVertexEdges(String id, Map<String, String> queryParams) throws CrudException {
+ List<Edge> list = new ArrayList<Edge>();
+ list.add(Edge.fromJson(champEdge));
+ return list;
+ }
+
+ @Override
+ public List<Vertex> getVertices(String type, Map<String, Object> filter, String version) throws CrudException {
+ List<Vertex> list = new ArrayList<Vertex>();
+ list.add(Vertex.fromJson(champVertex, "v11"));
+ return list;
+ }
+
+ @Override
+ public List<Vertex> getVertices(String type, Map<String, Object> filter, HashSet<String> properties, String version)
+ throws CrudException {
+ List<Vertex> list = new ArrayList<Vertex>();
+ list.add(Vertex.fromJson(champVertex, "v11"));
+ return list;
+ }
+
+ @Override
+ public Edge getEdge(String id, String type, Map<String, String> queryParams) throws CrudException {
+ return Edge.fromJson(champEdge);
+ }
+
+ @Override
+ public List<Edge> getEdges(String type, Map<String, Object> filter) throws CrudException {
+ List<Edge> list = new ArrayList<Edge>();
+ list.add(Edge.fromJson(champEdge));
+ return list;
+ }
+
+ @Override
+ public Vertex addVertex(String type, Map<String, Object> properties, String version) throws CrudException {
+ return Vertex.fromJson(champVertex, "v11");
+ }
+
+ @Override
+ public Vertex updateVertex(String id, String type, Map<String, Object> properties, String version)
+ throws CrudException {
+ return Vertex.fromJson(champVertex, "v11");
+ }
+
+ @Override
+ public void deleteVertex(String id, String type) throws CrudException {
+
+ }
+
+ @Override
+ public Edge addEdge(String type, Vertex source, Vertex target, Map<String, Object> properties, String version)
+ throws CrudException {
+ return Edge.fromJson(champEdge);
+ }
+
+ @Override
+ public Edge updateEdge(Edge edge) throws CrudException {
+ return Edge.fromJson(champEdge);
+ }
+
+ @Override
+ public void deleteEdge(String id, String type) throws CrudException {
+
+ }
+
+ @Override
+ public String openTransaction() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void commitTransaction(String id) throws CrudException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void rollbackTransaction(String id) throws CrudException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean transactionExists(String id) throws CrudException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public Vertex addVertex(String type, Map<String, Object> properties, String version, String txId)
+ throws CrudException {
+ return Vertex.fromJson(champVertex, "v11");
+ }
+
+ @Override
+ public Edge addEdge(String type, Vertex source, Vertex target, Map<String, Object> properties, String version,
+ String txId) throws CrudException {
+ return Edge.fromJson(champEdge);
+ }
+
+ @Override
+ public Vertex updateVertex(String id, String type, Map<String, Object> properties, String version, String txId)
+ throws CrudException {
+ return Vertex.fromJson(champVertex, "v11");
+ }
+
+ @Override
+ public Edge updateEdge(Edge edge, String txId) throws CrudException {
+ return Edge.fromJson(champEdge);
+ }
+
+ @Override
+ public void deleteVertex(String id, String type, String txId) throws CrudException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void deleteEdge(String id, String type, String txId) throws CrudException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Edge getEdge(String id, String type, String txId) throws CrudException {
+ return Edge.fromJson(champEdge);
+ }
+
+}
diff --git a/src/test/java/org/onap/crud/service/TestHeaders.java b/src/test/java/org/onap/crud/service/TestHeaders.java
new file mode 100644
index 0000000..6e30471
--- /dev/null
+++ b/src/test/java/org/onap/crud/service/TestHeaders.java
@@ -0,0 +1,91 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.crud.service;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.ws.rs.core.Cookie;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+
+public class TestHeaders implements HttpHeaders {
+
+ @Override
+ public List<Locale> getAcceptableLanguages() {
+ return null;
+ }
+
+ @Override
+ public List<MediaType> getAcceptableMediaTypes() {
+ return null;
+ }
+
+ @Override
+ public Map<String, Cookie> getCookies() {
+ return null;
+ }
+
+ @Override
+ public Date getDate() {
+ return null;
+ }
+
+ @Override
+ public String getHeaderString(String arg0) {
+ return null;
+ }
+
+ @Override
+ public Locale getLanguage() {
+ return null;
+ }
+
+ @Override
+ public int getLength() {
+ return 0;
+ }
+
+ @Override
+ public MediaType getMediaType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public List<String> getRequestHeader(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public MultivaluedMap<String, String> getRequestHeaders() {
+ MultivaluedMap<String, String> map = new MultivaluedHashMap<String, String>();
+ map.add("X-FromAppId", "test-app");
+ map.add("X-TransactionId", "65f7e29c-57fd-45b2-bfd5-19e25c59110e");
+ return map;
+ }
+
+}
diff --git a/src/test/java/org/onap/crud/service/TestRequest.java b/src/test/java/org/onap/crud/service/TestRequest.java
new file mode 100644
index 0000000..f5ee7d6
--- /dev/null
+++ b/src/test/java/org/onap/crud/service/TestRequest.java
@@ -0,0 +1,459 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.crud.service;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.security.Principal;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.servlet.AsyncContext;
+import javax.servlet.DispatcherType;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletInputStream;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpUpgradeHandler;
+import javax.servlet.http.Part;
+
+public class TestRequest implements HttpServletRequest {
+
+ @Override
+ public AsyncContext getAsyncContext() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Object getAttribute(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Enumeration<String> getAttributeNames() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getCharacterEncoding() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public int getContentLength() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public long getContentLengthLong() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public String getContentType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public DispatcherType getDispatcherType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public ServletInputStream getInputStream() throws IOException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getLocalAddr() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getLocalName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public int getLocalPort() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public Locale getLocale() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Enumeration<Locale> getLocales() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getParameter(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Map<String, String[]> getParameterMap() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Enumeration<String> getParameterNames() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String[] getParameterValues(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getProtocol() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public BufferedReader getReader() throws IOException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getRealPath(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getRemoteAddr() {
+ return "127.0.0.1";
+ }
+
+ @Override
+ public String getRemoteHost() {
+ return "127.0.0.1";
+ }
+
+ @Override
+ public int getRemotePort() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public RequestDispatcher getRequestDispatcher(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getScheme() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getServerName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public int getServerPort() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public ServletContext getServletContext() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean isAsyncStarted() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isAsyncSupported() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isSecure() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void removeAttribute(String arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setAttribute(String arg0, Object arg1) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setCharacterEncoding(String arg0) throws UnsupportedEncodingException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public AsyncContext startAsync() throws IllegalStateException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public AsyncContext startAsync(ServletRequest arg0, ServletResponse arg1) throws IllegalStateException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean authenticate(HttpServletResponse arg0) throws IOException, ServletException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public String changeSessionId() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getAuthType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getContextPath() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Cookie[] getCookies() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public long getDateHeader(String arg0) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public String getHeader(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Enumeration<String> getHeaderNames() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Enumeration<String> getHeaders(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public int getIntHeader(String arg0) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public String getMethod() {
+ return "OP";
+ }
+
+ @Override
+ public Part getPart(String arg0) throws IOException, ServletException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Collection<Part> getParts() throws IOException, ServletException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getPathInfo() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getPathTranslated() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getQueryString() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getRemoteUser() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getRequestURI() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public StringBuffer getRequestURL() {
+ return new StringBuffer();
+ }
+
+ @Override
+ public String getRequestedSessionId() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getServletPath() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public HttpSession getSession() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public HttpSession getSession(boolean arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Principal getUserPrincipal() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean isRequestedSessionIdFromCookie() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isRequestedSessionIdFromURL() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isRequestedSessionIdFromUrl() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isRequestedSessionIdValid() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isUserInRole(String arg0) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void login(String arg0, String arg1) throws ServletException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void logout() throws ServletException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public <T extends HttpUpgradeHandler> T upgrade(Class<T> arg0) throws IOException, ServletException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/test/java/org/onap/crud/service/TestUriInfo.java b/src/test/java/org/onap/crud/service/TestUriInfo.java
new file mode 100644
index 0000000..980f0da
--- /dev/null
+++ b/src/test/java/org/onap/crud/service/TestUriInfo.java
@@ -0,0 +1,148 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.crud.service;
+
+import java.net.URI;
+import java.util.List;
+
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.PathSegment;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
+
+public class TestUriInfo implements UriInfo {
+
+ @Override
+ public URI getAbsolutePath() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public UriBuilder getAbsolutePathBuilder() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public URI getBaseUri() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public UriBuilder getBaseUriBuilder() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public List<Object> getMatchedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public List<String> getMatchedURIs() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public List<String> getMatchedURIs(boolean arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getPath() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getPath(boolean arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public MultivaluedMap<String, String> getPathParameters() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public MultivaluedMap<String, String> getPathParameters(boolean arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public List<PathSegment> getPathSegments() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public List<PathSegment> getPathSegments(boolean arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public MultivaluedMap<String, String> getQueryParameters() {
+ MultivaluedMap<String, String> map = new MultivaluedHashMap<String, String>();
+ map.add("hostname", "myhost");
+ return map;
+ }
+
+ @Override
+ public MultivaluedMap<String, String> getQueryParameters(boolean arg0) {
+ return null;
+ }
+
+ @Override
+ public URI getRequestUri() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public UriBuilder getRequestUriBuilder() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public URI relativize(URI arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public URI resolve(URI arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}