X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Fschema%2FEdgeRulesLoaderTest.java;h=aad11fc0457b46c2c26b96190f2721d98b8bb6e7;hb=3bc6a702f2d3d8710c7aaa94cdc8c0ccf3deb759;hp=073e1d3b32b5bf5fe5e0fd39e6b743724002a183;hpb=00832f054dd0c21492af531548e321ea25cdb8b4;p=aai%2Fgizmo.git diff --git a/src/test/java/org/onap/schema/EdgeRulesLoaderTest.java b/src/test/java/org/onap/schema/EdgeRulesLoaderTest.java index 073e1d3..aad11fc 100644 --- a/src/test/java/org/onap/schema/EdgeRulesLoaderTest.java +++ b/src/test/java/org/onap/schema/EdgeRulesLoaderTest.java @@ -20,14 +20,17 @@ */ package org.onap.schema; -import org.junit.Test; -import org.onap.crud.exception.CrudException; +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.ArrayList; -import java.util.HashMap; -import java.util.Map; +import java.util.Set; -import static org.junit.Assert.*; +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 { @@ -56,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 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 {