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/web/Helper.java | 122 +++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 mod/runtimeapi/runtime-web/src/test/java/org/onap/dcae/runtime/web/Helper.java (limited to 'mod/runtimeapi/runtime-web/src/test/java/org/onap/dcae/runtime/web/Helper.java') diff --git a/mod/runtimeapi/runtime-web/src/test/java/org/onap/dcae/runtime/web/Helper.java b/mod/runtimeapi/runtime-web/src/test/java/org/onap/dcae/runtime/web/Helper.java new file mode 100644 index 0000000..52ccf0f --- /dev/null +++ b/mod/runtimeapi/runtime-web/src/test/java/org/onap/dcae/runtime/web/Helper.java @@ -0,0 +1,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 loadTestBlueprints() { + Map expectedBlueprints = new HashMap(); + 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 getAddNodeActionsForRequest() { + List actions = new ArrayList(); + Map payloadMap; + + Action action_1 = new Action(); + payloadMap = new HashMap(); + 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(); + 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 prepareExpectedResult() { + Map 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 getAddNodesWithEdge() { + List actions = getAddNodeActionsForRequest(); + Map payloadMap = new HashMap(); + + Map src = new HashMap<>(); + src.put("node", "comp1234"); + src.put("port", "DCAE-HELLO-WORLD-PUB-MR"); + + Map tgt = new HashMap<>(); + tgt.put("node", "comp5678"); + tgt.put("port", "DCAE-HELLO-WORLD-SUB-MR"); + + Map 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 prepareExpectedResultForAddEdge() { + Map 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; + } +} -- cgit 1.2.3-korg