Remove Multiplicity feature
[aai/gizmo.git] / src / test / java / org / onap / schema / EdgeRulesLoaderTest.java
index 073e1d3..2ad9456 100644 (file)
  */
 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.service.EdgePayload;
+import org.onap.crud.util.CrudServiceUtil;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.crud.OXMModelLoaderSetup;
 
-public class EdgeRulesLoaderTest {
+@RunWith(MockitoJUnitRunner.Silent.class)
+public class EdgeRulesLoaderTest extends OXMModelLoaderSetup{
 
     @Test
     public void loadModels() throws Exception {
@@ -56,6 +63,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 {