2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.schema;
23 import static org.junit.Assert.*;
24 import java.io.IOException;
25 import java.util.HashMap;
27 import org.junit.Test;
28 import org.onap.aai.edges.EdgeRule;
29 import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException;
30 import org.onap.crud.exception.CrudException;
31 import com.google.common.collect.ArrayListMultimap;
32 import com.google.common.collect.Multimap;
34 public class RelationshipSchemaTest {
37 public void shouldLoadAllTheVersionsInDirectory() throws Exception {
38 RelationshipSchema rs = loadRelations();
39 assertTrue(!rs.lookupRelationType ("org.onap.some-relation" ).isEmpty ());
43 public void shouldContainValidTypes() throws Exception {
44 RelationshipSchema rs = loadRelations();
45 assertTrue(rs.lookupRelationType ("org.onap.some-relation") != null);
46 assertTrue(rs.lookupRelationType("notValidType") == null);
50 public void shouldLookUpByRelation() throws Exception {
51 RelationshipSchema rs = loadRelations();
52 assertNotNull(rs.lookupRelation("service-instance:customer:org.onap.some-relation"));
56 public void shouldLookUpByRelationType() throws Exception {
57 RelationshipSchema rs = loadRelations();
58 assertNotNull(rs.lookupRelationType("org.onap.groupsResourcesIn"));
59 assertTrue(rs.lookupRelation("availability-zone:complex:org.onap.groupsResourcesIn").containsKey("prevent-delete"));
62 private RelationshipSchema loadRelations() throws CrudException, EdgeRuleNotFoundException, IOException {
63 String defaultEdgeProps = "{" +
64 "\"contains-other-v\": \"java.lang.String\"," +
65 "\"delete-other-v\": \"java.lang.String\"," +
66 "\"SVC-INFRA\": \"java.lang.String\"," +
67 "\"prevent-delete\": \"java.lang.String\"" +
70 Map<String, String> ruleOne = new HashMap<> ( );
71 Map<String, String> ruleTwo = new HashMap<> ( );
73 ruleOne.put("label", "org.onap.some-relation");
74 ruleOne.put("direction", "OUT");
75 ruleOne.put("contains-other-v", "NONE");
76 ruleOne.put("delete-other-v", "NONE");
77 ruleOne.put("prevent-delete", "NONE");
78 ruleOne.put("from", "service-instance");
79 ruleOne.put("to", "customer");
80 ruleOne.put("multiplicity", "MANY2MANY");
81 ruleOne.put("default", "true");
82 ruleOne.put("description", "");
84 ruleTwo.put("label", "org.onap.groupsResourcesIn");
85 ruleTwo.put("direction", "OUT");
86 ruleTwo.put("contains-other-v", "NONE");
87 ruleTwo.put("delete-other-v", "NONE");
88 ruleTwo.put("prevent-delete", "NONE");
89 ruleTwo.put("from", "availability-zone");
90 ruleTwo.put("to", "complex");
91 ruleTwo.put("multiplicity", "MANY2MANY");
92 ruleTwo.put("default", "true");
93 ruleTwo.put("description", "");
95 EdgeRule erOne = new EdgeRule ( ruleOne );
96 EdgeRule erTwo = new EdgeRule ( ruleTwo );
97 Multimap<String, EdgeRule> relationship = ArrayListMultimap.create();
98 relationship.put ( "customer|service-instane", erOne );
99 relationship.put ( "availability-zone|complex", erTwo );
100 return new RelationshipSchema ( relationship, defaultEdgeProps );