2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 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.vid.aai;
23 import java.io.IOException;
26 import com.fasterxml.jackson.databind.ObjectMapper;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.vid.aai.model.VnfResult;
32 import static org.hamcrest.CoreMatchers.is;
33 import static org.junit.Assert.*;
35 public class AaiGetVnfResponseTest {
37 private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
39 private static final String VNF_RESULT =
42 " \"nodetype\": \"testNodeType\",\n" +
43 " \"url\": \"test/url\",\n" +
44 " \"serviceProperties\": {},\n" +
45 " \"relatedTo\": []\n" +
48 private static final String AAI_GET_VNF_RESPONSE_TEST = "{ \n" +
56 private AaiGetVnfResponse aaiGetVnfResponse;
57 private VnfResult expectedVnfResult;
58 private List<VnfResult> expectedList;
61 public void setUp() throws IOException {
62 expectedVnfResult = OBJECT_MAPPER.readValue(VNF_RESULT, VnfResult.class);
63 expectedList = Collections.singletonList(expectedVnfResult);
68 public void shouldHaveProperSetters() {
69 aaiGetVnfResponse = new AaiGetVnfResponse();
70 aaiGetVnfResponse.setAdditionalProperty("key","value");
71 aaiGetVnfResponse.setResults(expectedList);
73 assertEquals(aaiGetVnfResponse.getAdditionalProperties().size(), 1);
74 assertTrue(aaiGetVnfResponse.getAdditionalProperties().containsKey("key"));
75 assertTrue(aaiGetVnfResponse.getAdditionalProperties().containsValue("value"));
76 assertEquals(aaiGetVnfResponse.getResults().size(), 1);
77 assertEquals(aaiGetVnfResponse.getResults().get(0), expectedVnfResult);
81 public void shouldProperlyConvertJsonToAiiGetVnfResponse() throws IOException {
82 aaiGetVnfResponse = OBJECT_MAPPER.readValue(AAI_GET_VNF_RESPONSE_TEST, AaiGetVnfResponse.class);
83 assertThat(aaiGetVnfResponse.getResults(), is(expectedList));
87 public void shouldReturnProperToString(){
88 aaiGetVnfResponse = new AaiGetVnfResponse();
89 aaiGetVnfResponse.setAdditionalProperty("testKey","testValue");
90 aaiGetVnfResponse.setResults(expectedList);
91 Map<String,Object> expectedMap = new HashMap<>();
92 expectedMap.put("testKey", "testValue");
94 String expectedOutput = "AaiGetVnfResponse{" +
95 "results=" + expectedList +
96 ", additionalProperties="+expectedMap+"}";
98 assertEquals(aaiGetVnfResponse.toString(), expectedOutput);
102 public void shouldAddAdditionalProperty(){
103 aaiGetVnfResponse = new AaiGetVnfResponse();
104 aaiGetVnfResponse.setAdditionalProperty("key", "value");
105 assertTrue(aaiGetVnfResponse.getAdditionalProperties().containsKey("key"));