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.onap.so.openstack.mappers;
23 import static org.junit.Assert.assertEquals;
24 import java.io.IOException;
25 import java.nio.file.Files;
26 import java.nio.file.Paths;
27 import java.util.HashMap;
29 import org.junit.Test;
30 import org.onap.so.openstack.beans.HeatStatus;
31 import org.onap.so.openstack.beans.StackInfo;
32 import com.fasterxml.jackson.core.JsonParseException;
33 import com.fasterxml.jackson.databind.JsonMappingException;
34 import com.fasterxml.jackson.databind.ObjectMapper;
35 import com.woorea.openstack.heat.model.Stack;
37 public class StackInfoMapperTest {
39 private static final String PATH = "src/test/resources/";
42 public void nullStack() {
43 StackInfoMapper mapper = new StackInfoMapper(null);
44 assertEquals(HeatStatus.NOTFOUND, mapper.map().getStatus());
48 public void checkHeatStatusMap() {
49 StackInfoMapper mapper = new StackInfoMapper(null);
50 assertEquals(HeatStatus.BUILDING, mapper.mapStatus("CREATE_IN_PROGRESS"));
51 assertEquals(HeatStatus.CREATED, mapper.mapStatus("CREATE_COMPLETE"));
52 assertEquals(HeatStatus.FAILED, mapper.mapStatus("CREATE_FAILED"));
53 assertEquals(HeatStatus.DELETING, mapper.mapStatus("DELETE_IN_PROGRESS"));
54 assertEquals(HeatStatus.NOTFOUND, mapper.mapStatus("DELETE_COMPLETE"));
55 assertEquals(HeatStatus.FAILED, mapper.mapStatus("DELETE_FAILED"));
56 assertEquals(HeatStatus.UPDATING, mapper.mapStatus("UPDATE_IN_PROGRESS"));
57 assertEquals(HeatStatus.FAILED, mapper.mapStatus("UPDATE_FAILED"));
58 assertEquals(HeatStatus.UPDATED, mapper.mapStatus("UPDATE_COMPLETE"));
59 assertEquals(HeatStatus.INIT, mapper.mapStatus(null));
60 assertEquals(HeatStatus.UNKNOWN, mapper.mapStatus("status-not-there"));
64 public void checkOutputToMap() throws JsonParseException, JsonMappingException, IOException {
65 ObjectMapper jacksonMapper = new ObjectMapper();
66 Stack sample = jacksonMapper.readValue(this.getJson("stack-example.json"), Stack.class);
67 StackInfoMapper mapper = new StackInfoMapper(sample);
68 StackInfo result = mapper.map();
69 Map<String, Object> map = result.getOutputs();
70 assertEquals(true, map.containsKey("key2"));
71 assertEquals("value1", map.get("key1"));
75 public void mapRemainingFields() {
76 Stack stack = new Stack();
77 stack.setStackName("name");
79 stack.setStackStatusReason("message");
80 stack.setParameters(new HashMap<String, Object>());
81 StackInfoMapper mapper = new StackInfoMapper(stack);
82 StackInfo info = mapper.map();
83 assertEquals("name", info.getName());
84 assertEquals("name/id", info.getCanonicalName());
85 assertEquals("message", info.getStatusMessage());
86 assertEquals(stack.getParameters(), info.getParameters());
89 private String getJson(String filename) throws IOException {
90 return new String(Files.readAllBytes(Paths.get(PATH + filename)));