Update schema ingest library call schema service
[aai/aai-common.git] / aai-schema-ingest / src / test / java / org / onap / aai / edges / EdgeIngestorTest.java
index 6292da7..ab83e19 100644 (file)
@@ -1,4 +1,4 @@
-/** 
+/**
  * ============LICENSE_START=======================================================
  * org.onap.aai
  * ================================================================================
@@ -25,20 +25,22 @@ import static org.junit.Assert.*;
 import java.util.Collection;
 
 import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.runner.RunWith;
+import org.onap.aai.restclient.MockProvider;
+import org.onap.aai.restclient.MockRestClient;
+import org.onap.aai.config.EdgesConfiguration;
 import org.onap.aai.edges.enums.AAIDirection;
 import org.onap.aai.edges.enums.MultiplicityRule;
 import org.onap.aai.edges.exceptions.AmbiguousRuleChoiceException;
 import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException;
-import org.onap.aai.setup.SchemaLocationsBean;
 import org.onap.aai.setup.SchemaVersion;
-import org.onap.aai.setup.SchemaVersions;
-import org.onap.aai.testutils.TestUtilConfigTranslator;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.TestPropertySource;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -46,23 +48,29 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 import com.google.common.collect.Multimap;
 
 @RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(classes = {SchemaLocationsBean.class, SchemaVersions.class, TestUtilConfigTranslator.class, EdgeIngestor.class})
+@ContextConfiguration(classes = {MockProvider.class, EdgesConfiguration.class})
 @TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test.properties" })
+
+@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
 @SpringBootTest
 public class EdgeIngestorTest {
     @Autowired
-    EdgeIngestor ei;
-    
+    EdgeIngestor edgeIngestor;
+
     @Rule
     public ExpectedException thrown = ExpectedException.none();
-    
+
     @Test
     public void getRulesTest1() throws EdgeRuleNotFoundException {
         EdgeRuleQuery q = new EdgeRuleQuery.Builder("foo").build();
-        Multimap<String, EdgeRule> results = ei.getRules(q);
+        Multimap<String, EdgeRule> results = edgeIngestor.getRules(q);
+        System.out.println(results.size());
+        for (String key : results.keySet()) {
+            System.out.println(key);
+        }
         assertTrue(results.size() == 5);
         assertTrue(results.containsKey("bar|foo"));
-        
+
         assertTrue(2 == results.get("bar|foo").size());
         boolean seenLabel1 = false;
         boolean seenLabel2 = false;
@@ -75,16 +83,16 @@ public class EdgeIngestorTest {
             }
         }
         assertTrue(seenLabel1 && seenLabel2);
-        
+
         assertTrue(results.containsKey("baz|foo"));
         assertTrue(results.containsKey("foo|quux"));
         assertTrue(results.containsKey("dog|foo"));
     }
-    
+
     @Test
     public void getRulesTest2() throws EdgeRuleNotFoundException {
         EdgeRuleQuery q = new EdgeRuleQuery.Builder("dog", "puppy").build();
-        Multimap<String, EdgeRule> results = ei.getRules(q);
+        Multimap<String, EdgeRule> results = edgeIngestor.getRules(q);
         assertTrue(results.size() == 1);
         assertTrue(results.containsKey("dog|puppy"));
         Collection<EdgeRule> cr = results.get("dog|puppy");
@@ -100,11 +108,11 @@ public class EdgeIngestorTest {
             assertTrue(r.isDefault());
         }
     }
-    
+
     @Test
     public void getRulesFlippedTypesTest() throws EdgeRuleNotFoundException {
         EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface", "logical-link").version(new SchemaVersion("v11")).build();
-        Multimap<String, EdgeRule> results = ei.getRules(q);
+        Multimap<String, EdgeRule> results = edgeIngestor.getRules(q);
         assertTrue(results.size() == 3);
         for (EdgeRule r : results.get("l-interface|logical-link")) {
             if ("org.onap.relationships.inventory.Source".equals(r.getLabel()) ||
@@ -119,51 +127,51 @@ public class EdgeIngestorTest {
             }
         }
     }
-    
+
     @Test
     public void fromToSameFlipTests() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
         //getRules, setting from and to
         EdgeRuleQuery q = new EdgeRuleQuery.Builder("bloop","bloop").version(new SchemaVersion("v11")).build();
-        Multimap<String, EdgeRule> results = ei.getRules(q);
+        Multimap<String, EdgeRule> results = edgeIngestor.getRules(q);
         assertTrue(results.size() == 1);
         for (EdgeRule r : results.get("bloop|bloop")) {
             assertTrue(Direction.IN.equals(r.getDirection()));
         }
-        
+
         //getRule, setting just from
         EdgeRuleQuery q2 = new EdgeRuleQuery.Builder("bloop").version(new SchemaVersion("v11")).build();
-        assertTrue(Direction.IN.equals(ei.getRule(q2).getDirection()));
-        
+        assertTrue(Direction.IN.equals(edgeIngestor.getRule(q2).getDirection()));
+
         //getChildRules
-        Multimap<String, EdgeRule> child = ei.getChildRules("bloop", new SchemaVersion("v11"));
+        Multimap<String, EdgeRule> child = edgeIngestor.getChildRules("bloop", new SchemaVersion("v11"));
         assertTrue(child.size() == 1);
         for (EdgeRule r : child.get("bloop|bloop")) {
             assertTrue(Direction.IN.equals(r.getDirection()));
         }
     }
-    
+
     @Test
     public void getRulesTest3() throws EdgeRuleNotFoundException {
         EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface").version(new SchemaVersion("v11")).build();
-        Multimap<String, EdgeRule> results = ei.getRules(q);
+        Multimap<String, EdgeRule> results = edgeIngestor.getRules(q);
         assertTrue(results.size() == 4);
         assertTrue(results.containsKey("lag-interface|l-interface"));
         assertTrue(results.containsKey("l-interface|logical-link"));
         assertTrue(results.get("l-interface|logical-link").size() == 3);
     }
-    
+
     @Test
     public void getRulesNoneFound() throws EdgeRuleNotFoundException {
         thrown.expect(EdgeRuleNotFoundException.class);
         thrown.expectMessage("No rules found for");
-        EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface").build();
-        ei.getRules(q);
+        EdgeRuleQuery q = new EdgeRuleQuery.Builder("bogus-value").build();
+        edgeIngestor.getRules(q);
     }
-    
+
     @Test
     public void getRuleSimpleTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
         EdgeRuleQuery q = new EdgeRuleQuery.Builder("parent", "notation").build();
-        EdgeRule result = ei.getRule(q);
+        EdgeRule result = edgeIngestor.getRule(q);
         assertTrue("parent".equals(result.getFrom()));
         assertTrue("notation".equals(result.getTo()));
         assertTrue("has".equals(result.getLabel()));
@@ -174,11 +182,30 @@ public class EdgeIngestorTest {
         assertTrue(AAIDirection.NONE.toString().equals(result.getPreventDelete()));
         assertTrue("parent contains notation".equals(result.getDescription()));
     }
-    
+//    @Test
+//    public void getRuleSimpleTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
+//        EdgeRuleQuery q = new EdgeRuleQuery.Builder("parent", "notation").build();
+//        Multimap<String, EdgeRule> results = edgeIngestor.getRules(q);
+//        assertTrue(results.size() == 1);
+//        //        EdgeRule result = edgeIngestor.getRule(q);
+//        for (EdgeRule result : results.get("parent|notation")) {
+//            assertTrue("parent".equals(result.getFrom()));
+//            assertTrue("notation".equals(result.getTo()));
+//            assertTrue("has".equals(result.getLabel()));
+//            assertTrue(Direction.OUT.equals(result.getDirection()));
+//            assertTrue(MultiplicityRule.MANY2MANY.equals(result.getMultiplicityRule()));
+//            assertTrue(AAIDirection.OUT.toString().equals(result.getContains()));
+//            assertTrue(AAIDirection.NONE.toString().equals(result.getDeleteOtherV()));
+//            assertTrue(AAIDirection.NONE.toString().equals(result.getPreventDelete()));
+//            assertTrue("parent contains notation".equals(result.getDescription()));
+//        }
+//    }
+
+
     @Test
     public void getRuleFlippedTypesTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
         EdgeRuleQuery q = new EdgeRuleQuery.Builder("notation", "parent").build();
-        EdgeRule result = ei.getRule(q);
+        EdgeRule result = edgeIngestor.getRule(q);
         assertTrue("parent".equals(result.getFrom()));
         assertTrue("notation".equals(result.getTo()));
         assertTrue("has".equals(result.getLabel()));
@@ -190,95 +217,97 @@ public class EdgeIngestorTest {
         assertTrue(AAIDirection.NONE.toString().equals(result.getPreventDelete()));
         assertTrue("parent contains notation".equals(result.getDescription()));
     }
-    
+
     @Test
     public void getRuleWithDefaultTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
 
         EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface","logical-link").version(new SchemaVersion("v11")).build();
-        EdgeRule res = ei.getRule(q);
+        EdgeRule res = edgeIngestor.getRule(q);
         assertTrue(res.isDefault());
         assertTrue("tosca.relationships.network.LinksTo".equals(res.getLabel()));
     }
-    
+
     @Test
     public void getRuleWithNonDefault() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
         EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface","logical-link").label("org.onap.relationships.inventory.Source").version(new SchemaVersion("v11")).build();
-        EdgeRule res = ei.getRule(q);
+        EdgeRule res = edgeIngestor.getRule(q);
         assertFalse(res.isDefault());
         assertTrue("org.onap.relationships.inventory.Source".equals(res.getLabel()));
     }
-    
+
     @Test
     public void getRuleNoneFoundTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
         thrown.expect(EdgeRuleNotFoundException.class);
         thrown.expectMessage("No rule found for");
         EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface","nonexistent").build();
-        ei.getRule(q);
+        edgeIngestor.getRule(q);
     }
-    
+
     @Test
     public void getRuleTooManyPairsTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
         thrown.expect(AmbiguousRuleChoiceException.class);
         thrown.expectMessage("No way to select single rule from these pairs:");
         EdgeRuleQuery q = new EdgeRuleQuery.Builder("foo").build();
-        ei.getRule(q);
+        edgeIngestor.getRule(q);
     }
-    
+
     @Test
     public void getRuleAmbiguousDefaultTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
         thrown.expect(AmbiguousRuleChoiceException.class);
         thrown.expectMessage("Multiple defaults found.");
         EdgeRuleQuery q = new EdgeRuleQuery.Builder("seed","plant").version(new SchemaVersion("v11")).build();
-        ei.getRule(q);
+        edgeIngestor.getRule(q);
     }
-    
+
     @Test
     public void getRuleNoDefaultTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
         thrown.expect(AmbiguousRuleChoiceException.class);
         thrown.expectMessage("No default found.");
         EdgeRuleQuery q = new EdgeRuleQuery.Builder("apple", "orange").version(new SchemaVersion("v11")).build();
-        ei.getRule(q);
+        edgeIngestor.getRule(q);
     }
-    
+
     @Test
     public void hasRuleTest() {
-        assertTrue(ei.hasRule(new EdgeRuleQuery.Builder("l-interface").version(new SchemaVersion("v11")).build()));
-        assertFalse(ei.hasRule(new EdgeRuleQuery.Builder("l-interface").build()));
+        assertTrue(edgeIngestor.hasRule(new EdgeRuleQuery.Builder("l-interface").version(new SchemaVersion("v11")).build()));
+        assertFalse(edgeIngestor.hasRule(new EdgeRuleQuery.Builder("l-interface").version(new SchemaVersion("v10")).build()));
+        assertTrue(edgeIngestor.hasRule(new EdgeRuleQuery.Builder("l-interface").build()));
+//        assertFalse(edgeIngestor.hasRule(new EdgeRuleQuery.Builder("l-interface").build()));
     }
-    
+
     @Test
     public void getCousinRulesTest() {
-        Multimap<String, EdgeRule> results = ei.getCousinRules("dog");
+        Multimap<String, EdgeRule> results = edgeIngestor.getCousinRules("dog");
         assertTrue(results.size() == 2);
         assertTrue(results.containsKey("dog|puppy"));
         assertTrue(results.containsKey("dog|foo"));
     }
-    
+
     @Test
     public void getCousinRulesWithVersionTest() {
-        Multimap<String, EdgeRule> results = ei.getCousinRules("foo", new SchemaVersion("v10"));
+        Multimap<String, EdgeRule> results = edgeIngestor.getCousinRules("foo", new SchemaVersion("v10"));
         assertTrue(results.size() == 2);
         assertTrue(results.containsKey("bar|foo"));
         assertTrue(results.get("bar|foo").size() == 2);
     }
-    
+
     @Test
     public void getCousinsNoneInVersionTest() {
-        Multimap<String, EdgeRule> results = ei.getCousinRules("foo", new SchemaVersion("v11"));
+        Multimap<String, EdgeRule> results = edgeIngestor.getCousinRules("foo", new SchemaVersion("v11"));
         assertTrue(results.isEmpty());
     }
-    
+
     @Test
     public void hasCousinTest() {
-        assertTrue(ei.hasCousinRule("foo"));
-        assertTrue(ei.hasCousinRule("foo", new SchemaVersion("v10")));
-        assertFalse(ei.hasCousinRule("parent"));
-        assertFalse(ei.hasCousinRule("foo", new SchemaVersion("v11")));
+        assertTrue(edgeIngestor.hasCousinRule("foo"));
+        assertTrue(edgeIngestor.hasCousinRule("foo", new SchemaVersion("v10")));
+        assertFalse(edgeIngestor.hasCousinRule("parent"));
+        assertFalse(edgeIngestor.hasCousinRule("foo", new SchemaVersion("v11")));
     }
 
     @Test
     public void getChildRulesTest() {
-        Multimap<String, EdgeRule> results = ei.getChildRules("parent");
+        Multimap<String, EdgeRule> results = edgeIngestor.getChildRules("parent");
         assertTrue(results.size() == 6);
         assertTrue(results.containsKey("notation|parent"));
         assertTrue(results.containsKey("not-notation|parent"));
@@ -287,32 +316,32 @@ public class EdgeIngestorTest {
         assertTrue(results.containsKey("in-out|parent"));
         assertTrue(results.containsKey("out-in|parent"));
     }
-    
+
     @Test
     public void getChildRulesWithVersionTest() {
-        Multimap<String, EdgeRule> results = ei.getChildRules("foo", new SchemaVersion("v10"));
+        Multimap<String, EdgeRule> results = edgeIngestor.getChildRules("foo", new SchemaVersion("v10"));
         assertTrue(results.size() == 2);
         assertTrue(results.containsKey("baz|foo"));
         assertTrue(results.containsKey("foo|quux"));
     }
-    
+
     @Test
     public void getChildRulesNoneInVersionTest() {
-        Multimap<String, EdgeRule> results = ei.getChildRules("foo", new SchemaVersion("v11"));
+        Multimap<String, EdgeRule> results = edgeIngestor.getChildRules("foo", new SchemaVersion("v11"));
         assertTrue(results.isEmpty());
     }
-    
+
     @Test
     public void hasChildTest() {
-        assertTrue(ei.hasChildRule("foo"));
-        assertTrue(ei.hasChildRule("foo", new SchemaVersion("v10")));
-        assertFalse(ei.hasChildRule("puppy"));
-        assertFalse(ei.hasChildRule("foo", new SchemaVersion("v11")));
+        assertTrue(edgeIngestor.hasChildRule("foo"));
+        assertTrue(edgeIngestor.hasChildRule("foo", new SchemaVersion("v10")));
+        assertFalse(edgeIngestor.hasChildRule("puppy"));
+        assertFalse(edgeIngestor.hasChildRule("foo", new SchemaVersion("v11")));
     }
-    
+
     @Test
     public void getParentRulesTest() {
-        Multimap<String, EdgeRule> results = ei.getParentRules("parent");
+        Multimap<String, EdgeRule> results = edgeIngestor.getParentRules("parent");
         assertTrue(results.size() == 6);
         assertTrue(results.containsKey("grandparent1|parent"));
         assertTrue(results.containsKey("grandparent2|parent"));
@@ -321,45 +350,45 @@ public class EdgeIngestorTest {
         assertTrue(results.containsKey("grandparent5|parent"));
         assertTrue(results.containsKey("grandparent6|parent"));
     }
-    
+
     @Test
     public void getParentRulesWithVersionTest() {
-        Multimap<String, EdgeRule> results = ei.getParentRules("baz", new SchemaVersion("v10"));
+        Multimap<String, EdgeRule> results = edgeIngestor.getParentRules("baz", new SchemaVersion("v10"));
         assertTrue(results.size() == 1);
         assertTrue(results.containsKey("baz|foo"));
     }
-    
+
     @Test
     public void getParentRulesNoneInVersionTest() {
-        Multimap<String, EdgeRule> results = ei.getParentRules("baz", new SchemaVersion("v11"));
+        Multimap<String, EdgeRule> results = edgeIngestor.getParentRules("baz", new SchemaVersion("v11"));
         assertTrue(results.isEmpty());
     }
-    
+
     @Test
     public void hasParentTest() {
-        assertTrue(ei.hasParentRule("parent"));
-        assertTrue(ei.hasParentRule("quux", new SchemaVersion("v10")));
-        assertFalse(ei.hasParentRule("puppy"));
-        assertFalse(ei.hasParentRule("foo", new SchemaVersion("v11")));
+        assertTrue(edgeIngestor.hasParentRule("parent"));
+        assertTrue(edgeIngestor.hasParentRule("quux", new SchemaVersion("v10")));
+        assertFalse(edgeIngestor.hasParentRule("puppy"));
+        assertFalse(edgeIngestor.hasParentRule("foo", new SchemaVersion("v11")));
     }
-    
+
     @Test
     public void getAllCurrentRulesTest() throws EdgeRuleNotFoundException {
-        Multimap<String, EdgeRule> res = ei.getAllCurrentRules();
-        assertTrue(res.size() == 18);
+        Multimap<String, EdgeRule> res = edgeIngestor.getAllCurrentRules();
+        assertTrue(res.size() == 24);
     }
-    
+
     @Test
     public void getAllRulesTest() throws EdgeRuleNotFoundException {
-        Multimap<String, EdgeRule> res = ei.getAllRules(new SchemaVersion("v10"));
+        Multimap<String, EdgeRule> res = edgeIngestor.getAllRules(new SchemaVersion("v10"));
         assertTrue(res.size() == 4);
         assertTrue(res.containsKey("bar|foo"));
         assertTrue(res.get("bar|foo").size() == 2);
         assertTrue(res.containsKey("baz|foo"));
         assertTrue(res.containsKey("foo|quux"));
-        
+
         thrown.expect(EdgeRuleNotFoundException.class);
         thrown.expectMessage("No rules found for version v9.");
-        ei.getAllRules(new SchemaVersion("v9"));
+        edgeIngestor.getAllRules(new SchemaVersion("v9"));
     }
 }