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