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.client.aai.entities;
23 import static org.junit.Assert.*;
25 import java.io.IOException;
26 import java.nio.file.Files;
27 import java.nio.file.Paths;
28 import java.util.HashMap;
30 import java.util.Optional;
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;
43 @RunWith(MockitoJUnitRunner.class)
44 public class AAIResultWrapperTest {
47 AAIResultWrapper aaiResultWrapper;
48 AAIResultWrapper aaiResultWrapperEmpty;
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")));
55 aaiResultWrapper = new AAIResultWrapper(json);
56 aaiResultWrapperEmpty = new AAIResultWrapper("{}");
60 public void testGetRelationshipsEmpty() {
61 Optional<Relationships> relationships = aaiResultWrapperEmpty.getRelationships();
62 assertEquals("Compare relationships", Optional.empty(), relationships);
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>>(){});
70 Map<String, Object> actual = aaiResultWrapper.asMap();
71 assertEquals(expected, actual);
75 public void testAsMapEmpty() {
76 Map<String, Object> actual = aaiResultWrapperEmpty.asMap();
77 assertEquals(new HashMap<>(), actual);
81 public void nullCases() {
83 AAIResultWrapper wrapper = new AAIResultWrapper(null);
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());