summaryrefslogtreecommitdiffstats
path: root/mod/runtimeapi/runtime-web/src/test/java/org/onap/dcae/runtime/web/Helper.java
blob: 52ccf0f827d852b0a1222da97496a0f1ef58d8c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*-
 * ============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.web;

import org.onap.dcae.runtime.web.models.Action;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
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<String, String> loadTestBlueprints() {
        Map<String,String> expectedBlueprints = new HashMap<String, String>();
        expectedBlueprints.put("hello-world_blueprint",
                loadFileContent("src/test/data/blueprints/helloworld_test_2.yaml"));
        expectedBlueprints.put("toolbox_blueprint",
                loadFileContent("src/test/data/blueprints/dcae-controller-toolbox-gui-eom-k8s.yaml"));
        return expectedBlueprints;
    }

    public static List<Action> getAddNodeActionsForRequest() {
        List<Action> actions = new ArrayList<Action>();
        Map<String,Object> payloadMap;

        Action action_1 = new Action();
        payloadMap = new HashMap<String,Object>();
        payloadMap.put("component_id","comp5678");
        payloadMap.put("name","hello-world-2");
        payloadMap.put("component_spec", Helper.loadFileContent("src/test/data/compspecs/componentSpec_hello_world.json"));
        action_1.setPayload(payloadMap);
        action_1.setCommand("addnode");

        Action action_2 = new Action();
        payloadMap = new HashMap<String,Object>();
        payloadMap.put("component_id","comp1234");
        payloadMap.put("name","hello-world-1");
        payloadMap.put("component_spec", Helper.loadFileContent("src/test/data/compspecs/componentSpec_hello_world.json"));
        action_2.setPayload(payloadMap);
        action_2.setCommand("addnode");

        actions.add(action_1);
        actions.add(action_2);

        return actions;
    }

    public static Map<String, String> prepareExpectedResult() {
        Map<String,String> result = new HashMap<>();
//        result.put("HelloWorld_blueprint",loadFileContent("src/test/data/blueprints_samples/dcae-collectors-vcc-helloworld-pm-eom-k8s.yaml"));
//        result.put("Toolbox_blueprint",loadFileContent("src/test/data/blueprints_samples/dcae-controller-toolbox-gui-eom-k8s.yaml"));
        result.put("hello-world-1_blueprint",loadFileContent("src/test/data/blueprints_samples/helloworld_test_1.yaml"));
        result.put("hello-world-2_blueprint",loadFileContent("src/test/data/blueprints_samples/helloworld_test_2.yaml"));
        return result;
    }

    public static List<Action> getAddNodesWithEdge() {
        List<Action> actions = getAddNodeActionsForRequest();
        Map<String,Object> payloadMap = new HashMap<String,Object>();

        Map<String,String> src = new HashMap<>();
        src.put("node", "comp1234");
        src.put("port", "DCAE-HELLO-WORLD-PUB-MR");

        Map<String,String> tgt = new HashMap<>();
        tgt.put("node", "comp5678");
        tgt.put("port", "DCAE-HELLO-WORLD-SUB-MR");

        Map<String,String> metadata = new HashMap<>();
        metadata.put("name","sample_topic_1");
        metadata.put("data_type","json");
        metadata.put("dmaap_type","MR");

        payloadMap.put("src",src);
        payloadMap.put("tgt",tgt);
        payloadMap.put("metadata",metadata);

        Action action = new Action();
        action.setCommand("addedge");
        action.setPayload(payloadMap);

        actions.add(action);
        System.out.println(action.getPayload().get("src"));

        return actions;
    }

    public static Map<String, String> prepareExpectedResultForAddEdge() {
        Map<String,String> result = new HashMap<>();
        result.put("hello-world-1_blueprint",loadFileContent("src/test/data/blueprints_samples/helloworld_test_1.yaml"));
        result.put("hello-world-2_blueprint",loadFileContent("src/test/data/blueprints_samples/helloworld_test_2.yaml"));
        return result;
    }
}