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 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;
30 import java.io.IOException;
31 import java.util.HashMap;
34 import static org.junit.Assert.*;
36 public class RelationshipSchemaTest {
39 public void shouldLoadAllTheVersionsInDirectory() throws Exception {
40 RelationshipSchema rs = loadRelations();
41 assertTrue(!rs.lookupRelationType ("org.onap.some-relation" ).isEmpty ());
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);
52 public void shouldLookUpByRelation() throws Exception {
53 RelationshipSchema rs = loadRelations();
54 assertNotNull(rs.lookupRelation("service-instance:customer:org.onap.some-relation"));
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"));
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\"" +
72 Map<String, String> ruleOne = new HashMap<> ( );
73 Map<String, String> ruleTwo = new HashMap<> ( );
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", "");
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", "");
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 );