2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
24 package org.onap.clamp.loop;
26 import static org.assertj.core.api.Assertions.assertThat;
28 import com.google.gson.Gson;
29 import com.google.gson.JsonObject;
31 import java.io.IOException;
32 import java.util.HashSet;
34 import org.junit.Test;
35 import org.onap.clamp.clds.model.dcae.DcaeOperationStatusResponse;
36 import org.onap.clamp.loop.components.external.DcaeComponent;
37 import org.onap.clamp.policy.microservice.MicroServicePolicy;
39 public class DcaeComponentTest {
41 private Loop createTestLoop() {
42 String yaml = "imports:\n" + " - \"http://www.getcloudify.org/spec/cloudify/3.4/types.yaml\"\n"
43 + "node_templates:\n" + " docker_service_host:\n" + " type: dcae.nodes.SelectedDockerHost";
45 Loop loopTest = new Loop("ControlLoopTest", yaml, "<xml></xml>");
46 loopTest.setGlobalPropertiesJson(
47 new Gson().fromJson("{\"dcaeDeployParameters\":" + "{\"policy_id\": \"name\"}}", JsonObject.class));
48 loopTest.setLastComputedState(LoopState.DESIGN);
49 loopTest.setDcaeDeploymentId("123456789");
50 loopTest.setDcaeDeploymentStatusUrl("http4://localhost:8085");
51 loopTest.setDcaeBlueprintId("UUID-blueprint");
53 MicroServicePolicy microServicePolicy = new MicroServicePolicy("configPolicyTest", "",
54 "tosca_definitions_version: tosca_simple_yaml_1_0_0", true,
55 new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class), new HashSet<>());
56 microServicePolicy.setProperties(new Gson().fromJson("{\"param1\":\"value1\"}", JsonObject.class));
58 loopTest.addMicroServicePolicy(microServicePolicy);
63 public void convertDcaeResponseTest() throws IOException {
64 String dcaeFakeResponse = "{'requestId':'testId','operationType':'install','status':'state','error':'errorMessage', 'links':{'self':'selfUrl','uninstall':'uninstallUrl'}}";
65 DcaeOperationStatusResponse responseObject = DcaeComponent.convertDcaeResponse(dcaeFakeResponse);
66 assertThat(responseObject.getRequestId()).isEqualTo("testId");
67 assertThat(responseObject.getOperationType()).isEqualTo("install");
68 assertThat(responseObject.getStatus()).isEqualTo("state");
69 assertThat(responseObject.getError()).isEqualTo("errorMessage");
70 assertThat(responseObject.getLinks()).isNotNull();
71 assertThat(responseObject.getLinks().getSelf()).isEqualTo("selfUrl");
72 assertThat(responseObject.getLinks().getUninstall()).isEqualTo("uninstallUrl");
74 assertThat(responseObject.getLinks().getStatus()).isNull();
78 public void testGetDeployPayload() throws IOException {
79 Loop loop = this.createTestLoop();
80 String deploymentPayload = DcaeComponent.getDeployPayload(loop);
81 String expectedPayload = "{\"serviceTypeId\":\"UUID-blueprint\",\"inputs\":{\"policy_id\":\"name\"}}";
82 assertThat(deploymentPayload).isEqualTo(expectedPayload);
86 public void testGetUndeployPayload() throws IOException {
87 Loop loop = this.createTestLoop();
88 String unDeploymentPayload = DcaeComponent.getUndeployPayload(loop);
89 String expectedPayload = "{\"serviceTypeId\":\"UUID-blueprint\"}";
90 assertThat(unDeploymentPayload).isEqualTo(expectedPayload);