Fix for Penetration test _ Session and cookie management
[vid.git] / vid-app-common / src / test / java / org / onap / vid / aai / AaiGetVnfResponseTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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
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.vid.aai;
22
23 import java.io.IOException;
24 import java.util.*;
25
26 import com.fasterxml.jackson.databind.ObjectMapper;
27
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.vid.aai.model.VnfResult;
31
32 import static org.hamcrest.CoreMatchers.is;
33 import static org.junit.Assert.*;
34
35 public class AaiGetVnfResponseTest {
36
37         private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
38
39         private static final String VNF_RESULT =
40                         "{\n" +
41                                         "       \"id\": \"1\",\n" +
42                                         "   \"nodetype\": \"testNodeType\",\n" +
43                                         "   \"url\": \"test/url\",\n" +
44                                         "   \"serviceProperties\": {},\n" +
45                                         "   \"relatedTo\": []\n" +
46                                         "}\n";
47
48         private static final String AAI_GET_VNF_RESPONSE_TEST = "{ \n" +
49                         "  \"results\": \n" +
50                         "  [\n" +
51                                         VNF_RESULT +
52                         "  ]\n" +
53                         "}";
54
55
56         private AaiGetVnfResponse aaiGetVnfResponse;
57         private VnfResult expectedVnfResult;
58         private List<VnfResult> expectedList;
59
60         @Before
61         public void setUp() throws IOException {
62                 expectedVnfResult = OBJECT_MAPPER.readValue(VNF_RESULT, VnfResult.class);
63                 expectedList = Collections.singletonList(expectedVnfResult);
64
65         }
66
67         @Test
68         public void shouldHaveProperSetters() {
69                 aaiGetVnfResponse = new AaiGetVnfResponse();
70                 aaiGetVnfResponse.setAdditionalProperty("key","value");
71                 aaiGetVnfResponse.setResults(expectedList);
72
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);
78         }
79
80         @Test
81         public void shouldProperlyConvertJsonToAiiGetVnfResponse() throws IOException {
82                 aaiGetVnfResponse = OBJECT_MAPPER.readValue(AAI_GET_VNF_RESPONSE_TEST, AaiGetVnfResponse.class);
83                 assertThat(aaiGetVnfResponse.getResults(), is(expectedList));
84         }
85
86         @Test
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");
93
94                 String expectedOutput = "AaiGetVnfResponse{" +
95                                 "results=" + expectedList +
96                                 ", additionalProperties="+expectedMap+"}";
97
98                 assertEquals(aaiGetVnfResponse.toString(), expectedOutput);
99         }
100
101         @Test
102         public void shouldAddAdditionalProperty(){
103                 aaiGetVnfResponse = new AaiGetVnfResponse();
104                 aaiGetVnfResponse.setAdditionalProperty("key", "value");
105                 assertTrue(aaiGetVnfResponse.getAdditionalProperties().containsKey("key"));
106         }
107 }