From 9941d0d8597d9d69954819ca9458962aee281b10 Mon Sep 17 00:00:00 2001 From: "Threefoot, Jane (jt6620)" Date: Mon, 31 Jul 2017 15:49:04 -0400 Subject: [AAI-100 Amsterdam] refactored dbedgerules Change-Id: I778a56f525cba0ebd39d24d366fc9f0935be71f2 Signed-off-by: Threefoot, Jane (jt6620) --- .../aai/dbmodel/DbEdgeRulesConverterTest.java | 90 ++++++++++++++++++++++ .../aai/serialization/db/EdgeRulesTest.java | 7 +- 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 aai-core/src/test/java/org/openecomp/aai/dbmodel/DbEdgeRulesConverterTest.java (limited to 'aai-core/src/test/java') diff --git a/aai-core/src/test/java/org/openecomp/aai/dbmodel/DbEdgeRulesConverterTest.java b/aai-core/src/test/java/org/openecomp/aai/dbmodel/DbEdgeRulesConverterTest.java new file mode 100644 index 00000000..1310a05b --- /dev/null +++ b/aai-core/src/test/java/org/openecomp/aai/dbmodel/DbEdgeRulesConverterTest.java @@ -0,0 +1,90 @@ +/*- + * ============LICENSE_START======================================================= + * org.openecomp.aai + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.aai.dbmodel; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.util.Map.Entry; + +import org.apache.commons.io.FileUtils; +import org.junit.Test; + +import com.google.common.collect.ImmutableSetMultimap; +import com.google.common.collect.Multimap; + +import freemarker.template.TemplateException; + +public class DbEdgeRulesConverterTest { + + @Test + public void testExtractData() { + Multimap EdgeRules = new ImmutableSetMultimap.Builder() + .putAll("availability-zone|complex", + "groupsResourcesIn,OUT,Many2Many,false,true,false,true").build(); + + DbEdgeRulesConverter dberConverter = new DbEdgeRulesConverter(); + + for (Entry r : EdgeRules.entries()) { + EdgeRuleBean bean = dberConverter.extractData(r); + assertEquals("from availability-zone", "availability-zone", bean.getFrom()); + assertEquals("to complex", "complex", bean.getTo()); + assertEquals("label", "groupsResourcesIn", bean.getLabel()); + assertEquals("direction", "OUT", bean.getDirection()); + assertEquals("multiplicity", "Many2Many", bean.getMultiplicity()); + assertEquals("isParent", "false", bean.getIsParent()); + assertEquals("usesResource", "true", bean.getUsesResource()); + assertEquals("hasDelTarget", "false", bean.getHasDelTarget()); + assertEquals("SVC-INFRA", "true", bean.getSvcInfra()); + } + } + + @Test + public void testConvert(){ + DbEdgeRulesConverter dberCon = new DbEdgeRulesConverter(); + String dest = "src/test/resources/dbEdgeRulesConversion"; + String outFile = dest + "/testOutput.json"; + + Multimap EdgeRules = new ImmutableSetMultimap.Builder() + .putAll("foo|bar", + "has,OUT,Many2Many,false,false,false,false") + .putAll("baz|quux", + "treatsVeryKindly,IN,One2One,true,true,true,true") + .build(); + + try { + dberCon.setup(dest); + File result = new File(outFile); + FileOutputStream writeStream = new FileOutputStream(result); + Writer writer = new OutputStreamWriter(writeStream); + dberCon.convert(EdgeRules, writer); + File compare = new File("src/test/resources/dbEdgeRulesConversion/conversionTestCompare.json"); + assertTrue(FileUtils.contentEquals(result, compare)); + } catch (IOException e) { + e.printStackTrace(); + fail("IOException on setup"); + } + } +} diff --git a/aai-core/src/test/java/org/openecomp/aai/serialization/db/EdgeRulesTest.java b/aai-core/src/test/java/org/openecomp/aai/serialization/db/EdgeRulesTest.java index 69f8642f..5e73e3bc 100644 --- a/aai-core/src/test/java/org/openecomp/aai/serialization/db/EdgeRulesTest.java +++ b/aai-core/src/test/java/org/openecomp/aai/serialization/db/EdgeRulesTest.java @@ -25,6 +25,7 @@ import static org.junit.Assert.assertEquals; import java.util.Map; import org.apache.tinkerpop.gremlin.structure.Direction; +import org.junit.BeforeClass; import org.junit.Test; import org.openecomp.aai.exceptions.AAIException; @@ -32,7 +33,11 @@ import org.openecomp.aai.serialization.db.exceptions.NoEdgeRuleFoundException; public class EdgeRulesTest { - + @BeforeClass + public static void setup() { + System.setProperty("AJSC_HOME", "."); + System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local"); + } @Test -- cgit 1.2.3-korg