From cc9d389bf197c1a365e669b407ea781f2bc87fd4 Mon Sep 17 00:00:00 2001 From: Michael Hwang Date: Wed, 20 Nov 2019 12:32:48 -0500 Subject: Add mod/runtimeapi Change-Id: I6c0a45ddf460a63a1e4b9284e19bf4ab111bd463 Issue-ID: DCAEGEN2-1860 Signed-off-by: Michael Hwang --- .../java/org/onap/dcae/runtime/core/Helper.java | 67 +++++++++++++++ .../org/onap/dcae/runtime/core/TestFlowGraph.java | 97 ++++++++++++++++++++++ .../dcae/runtime/core/TestFlowGraphParser.java | 49 +++++++++++ .../onap/dcae/runtime/core/TestIntegeration.java | 54 ++++++++++++ .../org/onap/dcae/runtime/core/TestOnapBpGen.java | 35 ++++++++ .../onap/dcae/runtime/core/TestStringReplace.java | 38 +++++++++ .../dcae/runtime/core/TestYamlStringToObject.java | 52 ++++++++++++ 7 files changed, 392 insertions(+) create mode 100644 mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/Helper.java create mode 100644 mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestFlowGraph.java create mode 100644 mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestFlowGraphParser.java create mode 100644 mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestIntegeration.java create mode 100644 mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestOnapBpGen.java create mode 100644 mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestStringReplace.java create mode 100644 mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestYamlStringToObject.java (limited to 'mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime') diff --git a/mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/Helper.java b/mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/Helper.java new file mode 100644 index 0000000..c75ed5d --- /dev/null +++ b/mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/Helper.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.onap.dcae.runtime.core; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; + +public class Helper { + public static String loadFileContent(String filePath) { + String fileContent = ""; + try { + fileContent = new String(Files.readAllBytes(Paths.get(filePath)),"UTF-8"); + } catch (IOException e) { + e.printStackTrace(); + } + return fileContent; + } + + public static Map loadTestBlueprints() { + Map expectedBlueprints = new HashMap(); + expectedBlueprints.put("hello-world-2_blueprint", + loadFileContent("src/test/data/blueprints/helloworld_test_2.yaml")); + expectedBlueprints.put("hello-world-1_blueprint", + loadFileContent("src/test/data/blueprints/helloworld_test_1.yaml")); + return expectedBlueprints; + } + + public static Edge getTestEdge(){ + EdgeLocation src = new EdgeLocation("comp1234","DCAE-HELLO-WORLD-PUB-MR"); + EdgeLocation tgt = new EdgeLocation("comp5678", "DCAE-HELLO-WORLD-SUB-MR"); + EdgeMetadata metadata = new EdgeMetadata("sample_topic_1", "json", "MR"); + Edge edge = new Edge(src, tgt, metadata); + return edge; + } + + public static FlowGraph prepareFlowGraph() { + FlowGraph flowGraph = new FlowGraph("random_id","anyName",true,"someDescription"); + + Node node_1 = new Node("comp1234", "hello-world-1", + Helper.loadFileContent("src/test/data/compspecs/componentSpec_hello_world.json")); + Node node_2 = new Node("comp5678", "hello-world-2", + Helper.loadFileContent("src/test/data/compspecs/componentSpec_hello_world.json")); + flowGraph.addNode(node_1); + flowGraph.addNode(node_2); + flowGraph.addEdge(node_1,node_2,Helper.getTestEdge()); + + return flowGraph; + } +} diff --git a/mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestFlowGraph.java b/mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestFlowGraph.java new file mode 100644 index 0000000..b7a74b2 --- /dev/null +++ b/mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestFlowGraph.java @@ -0,0 +1,97 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.onap.dcae.runtime.core; + +import org.junit.Before; +import org.junit.Test; + +import java.util.HashSet; +import java.util.Set; + +import static org.junit.Assert.*; + +public class TestFlowGraph { + + private FlowGraph flowGraph; + private Node node_1; + private Node node_2; + + @Before + public void setUp() throws Exception{ + flowGraph = new FlowGraph("random_id","anyName",true,"someDescription"); + node_1 = new Node("comp1234", "component_1", ""); + node_2 = new Node("comp5678", "component_2", ""); + flowGraph.addNode(node_1); + flowGraph.addNode(node_2); + } + + @Test + public void testFlowGraphProperties() throws Exception{ + assertEquals("random_id",flowGraph.getId()); + assertEquals("anyName",flowGraph.getName()); + assertEquals("someDescription",flowGraph.getDescription()); + assertTrue(flowGraph.isMain()); + } + + @Test + public void testAddNodeToGraph() throws Exception{ + Set nodes = new HashSet(); + nodes.add(node_1); + nodes.add(node_2); + + assertEquals(2,flowGraph.getNodeSize()); + assertEquals(nodes,flowGraph.getNodes()); + + } + + @Test + public void testAddEdgeToGraph() throws Exception{ + Edge edge_1 = Helper.getTestEdge(); + flowGraph.addEdge(node_1,node_2,edge_1); + assertEquals(1, flowGraph.getEdgeSize()); + assertEquals(edge_1, flowGraph.getEdge(node_1,node_2)); + } + + @Test + public void testRemoveNodeFromGraph() throws Exception{ + flowGraph.removeNode(node_1); + assertEquals(1,flowGraph.getNodeSize()); + assertEquals(node_2,flowGraph.getNodes().toArray()[0]); + } + + @Test + public void testRemoveEdgeFromGraph() throws Exception{ + Edge edge_1 = Helper.getTestEdge(); + flowGraph.addEdge(node_1,node_2,edge_1); + flowGraph.removeEdge(edge_1); + assertEquals(0,flowGraph.getEdgeSize()); + } + + @Test + public void testDummyNodeInEdge() throws Exception{ + Node node_dummy = new Node("dummy", "component_dummy", ""); + Edge edge_1 = Helper.getTestEdge(); + Edge edge_2 = Helper.getTestEdge(); + Edge edge_3 = Helper.getTestEdge(); + flowGraph.addEdge(node_dummy,node_2,edge_1); + flowGraph.addEdge(node_2,node_dummy,edge_2); + flowGraph.addEdge(node_1,node_dummy,edge_3); + System.out.println(flowGraph.getNodes()); + System.out.println(flowGraph.getEdges()); + } +} diff --git a/mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestFlowGraphParser.java b/mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestFlowGraphParser.java new file mode 100644 index 0000000..bacfcb1 --- /dev/null +++ b/mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestFlowGraphParser.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.onap.dcae.runtime.core; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.onap.dcae.runtime.core.blueprint_creator.BlueprintCreatorOnapDublin; + +public class TestFlowGraphParser { + + private FlowGraph flowGraph; + private FlowGraphParser flowGraphParser; + + @Before + public void setUp() throws Exception{ + flowGraph = Helper.prepareFlowGraph(); + flowGraphParser = new FlowGraphParser(new BlueprintCreatorOnapDublin()); + flowGraphParser.parse(flowGraph); + } + + @Test + @Ignore + public void testBlueprintsCreate() throws Exception{ + /* + TODO: FIX + Map expectedBlueprints = Helper.loadTestBlueprints(); + Map resultBlueprints = flowGraphParser.createAndProcessBlueprints(); + + assertEquals(expectedBlueprints,resultBlueprints); + */ + } + +} diff --git a/mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestIntegeration.java b/mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestIntegeration.java new file mode 100644 index 0000000..612f9f0 --- /dev/null +++ b/mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestIntegeration.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.onap.dcae.runtime.core; + +import org.onap.dcae.runtime.core.blueprint_creator.BlueprintCreator; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.onap.dcae.runtime.core.blueprint_creator.BlueprintCreatorOnapDublin; + +public class TestIntegeration { + + private FlowGraphParser flowGraphParser; + + @Before + public void setUp() throws Exception{ + //1. prepare Graph + FlowGraph flowGraph = Helper.prepareFlowGraph(); + + //2. Inject graph in FlowGraphParser + BlueprintCreator blueprintCreator = new BlueprintCreatorOnapDublin(); + flowGraphParser = new FlowGraphParser(blueprintCreator); + flowGraphParser.parse(flowGraph); + } + + @Test + @Ignore + public void testParserCreatesBlueprintsFromFlowGraph() throws Exception{ + /* + TODO: FIX + //3. Check if the parser can create blueprints for the componentSpec collection + //resultMap has key as a component-name and value is a blueprint string + Map expectedBlueprints = Helper.loadTestBlueprints(); + Map resultBlueprints = flowGraphParser.createAndProcessBlueprints(); + + assertEquals(expectedBlueprints,resultBlueprints); + */ + } +} diff --git a/mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestOnapBpGen.java b/mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestOnapBpGen.java new file mode 100644 index 0000000..f717022 --- /dev/null +++ b/mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestOnapBpGen.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.onap.dcae.runtime.core; + +import org.junit.Test; +import org.onap.blueprintgenerator.models.blueprint.Blueprint; +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; + +public class TestOnapBpGen { + + @Test + public void testOnapBPGeneration() throws Exception{ + ComponentSpec componentSpec = new ComponentSpec(); + componentSpec.createComponentSpecFromString(Helper.loadFileContent( + "src/test/data/compspecs/componentSpec_hello_world_only_MR.json")); + + Blueprint bp = new Blueprint().createBlueprint(componentSpec,"",'d',""); + System.out.println(bp.getInputs()); + } +} diff --git a/mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestStringReplace.java b/mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestStringReplace.java new file mode 100644 index 0000000..4917d76 --- /dev/null +++ b/mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestStringReplace.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.onap.dcae.runtime.core; + +import org.junit.Ignore; +import org.junit.Test; + +public class TestStringReplace { + + @Test + @Ignore + public void testFindTopicFromBlueprint() throws Exception{ + String bp_string = Helper.loadFileContent("src/test/data/blueprints/helloworld_test_1.yaml"); +// //Pattern pattern = Pattern.compile("DCAE-HELLO-WORLD-PUB-MR_topic(.*)_name:[\\s\\S]*default: 'DCAE-HELLO-WORLD-PUB-MR'"); +// Pattern pattern = Pattern.compile("'DCAE-HELLO-WORLD-PUB-MR'"); +// Matcher matcher = pattern.matcher(bp_string); +// +// while(matcher.find()){ +// System.out.println(bp_string.substring(matcher.start(),matcher.end())); +// } + System.out.println(bp_string.replaceAll("'DCAE-HELLO-WORLD-PUB-MR'", "'sample_topic_0'")); + } +} diff --git a/mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestYamlStringToObject.java b/mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestYamlStringToObject.java new file mode 100644 index 0000000..ebc31e5 --- /dev/null +++ b/mod/runtimeapi/runtime-core/src/test/java/org/onap/dcae/runtime/core/TestYamlStringToObject.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.onap.dcae.runtime.core; + +import org.junit.Test; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.Yaml; + +import java.util.Map; + +public class TestYamlStringToObject { + + @Test + public void testYamlStringToObject() throws Exception{ + String bp_content = Helper.loadFileContent("src/test/data/blueprints/helloworld_onap_dublin.yaml"); + String locationPort = "DCAE-HELLO-WORLD-SUB-MR"; + Yaml yaml = getYamlInstance(); + Map obj = yaml.load(bp_content); + Map inputsObj = (Map) obj.get("inputs"); + for(Map.Entry entry: inputsObj.entrySet()){ + System.out.println(String.format("^%s.*url",locationPort.replaceAll("-","_"))); + if(entry.getKey().matches(String.format("^%s.*url",locationPort.replaceAll("-","_")))) { + Map inputValue = (Map) entry.getValue(); + inputValue.put("default","test_topic"); + System.out.println(entry); + } + } + // System.out.println(yaml.dump(obj)); + } + + private Yaml getYamlInstance() { + DumperOptions options = new DumperOptions(); + options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + options.setPrettyFlow(true); + return new Yaml(options); + } +} -- cgit 1.2.3-korg