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.grm;
24 import java.nio.file.Files;
25 import java.util.List;
26 import static org.junit.Assert.*;
27 import org.junit.Test;
28 import org.onap.so.client.grm.beans.ServiceEndPoint;
29 import org.onap.so.client.grm.beans.ServiceEndPointList;
30 import com.fasterxml.jackson.databind.ObjectMapper;
32 public class ServiceEndPointListTest {
34 private ObjectMapper mapper = new ObjectMapper();
37 public void testUnmarshall() throws Exception {
38 String endpointsJson = getFileContentsAsString("__files/grm/endpoints.json");
39 ServiceEndPointList sel = mapper.readValue(endpointsJson, ServiceEndPointList.class);
41 List<ServiceEndPoint> list = sel.getServiceEndPointList();
42 ServiceEndPoint se = list.get(0);
44 assertEquals(3, list.size());
45 assertEquals("dummy.pod.ns.dummy-pod3", se.getName());
46 assertEquals(Integer.valueOf(1), Integer.valueOf(se.getVersion().getMajor()));
47 assertEquals(Integer.valueOf(0), Integer.valueOf(se.getVersion().getMinor()));
48 assertEquals(Integer.valueOf(0), Integer.valueOf(se.getVersion().getPatch()));
49 assertEquals("192.168.120.218", se.getHostAddress());
50 assertEquals("32004", se.getListenPort());
51 assertEquals("37.7022", se.getLatitude());
52 assertEquals("121.9358", se.getLongitude());
53 assertEquals("/", se.getContextPath());
54 assertEquals("edge", se.getOperationalInfo().getCreatedBy());
55 assertEquals("edge", se.getOperationalInfo().getUpdatedBy());
56 assertEquals("Environment", se.getProperties().get(0).getName());
57 assertEquals("DEV", se.getProperties().get(0).getValue());
61 public void testUnmarshallServiceEndpointListStartsWithUppercase() throws Exception {
62 String endpointsJson = getFileContentsAsString("__files/grm/endpoints2.json");
63 ServiceEndPointList sel = mapper.readValue(endpointsJson, ServiceEndPointList.class);
65 List<ServiceEndPoint> list = sel.getServiceEndPointList();
66 ServiceEndPoint se = list.get(0);
68 assertEquals(3, list.size());
69 assertEquals("dummy.pod.ns.dummy-pod3", se.getName());
70 assertEquals(Integer.valueOf(1), Integer.valueOf(se.getVersion().getMajor()));
71 assertEquals(Integer.valueOf(0), Integer.valueOf(se.getVersion().getMinor()));
72 assertEquals(Integer.valueOf(0), Integer.valueOf(se.getVersion().getPatch()));
73 assertEquals("192.168.120.218", se.getHostAddress());
74 assertEquals("32004", se.getListenPort());
75 assertEquals("37.7022", se.getLatitude());
76 assertEquals("121.9358", se.getLongitude());
77 assertEquals("/", se.getContextPath());
78 assertEquals("edge", se.getOperationalInfo().getCreatedBy());
79 assertEquals("edge", se.getOperationalInfo().getUpdatedBy());
80 assertEquals("Environment", se.getProperties().get(0).getName());
81 assertEquals("DEV", se.getProperties().get(0).getValue());
84 protected String getFileContentsAsString(String fileName) {
88 ClassLoader classLoader = this.getClass().getClassLoader();
89 File file = new File(classLoader.getResource(fileName).getFile());
90 content = new String(Files.readAllBytes(file.toPath()));
91 } catch (Exception e) {
93 System.out.println("Exception encountered reading " + fileName + ". Error: " + e.getMessage());