25e3e54a939adf56a98600434b93c39f3218b3a2
[dcaegen2/platform.git] / mod / runtimeapi / runtime-core / src / test / java / org / onap / dcae / runtime / core / TestFlowGraphParser.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END=========================================================
17  */
18 package org.onap.dcae.runtime.core;
19
20 import java.io.File;
21 import java.io.FileWriter;
22 import java.io.IOException;
23 import java.io.Writer;
24 import java.util.Map;
25 import org.junit.Rule;
26 import org.junit.rules.TemporaryFolder;
27 import org.junit.Test;
28 import static org.junit.Assert.assertEquals;
29 import org.onap.dcae.runtime.core.blueprint_creator.BlueprintCreatorOnap;
30
31 public class TestFlowGraphParser {
32
33     @Rule
34     public TemporaryFolder folder = new TemporaryFolder();
35
36     @Test
37     public void testFlowGraphParser() throws IOException {
38         try {
39         File importsfile = folder.newFile("imports.yaml");
40         try (Writer w = new FileWriter(importsfile)) {
41             w.write(
42                 "imports:\n" +
43                 " - 'http://www.getcloudify.org/spec/cloudify/3.4/types.yaml'\n" +
44                 " - 'https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R4/k8splugin/1.4.5/k8splugin_types.yaml'\n" +
45                 " - 'https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R4/dcaepolicyplugin/2.3.0/dcaepolicyplugin_types.yaml'\n"
46             );
47         }
48         FlowGraph<Node, Edge> mainFlowGraph = new FlowGraph<>("1234", "nifi-main", true, "mock graph");
49         mainFlowGraph.addNode(new Node("dummy_id", "dummy_name", "dummy_compspec"));
50         BlueprintCreatorOnap bcod = new BlueprintCreatorOnap();
51         bcod.setTopicUrl("u.r.l");
52         bcod.setImportFilePath(importsfile.getAbsolutePath());
53         FlowGraphParser flowGraphParser = new FlowGraphParser(bcod);
54         flowGraphParser.parse(mainFlowGraph);
55         String compspec = Helper.loadFileContent("src/test/data/compspecs/componentSpec_hello_world.json");
56         mainFlowGraph.addNode(new Node("comp5678", "hello-world-2", compspec));
57         mainFlowGraph.addNode(new Node("comp1234", "hello-world-1", compspec));
58         mainFlowGraph.addEdge(
59           flowGraphParser.getNodeFromId("comp1234"),
60           flowGraphParser.getNodeFromId("comp5678"), 
61           new Edge(
62             new EdgeLocation("comp1234", "DCAE-HELLO-WORLD-PUB-MR"),
63             new EdgeLocation("comp5678", "DCAE-HELLO-WORLD-SUB-MR"),
64             new EdgeMetadata("sample_topic_1", "json", "MR")));
65         flowGraphParser.createAndProcessBlueprints();
66         } catch (RuntimeException rte) {
67             rte.printStackTrace();
68             throw rte;
69         } catch (Exception e) {
70             e.printStackTrace();
71             throw new RuntimeException(e);
72         }
73     }
74 }