diff options
author | 2018-07-19 16:03:44 -0400 | |
---|---|---|
committer | 2018-07-19 16:08:20 -0400 | |
commit | 3bc6a702f2d3d8710c7aaa94cdc8c0ccf3deb759 (patch) | |
tree | 9703ebe15777acc73ad118520f6b1a219f60e107 /src/test/java/org/onap/schema | |
parent | 194adee686ebb90488f739f2c637f6cb3def94d5 (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/java/org/onap/schema')
-rw-r--r-- | src/test/java/org/onap/schema/EdgeRulesLoaderTest.java | 62 |
1 files changed, 62 insertions, 0 deletions
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 { |