Add mod/runtimeapi
[dcaegen2/platform.git] / mod / runtimeapi / runtime-web / src / test / java / org / onap / dcae / runtime / web / Helper.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2019 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.web;
19
20 import org.onap.dcae.runtime.web.models.Action;
21
22 import java.io.IOException;
23 import java.nio.file.Files;
24 import java.nio.file.Paths;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29
30 public class Helper {
31     public static String loadFileContent(String filePath) {
32         String fileContent = "";
33         try {
34             fileContent = new String(Files.readAllBytes(Paths.get(filePath)),"UTF-8");
35         } catch (IOException e) {
36             e.printStackTrace();
37         }
38         return fileContent;
39     }
40
41     public static Map<String, String> loadTestBlueprints() {
42         Map<String,String> expectedBlueprints = new HashMap<String, String>();
43         expectedBlueprints.put("hello-world_blueprint",
44                 loadFileContent("src/test/data/blueprints/helloworld_test_2.yaml"));
45         expectedBlueprints.put("toolbox_blueprint",
46                 loadFileContent("src/test/data/blueprints/dcae-controller-toolbox-gui-eom-k8s.yaml"));
47         return expectedBlueprints;
48     }
49
50     public static List<Action> getAddNodeActionsForRequest() {
51         List<Action> actions = new ArrayList<Action>();
52         Map<String,Object> payloadMap;
53
54         Action action_1 = new Action();
55         payloadMap = new HashMap<String,Object>();
56         payloadMap.put("component_id","comp5678");
57         payloadMap.put("name","hello-world-2");
58         payloadMap.put("component_spec", Helper.loadFileContent("src/test/data/compspecs/componentSpec_hello_world.json"));
59         action_1.setPayload(payloadMap);
60         action_1.setCommand("addnode");
61
62         Action action_2 = new Action();
63         payloadMap = new HashMap<String,Object>();
64         payloadMap.put("component_id","comp1234");
65         payloadMap.put("name","hello-world-1");
66         payloadMap.put("component_spec", Helper.loadFileContent("src/test/data/compspecs/componentSpec_hello_world.json"));
67         action_2.setPayload(payloadMap);
68         action_2.setCommand("addnode");
69
70         actions.add(action_1);
71         actions.add(action_2);
72
73         return actions;
74     }
75
76     public static Map<String, String> prepareExpectedResult() {
77         Map<String,String> result = new HashMap<>();
78 //        result.put("HelloWorld_blueprint",loadFileContent("src/test/data/blueprints_samples/dcae-collectors-vcc-helloworld-pm-eom-k8s.yaml"));
79 //        result.put("Toolbox_blueprint",loadFileContent("src/test/data/blueprints_samples/dcae-controller-toolbox-gui-eom-k8s.yaml"));
80         result.put("hello-world-1_blueprint",loadFileContent("src/test/data/blueprints_samples/helloworld_test_1.yaml"));
81         result.put("hello-world-2_blueprint",loadFileContent("src/test/data/blueprints_samples/helloworld_test_2.yaml"));
82         return result;
83     }
84
85     public static List<Action> getAddNodesWithEdge() {
86         List<Action> actions = getAddNodeActionsForRequest();
87         Map<String,Object> payloadMap = new HashMap<String,Object>();
88
89         Map<String,String> src = new HashMap<>();
90         src.put("node", "comp1234");
91         src.put("port", "DCAE-HELLO-WORLD-PUB-MR");
92
93         Map<String,String> tgt = new HashMap<>();
94         tgt.put("node", "comp5678");
95         tgt.put("port", "DCAE-HELLO-WORLD-SUB-MR");
96
97         Map<String,String> metadata = new HashMap<>();
98         metadata.put("name","sample_topic_1");
99         metadata.put("data_type","json");
100         metadata.put("dmaap_type","MR");
101
102         payloadMap.put("src",src);
103         payloadMap.put("tgt",tgt);
104         payloadMap.put("metadata",metadata);
105
106         Action action = new Action();
107         action.setCommand("addedge");
108         action.setPayload(payloadMap);
109
110         actions.add(action);
111         System.out.println(action.getPayload().get("src"));
112
113         return actions;
114     }
115
116     public static Map<String, String> prepareExpectedResultForAddEdge() {
117         Map<String,String> result = new HashMap<>();
118         result.put("hello-world-1_blueprint",loadFileContent("src/test/data/blueprints_samples/helloworld_test_1.yaml"));
119         result.put("hello-world-2_blueprint",loadFileContent("src/test/data/blueprints_samples/helloworld_test_2.yaml"));
120         return result;
121     }
122 }