Containerization feature of SO
[so.git] / common / src / test / java / org / onap / so / client / aai / entities / AAIResultWrapperTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.client.aai.entities;
22
23 import static org.junit.Assert.*;
24
25 import java.io.IOException;
26 import java.nio.file.Files;
27 import java.nio.file.Paths;
28 import java.util.HashMap;
29 import java.util.Map;
30 import java.util.Optional;
31
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.mockito.runners.MockitoJUnitRunner;
36 import org.onap.aai.domain.yang.GenericVnf;
37 import org.onap.so.client.aai.AAICommonObjectMapperProvider;
38 import com.fasterxml.jackson.core.JsonParseException;
39 import com.fasterxml.jackson.core.type.TypeReference;
40 import com.fasterxml.jackson.databind.JsonMappingException;
41 import com.fasterxml.jackson.databind.ObjectMapper;
42
43 @RunWith(MockitoJUnitRunner.class) 
44 public class AAIResultWrapperTest {
45         String json;
46
47         AAIResultWrapper aaiResultWrapper;
48         AAIResultWrapper aaiResultWrapperEmpty;
49         
50         @Before
51         public void init() throws IOException {
52                 final String RESOURCE_PATH = "src/test/resources/__files/aai/resources/";
53                 json = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "e2e-complex.json")));
54                 
55                 aaiResultWrapper = new AAIResultWrapper(json);
56                 aaiResultWrapperEmpty = new AAIResultWrapper("{}");
57         }
58         
59         @Test
60         public void testGetRelationshipsEmpty() {
61                 Optional<Relationships> relationships = aaiResultWrapperEmpty.getRelationships();
62                 assertEquals("Compare relationships", Optional.empty(), relationships);
63         }
64
65         @Test
66         public void testAsMap() throws JsonParseException, JsonMappingException, IOException {
67                 ObjectMapper mapper = new AAICommonObjectMapperProvider().getMapper();
68                 Map<String, Object> expected = mapper.readValue(json, new TypeReference<Map<String, Object>>(){});
69                 
70                 Map<String, Object> actual = aaiResultWrapper.asMap();
71                 assertEquals(expected, actual);
72         }
73         
74         @Test
75         public void testAsMapEmpty() {
76                 Map<String, Object> actual = aaiResultWrapperEmpty.asMap();
77                 assertEquals(new HashMap<>(), actual);
78         }
79         
80         @Test
81         public void nullCases() {
82                 
83                 AAIResultWrapper wrapper = new AAIResultWrapper(null);
84                 
85                 assertEquals(Optional.empty(), wrapper.getRelationships());
86                 assertEquals("{}", wrapper.getJson());
87                 assertEquals(Optional.empty(), wrapper.asBean(GenericVnf.class));
88                 assertEquals(true, wrapper.asMap().isEmpty());
89                 assertEquals("{}", wrapper.toString());
90
91
92                 
93         }
94 }