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 static org.junit.Assert.*;
26 import java.io.FileOutputStream;
27 import java.io.IOException;
28 import java.io.OutputStreamWriter;
29 import java.io.Writer;
30 import java.util.Map.Entry;
32 import org.apache.commons.io.FileUtils;
33 import org.junit.Test;
35 import com.google.common.collect.ImmutableSetMultimap;
36 import com.google.common.collect.Multimap;
38 import freemarker.template.TemplateException;
40 public class DbEdgeRulesConverterTest {
43 public void testExtractData() {
44 Multimap<String, String> EdgeRules = new ImmutableSetMultimap.Builder<String, String>()
45 .putAll("availability-zone|complex",
46 "groupsResourcesIn,OUT,Many2Many,false,true,false,true").build();
48 DbEdgeRulesConverter dberConverter = new DbEdgeRulesConverter();
50 for (Entry<String, String> r : EdgeRules.entries()) {
51 EdgeRuleBean bean = dberConverter.extractData(r);
52 assertEquals("from availability-zone", "availability-zone", bean.getFrom());
53 assertEquals("to complex", "complex", bean.getTo());
54 assertEquals("label", "groupsResourcesIn", bean.getLabel());
55 assertEquals("direction", "OUT", bean.getDirection());
56 assertEquals("multiplicity", "Many2Many", bean.getMultiplicity());
57 assertEquals("isParent", "false", bean.getIsParent());
58 assertEquals("usesResource", "true", bean.getUsesResource());
59 assertEquals("hasDelTarget", "false", bean.getHasDelTarget());
60 assertEquals("SVC-INFRA", "true", bean.getSvcInfra());
65 public void testConvert(){
66 DbEdgeRulesConverter dberCon = new DbEdgeRulesConverter();
67 String dest = "src/test/resources/dbEdgeRulesConversion";
68 String outFile = dest + "/testOutput.json";
70 Multimap<String, String> EdgeRules = new ImmutableSetMultimap.Builder<String, String>()
72 "has,OUT,Many2Many,false,false,false,false")
74 "treatsVeryKindly,IN,One2One,true,true,true,true")
79 File result = new File(outFile);
80 FileOutputStream writeStream = new FileOutputStream(result);
81 Writer writer = new OutputStreamWriter(writeStream);
82 dberCon.convert(EdgeRules, writer);
83 File compare = new File("src/test/resources/dbEdgeRulesConversion/conversionTestCompare.json");
84 assertTrue(FileUtils.contentEquals(result, compare));
85 } catch (IOException e) {
87 fail("IOException on setup");