2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.aai.dbmodel;
23 import com.google.common.collect.ImmutableSetMultimap;
24 import com.google.common.collect.Multimap;
25 import org.apache.commons.io.FileUtils;
26 import org.junit.Test;
29 import java.util.Map.Entry;
31 import static org.junit.Assert.*;
33 public class DbEdgeRulesConverterTest {
36 public void testExtractData() {
37 Multimap<String, String> EdgeRules = new ImmutableSetMultimap.Builder<String, String>()
38 .putAll("availability-zone|complex",
39 "groupsResourcesIn,OUT,Many2Many,false,true,false,true").build();
41 DbEdgeRulesConverter dberConverter = new DbEdgeRulesConverter();
43 for (Entry<String, String> r : EdgeRules.entries()) {
44 EdgeRuleBean bean = dberConverter.extractData(r);
45 assertEquals("from availability-zone", "availability-zone", bean.getFrom());
46 assertEquals("to complex", "complex", bean.getTo());
47 assertEquals("label", "groupsResourcesIn", bean.getLabel());
48 assertEquals("direction", "OUT", bean.getDirection());
49 assertEquals("multiplicity", "Many2Many", bean.getMultiplicity());
50 assertEquals("isParent", "false", bean.getIsParent());
51 assertEquals("usesResource", "true", bean.getUsesResource());
52 assertEquals("hasDelTarget", "false", bean.getHasDelTarget());
53 assertEquals("SVC-INFRA", "true", bean.getSvcInfra());
58 public void testConvert(){
59 DbEdgeRulesConverter dberCon = new DbEdgeRulesConverter();
60 String dest = "src/test/resources/dbEdgeRulesConversion";
61 String outFile = dest + "/testOutput.json";
63 Multimap<String, String> EdgeRules = new ImmutableSetMultimap.Builder<String, String>()
65 "has,OUT,Many2Many,false,false,false,false")
67 "treatsVeryKindly,IN,One2One,true,true,true,true")
72 File result = new File(outFile);
73 //Add delete hook to delete the temporary result file on exit/
74 result.deleteOnExit();
75 FileOutputStream writeStream = new FileOutputStream(result);
76 Writer writer = new OutputStreamWriter(writeStream);
77 dberCon.convert(EdgeRules, writer);
78 File compare = new File("src/test/resources/dbEdgeRulesConversion/conversionTestCompare.json");
79 assertTrue(FileUtils.contentEquals(result, compare));
81 } catch (IOException e) {
83 fail("IOException on setup");