9467f41515d411615a6afb8be5890a898219ea68
[aai/gizmo.git] / src / test / java / org / onap / schema / RelationshipSchemaTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.schema;
22
23 import com.google.common.collect.ArrayListMultimap;
24 import com.google.common.collect.Multimap;
25 import org.junit.Test;
26 import org.onap.aai.edges.EdgeRule;
27 import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException;
28 import org.onap.crud.exception.CrudException;
29
30 import java.io.IOException;
31 import java.util.HashMap;
32 import java.util.Map;
33
34 import static org.junit.Assert.*;
35
36 public class RelationshipSchemaTest {
37
38     @Test
39     public void shouldLoadAllTheVersionsInDirectory() throws Exception {
40         RelationshipSchema rs = loadRelations();
41         assertTrue(!rs.lookupRelationType ("org.onap.some-relation"  ).isEmpty ());
42     }
43
44     @Test
45     public void shouldContainValidTypes() throws Exception {
46         RelationshipSchema rs = loadRelations();
47         assertTrue(rs.lookupRelationType ("org.onap.some-relation") != null);
48         assertTrue(rs.lookupRelationType("notValidType") == null);
49     }
50
51     @Test
52     public void shouldLookUpByRelation() throws Exception {
53         RelationshipSchema rs = loadRelations();
54         assertNotNull(rs.lookupRelation("service-instance:customer:org.onap.some-relation"));
55     }
56
57     @Test
58     public void shouldLookUpByRelationType() throws Exception {
59         RelationshipSchema rs = loadRelations();
60         assertNotNull(rs.lookupRelationType("org.onap.groupsResourcesIn"));
61         assertTrue(rs.lookupRelation("availability-zone:complex:org.onap.groupsResourcesIn").containsKey("prevent-delete"));
62     }
63
64     private RelationshipSchema loadRelations() throws CrudException, EdgeRuleNotFoundException, IOException {
65         String defaultEdgeProps = "{" +
66                 "\"contains-other-v\": \"java.lang.String\"," +
67                 "\"delete-other-v\": \"java.lang.String\"," +
68                 "\"SVC-INFRA\": \"java.lang.String\"," +
69                 "\"prevent-delete\": \"java.lang.String\"" +
70                 "}";
71
72         Map<String, String> ruleOne = new HashMap<> (  );
73         Map<String, String> ruleTwo = new HashMap<> (  );
74
75         ruleOne.put("label", "org.onap.some-relation");
76         ruleOne.put("direction", "OUT");
77         ruleOne.put("contains-other-v", "NONE");
78         ruleOne.put("delete-other-v", "NONE");
79         ruleOne.put("prevent-delete", "NONE");
80         ruleOne.put("from", "service-instance");
81         ruleOne.put("to", "customer");
82         ruleOne.put("multiplicity", "MANY2MANY");
83         ruleOne.put("default", "true");
84         ruleOne.put("description", "");
85
86         ruleTwo.put("label", "org.onap.groupsResourcesIn");
87         ruleTwo.put("direction", "OUT");
88         ruleTwo.put("contains-other-v", "NONE");
89         ruleTwo.put("delete-other-v", "NONE");
90         ruleTwo.put("prevent-delete", "NONE");
91         ruleTwo.put("from", "availability-zone");
92         ruleTwo.put("to", "complex");
93         ruleTwo.put("multiplicity", "MANY2MANY");
94         ruleTwo.put("default", "true");
95         ruleTwo.put("description", "");
96
97         EdgeRule erOne = new EdgeRule ( ruleOne );
98         EdgeRule erTwo = new EdgeRule ( ruleTwo );
99         Multimap<String, EdgeRule> relationship = ArrayListMultimap.create();
100         relationship.put ( "customer|service-instane", erOne );
101         relationship.put ( "availability-zone|complex", erTwo );
102         return new RelationshipSchema ( relationship, defaultEdgeProps );
103
104     }
105 }