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