Replaced all tabs with spaces in java and pom.xml
[so.git] / common / src / test / java / org / onap / so / client / grm / ServiceEndPointListTest.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.grm;
22
23 import java.io.File;
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;
31
32 public class ServiceEndPointListTest {
33
34     private ObjectMapper mapper = new ObjectMapper();
35
36     @Test
37     public void testUnmarshall() throws Exception {
38         String endpointsJson = getFileContentsAsString("__files/grm/endpoints.json");
39         ServiceEndPointList sel = mapper.readValue(endpointsJson, ServiceEndPointList.class);
40
41         List<ServiceEndPoint> list = sel.getServiceEndPointList();
42         ServiceEndPoint se = list.get(0);
43
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());
58     }
59
60     @Test
61     public void testUnmarshallServiceEndpointListStartsWithUppercase() throws Exception {
62         String endpointsJson = getFileContentsAsString("__files/grm/endpoints2.json");
63         ServiceEndPointList sel = mapper.readValue(endpointsJson, ServiceEndPointList.class);
64
65         List<ServiceEndPoint> list = sel.getServiceEndPointList();
66         ServiceEndPoint se = list.get(0);
67
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());
82     }
83
84     protected String getFileContentsAsString(String fileName) {
85
86         String content = "";
87         try {
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) {
92             e.printStackTrace();
93             System.out.println("Exception encountered reading " + fileName + ". Error: " + e.getMessage());
94         }
95         return content;
96     }
97 }