2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.openstack.beans;
23 import static org.assertj.core.api.Assertions.assertThat;
25 import com.woorea.openstack.heat.model.Stack;
26 import java.io.IOException;
27 import org.codehaus.jackson.JsonNode;
28 import org.codehaus.jackson.map.ObjectMapper;
29 import org.junit.Test;
31 public class StackInfoTest {
33 private static final String STACK_NAME = "stackNameTest";
34 private static final String STACK_STATUS = "CREATE_COMPLETE";
35 private static final String STACK_OUTPUT_KEY = "outputKeyTest";
36 private static final String STACK_OUTPUT_VALUE = "outputValueTest";
37 private static final String STACK_PARAM_KEY = "paramKeyTest";
38 private static final String STACK_PARAM_VALUE = "paramValueTest";
41 public void setStatusNotFoundWhenStackIsNull() {
42 StackInfo stackInfo = new StackInfo(null);
43 assertThat(stackInfo.getStatus()).isEqualTo(HeatStatus.NOTFOUND);
44 assertThat(stackInfo.getOutputs()).isEmpty();
45 assertThat(stackInfo.getParameters()).isEmpty();
49 public void createObjectWhenStackStatusIsNull() {
50 StackInfo stackInfo = new StackInfo(createStackWithStatus(null));
51 assertThat(stackInfo.getName()).isEqualTo(STACK_NAME);
52 assertThat(stackInfo.getOutputs()).isEmpty();
53 assertThat(stackInfo.getStatus()).isEqualTo(HeatStatus.INIT);
54 assertThat(stackInfo.getParameters()).hasSize(1).containsEntry(STACK_PARAM_KEY, STACK_PARAM_VALUE);
58 public void createObjectWhenStackStatusIsFound() {
59 StackInfo stackInfo = new StackInfo(createStackWithStatus(STACK_STATUS));
60 assertThat(stackInfo.getName()).isEqualTo(STACK_NAME);
61 assertThat(stackInfo.getOutputs()).isEmpty();
62 assertThat(stackInfo.getStatus()).isEqualTo(HeatStatus.CREATED);
63 assertThat(stackInfo.getParameters()).hasSize(1).containsEntry(STACK_PARAM_KEY, STACK_PARAM_VALUE);
67 public void createObjectWhenStackStatusIsUnknown() {
68 StackInfo stackInfo = new StackInfo(createStackWithStatus("unknownStatus"));
69 assertThat(stackInfo.getName()).isEqualTo(STACK_NAME);
70 assertThat(stackInfo.getOutputs()).isEmpty();
71 assertThat(stackInfo.getStatus()).isEqualTo(HeatStatus.UNKNOWN);
72 assertThat(stackInfo.getParameters()).hasSize(1).containsEntry(STACK_PARAM_KEY, STACK_PARAM_VALUE);
76 public void createStackWhenOutputsListIsNotNull() throws IOException {
77 StackInfo stackInfo = new StackInfo(createStackWithOutputs());
78 assertThat(stackInfo.getOutputs()).isNotEmpty().hasSize(1);
79 assertThat(stackInfo.getOutputs()).hasSize(1).containsEntry(STACK_OUTPUT_KEY, STACK_OUTPUT_VALUE);
82 private Stack createStackWithStatus(String stackStatus) {
83 Stack stack = new Stack();
84 stack.setStackName(STACK_NAME);
85 stack.setStackStatus(stackStatus);
86 stack.getParameters().put(STACK_PARAM_KEY, STACK_PARAM_VALUE);
90 private Stack createStackWithOutputs() throws IOException {
91 String json = "{\"outputs\":[{\"output_key\" : \"" + STACK_OUTPUT_KEY + "\", \"output_value\" : \""
92 + STACK_OUTPUT_VALUE + "\" }]}";
93 JsonNode node = new ObjectMapper().readTree(json);
94 Stack stack = new ObjectMapper().readValue(node, Stack.class);