summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorsblimkie <steven.blimkie@amdocs.com>2018-07-19 16:03:44 -0400
committersblimkie <steven.blimkie@amdocs.com>2018-07-19 16:08:20 -0400
commit3bc6a702f2d3d8710c7aaa94cdc8c0ccf3deb759 (patch)
tree9703ebe15777acc73ad118520f6b1a219f60e107 /src/test
parent194adee686ebb90488f739f2c637f6cb3def94d5 (diff)
Auto-resolve edge type
Auto-resolve edge type based on EdgeRules file. Change-Id: Ic6de47f5172bc410efcdd5f08c1ea5c4f822610e Issue-ID: AAI-1396 Signed-off-by: sblimkie <steven.blimkie@amdocs.com>
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/onap/crud/service/ChampDaoExceptionsTest.java10
-rw-r--r--src/test/java/org/onap/crud/service/ChampDaoMockTest.java25
-rw-r--r--src/test/java/org/onap/crud/service/CrudRestServiceTest.java3
-rw-r--r--src/test/java/org/onap/crud/service/TestDao.java14
-rw-r--r--src/test/java/org/onap/schema/EdgeRulesLoaderTest.java62
-rw-r--r--src/test/resources/rules/DbEdgeRules_test_two_v11.json12
6 files changed, 108 insertions, 18 deletions
diff --git a/src/test/java/org/onap/crud/service/ChampDaoExceptionsTest.java b/src/test/java/org/onap/crud/service/ChampDaoExceptionsTest.java
index 1f0a20b..a7479b5 100644
--- a/src/test/java/org/onap/crud/service/ChampDaoExceptionsTest.java
+++ b/src/test/java/org/onap/crud/service/ChampDaoExceptionsTest.java
@@ -229,7 +229,7 @@ public class ChampDaoExceptionsTest {
buildChampDao();
try {
- champDao.getEdge(idNotExists, type, txId);
+ champDao.getEdge(idNotExists, txId);
} catch (CrudException e) {
assertEquals(404, e.getHttpStatus().getStatusCode());
assertThat(e.getMessage(), containsString(failureCauseForGetEdge));
@@ -250,7 +250,7 @@ public class ChampDaoExceptionsTest {
// Type not matches
try {
- champDao.getEdge(id, "", txId);
+ champDao.getEdge(id, txId);
} catch (CrudException e) {
assertEquals(404, e.getHttpStatus().getStatusCode());
assertThat(e.getMessage(), containsString(failureCauseForGetEdgeTypeNotMatches));
@@ -332,7 +332,7 @@ public class ChampDaoExceptionsTest {
buildChampDao();
try {
- champDao.getVertexEdges(idNotExists, queryParams);
+ champDao.getVertexEdges(idNotExists, queryParams, null);
} catch (CrudException e) {
assertEquals(404, e.getHttpStatus().getStatusCode());
assertThat(e.getMessage(), containsString(failureCauseForGetVertexEdges));
@@ -509,13 +509,13 @@ public class ChampDaoExceptionsTest {
buildChampDao();
try {
- champDao.deleteEdge(id, type);
+ champDao.deleteEdge(id);
} catch (CrudException e) {
assertEquals(400, e.getHttpStatus().getStatusCode());
assertThat(e.getMessage(), containsString(failureCauseFordeleteEdge));
}
try {
- champDao.deleteEdge(id, type, txId);
+ champDao.deleteEdge(id, txId);
} catch (CrudException e) {
assertEquals(400, e.getHttpStatus().getStatusCode());
assertThat(e.getMessage(), containsString(failureCauseFordeleteEdge));
diff --git a/src/test/java/org/onap/crud/service/ChampDaoMockTest.java b/src/test/java/org/onap/crud/service/ChampDaoMockTest.java
index 75d5bfd..dadf81a 100644
--- a/src/test/java/org/onap/crud/service/ChampDaoMockTest.java
+++ b/src/test/java/org/onap/crud/service/ChampDaoMockTest.java
@@ -269,11 +269,13 @@ public class ChampDaoMockTest {
mockGetVertex("50bdab41-ad1c-4d00-952c-a0aa5d827811", "?transactionId=", "vserver");
mockGetVertices(queryParamsVertices, "pserver");
mockGetVertices(queryParamsVerticesV13, "pserver");
- mockGetVertexEdges("872dd5df-0be9-4167-95e9-2cf4b21165ed", queryParamsVertex, "tosca.relationships.HostedOn");
- mockGetVertexEdges("872dd5df-0be9-4167-95e9-2cf4b21165ed", queryParamsVertexV13,
+ mockGetVertexEdges("872dd5df-0be9-4167-95e9-2cf4b21165ed", queryParamsVertex, null, "tosca.relationships.HostedOn");
+ mockGetVertexEdges("872dd5df-0be9-4167-95e9-2cf4b21165ed", queryParamsVertexV13, null,
"tosca.relationships.HostedOn");
- mockGetVertexEdges("50bdab41-ad1c-4d00-952c-a0aa5d827811", emptyQueryParams, "tosca.relationships.HostedOn");
- mockGetVertexEdges("1d326bc7-b985-492b-9604-0d5d1f06f908", emptyQueryParams, "tosca.relationships.HostedOn");
+ mockGetVertexEdges("50bdab41-ad1c-4d00-952c-a0aa5d827811", emptyQueryParams, null, "tosca.relationships.HostedOn");
+ mockGetVertexEdges("1d326bc7-b985-492b-9604-0d5d1f06f908", emptyQueryParams, null, "tosca.relationships.HostedOn");
+ mockGetVertexEdges("50bdab41-ad1c-4d00-952c-a0aa5d827811", emptyQueryParams, "?transactionId=", "tosca.relationships.HostedOn");
+ mockGetVertexEdges("1d326bc7-b985-492b-9604-0d5d1f06f908", emptyQueryParams, "?transactionId=", "tosca.relationships.HostedOn");
mockGetEdges("?", "tosca.relationships.HostedOn");
mockGetEdge("50bdab41-ad1c-4d00-952c-a0aa5d827811", "?transactionId=", "tosca.relationships.HostedOn");
mockGetEdge("872dd5df-0be9-4167-95e9-2cf4b21165ed", emptyQueryParams, "tosca.relationships.HostedOn");
@@ -372,17 +374,24 @@ public class ChampDaoMockTest {
.thenReturn(operationResult);
}
- public void mockGetVertexEdges(String id, Map<String, String> queryParams, String type) {
+ public void mockGetVertexEdges(String id, Map<String, String> queryParams, String txId, String type) {
String edgeResponse = champEdge.replace("edgeType", type);
OperationResult operationResult = new OperationResult();
List<String> edgeResponselist = new ArrayList<>();
edgeResponselist.add(edgeResponse);
operationResult.setResult(edgeResponselist.toString());
operationResult.setResultCode(200);
+ String baseUrl = BASE_OBJECT_URL + "/" + RELATIONSHIP_SUB_URL + "/" + id;
+ String url;
+
+ if (txId != null) {
+ url = baseUrl + txId;
+ }
+ else {
+ url = appendQueryParams(baseUrl, queryParams).toString();
+ }
- StringBuilder url = appendQueryParams(BASE_OBJECT_URL + "/" + RELATIONSHIP_SUB_URL + "/" + id, queryParams);
-
- when(restClientMock.get(url.toString(), createHeaders(), MediaType.APPLICATION_JSON_TYPE))
+ when(restClientMock.get(url, createHeaders(), MediaType.APPLICATION_JSON_TYPE))
.thenReturn(operationResult);
}
diff --git a/src/test/java/org/onap/crud/service/CrudRestServiceTest.java b/src/test/java/org/onap/crud/service/CrudRestServiceTest.java
index d8be704..1098284 100644
--- a/src/test/java/org/onap/crud/service/CrudRestServiceTest.java
+++ b/src/test/java/org/onap/crud/service/CrudRestServiceTest.java
@@ -335,7 +335,8 @@ public class CrudRestServiceTest {
response = mockService.addBulk(payloadStr, "v9", "",
"services/inventory/v9", new TestHeaders(), null, new TestRequest());
- System.out.println("Bulk Response: " + response.getStatus() + "\n" + response.getEntity().toString());
+ System.out.println("Bulk Response: " + response);
+ System.out.println("Response Entity: " + response.getEntity().toString());
assertTrue(response.getStatus() == 200);
}
diff --git a/src/test/java/org/onap/crud/service/TestDao.java b/src/test/java/org/onap/crud/service/TestDao.java
index 20cd04a..4f1d34e 100644
--- a/src/test/java/org/onap/crud/service/TestDao.java
+++ b/src/test/java/org/onap/crud/service/TestDao.java
@@ -84,7 +84,7 @@ public class TestDao implements GraphDao {
}
@Override
- public List<Edge> getVertexEdges(String id, Map<String, String> queryParams) throws CrudException {
+ public List<Edge> getVertexEdges(String id, Map<String, String> queryParams, String txId) throws CrudException {
List<Edge> list = new ArrayList<Edge>();
list.add(Edge.fromJson(champEdge));
return list;
@@ -159,7 +159,7 @@ public class TestDao implements GraphDao {
}
@Override
- public void deleteEdge(String id, String type) throws CrudException {
+ public void deleteEdge(String id) throws CrudException {
}
@@ -217,13 +217,13 @@ public class TestDao implements GraphDao {
}
@Override
- public void deleteEdge(String id, String type, String txId) throws CrudException {
+ public void deleteEdge(String id, String txId) throws CrudException {
// TODO Auto-generated method stub
}
@Override
- public Edge getEdge(String id, String type, String txId) throws CrudException {
+ public Edge getEdge(String id, String txId) throws CrudException {
return Edge.fromJson(champEdge);
}
@@ -232,4 +232,10 @@ public class TestDao implements GraphDao {
headers.add("etag", "test123");
return headers;
}
+
+ @Override
+ public Edge getEdge(String id) throws CrudException {
+ // TODO Auto-generated method stub
+ return null;
+ }
} \ No newline at end of file
diff --git a/src/test/java/org/onap/schema/EdgeRulesLoaderTest.java b/src/test/java/org/onap/schema/EdgeRulesLoaderTest.java
index 05f998f..aad11fc 100644
--- a/src/test/java/org/onap/schema/EdgeRulesLoaderTest.java
+++ b/src/test/java/org/onap/schema/EdgeRulesLoaderTest.java
@@ -24,8 +24,13 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+
+import java.util.Set;
+
import org.junit.Test;
import org.onap.crud.exception.CrudException;
+import org.onap.crud.parser.EdgePayload;
+import org.onap.crud.util.CrudServiceUtil;
public class EdgeRulesLoaderTest {
@@ -54,6 +59,63 @@ public class EdgeRulesLoaderTest {
assertNull(g.lookupRelation("U:W:org.onap.relationships.inventory.groupsResourcesIn"));
}
+ @Test
+ public void getRelationshipTypeForNodePair() throws Exception {
+ EdgeRulesLoader.resetSchemaVersionContext();
+ EdgeRulesLoader.loadModels("v11");
+ RelationshipSchema schema = EdgeRulesLoader.getSchemaForVersion("v11");
+
+ EdgePayload payload1 = new EdgePayload();
+ payload1.setSource("services/inventory/v11/availability-zone/xxx");
+ payload1.setTarget("services/inventory/v11/cloud-region/xxx");
+
+ EdgePayload payload2 = new EdgePayload();
+ payload2.setSource("services/inventory/v11/image/xxx");
+ payload2.setTarget("services/inventory/v11/pserver/xxx");
+
+ EdgePayload payload3 = new EdgePayload();
+ payload3.setSource("services/inventory/v11/allotted-resource/xxx");
+ payload3.setTarget("services/inventory/v11/instance-group/xxx");
+
+ // Get edge types for node pair with a single possible edge between them
+ Set<String> typeList = schema.getValidRelationTypes("availability-zone", "cloud-region");
+ assertEquals(1, typeList.size());
+ assertTrue(typeList.contains("org.onap.relationships.inventory.BelongsTo"));
+ assertEquals(CrudServiceUtil.determineEdgeType(payload1, "v11"), "org.onap.relationships.inventory.BelongsTo");
+
+ // Get edge types for node pair with no possible edge between them
+ typeList = schema.getValidRelationTypes("image", "pserver");
+ assertEquals(0, typeList.size());
+ typeList = schema.getValidRelationTypes("cloud-region", "availability-zone");
+ assertEquals(0, typeList.size());
+
+ try {
+ // Should throw an exception here
+ CrudServiceUtil.determineEdgeType(payload2, "v11");
+ assertTrue(false);
+ }
+ catch (CrudException ex) {
+ System.out.println(ex.getMessage());
+ }
+
+ typeList = schema.getValidRelationTypes("allotted-resource", "instance-group");
+ assertEquals(2, typeList.size());
+ assertTrue(typeList.contains("org.onap.relationships.inventory.TestEdge"));
+ assertTrue(typeList.contains("org.onap.relationships.inventory.MemberOf"));
+
+ for (String type : typeList) {
+ System.out.println(type);
+ }
+
+ try {
+ // Should throw an exception here
+ CrudServiceUtil.determineEdgeType(payload3, "v11");
+ assertTrue(false);
+ }
+ catch (CrudException ex) {
+ System.out.println(ex.getMessage());
+ }
+ }
@Test
public void getSchemaForVersionFail() throws Exception {
diff --git a/src/test/resources/rules/DbEdgeRules_test_two_v11.json b/src/test/resources/rules/DbEdgeRules_test_two_v11.json
index f38bd2c..4ff4eb2 100644
--- a/src/test/resources/rules/DbEdgeRules_test_two_v11.json
+++ b/src/test/resources/rules/DbEdgeRules_test_two_v11.json
@@ -21,6 +21,18 @@
"delete-other-v": "NONE",
"SVC-INFRA": "NONE",
"prevent-delete": "!${direction}"
+ },
+ {
+ "from": "allotted-resource",
+ "to": "instance-group",
+ "label": "org.onap.relationships.inventory.TestEdge",
+ "direction": "OUT",
+ "multiplicity": "MANY2MANY",
+ "contains-other-v": "NONE",
+ "delete-other-v": "NONE",
+ "SVC-INFRA": "NONE",
+ "prevent-delete": "NONE",
+ "default": "true"
}
]
}