AT&T 1712 and 1802 release code
[so.git] / common / src / test / java / org / openecomp / mso / 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.openecomp.mso.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.openecomp.mso.client.grm.beans.ServiceEndPoint;
29 import org.openecomp.mso.client.grm.beans.ServiceEndPointList;
30
31 import com.fasterxml.jackson.databind.ObjectMapper;
32
33 public class ServiceEndPointListTest {
34         
35         private ObjectMapper mapper = new ObjectMapper();
36         
37         @Test
38         public void testUnmarshall() throws Exception {
39                 String endpointsJson = getFileContentsAsString("__files/grm/endpoints.json");
40                 ServiceEndPointList sel = mapper.readValue(endpointsJson, ServiceEndPointList.class);
41                 
42                 List<ServiceEndPoint> list = sel.getServiceEndPointList();
43                 ServiceEndPoint se = list.get(0);
44                 
45                 assertEquals(3, list.size());
46                 assertEquals("dummy.pod.ns.dummy-pod3", se.getName());
47                 assertEquals(Integer.valueOf(1), Integer.valueOf(se.getVersion().getMajor()));
48                 assertEquals(Integer.valueOf(0), Integer.valueOf(se.getVersion().getMinor()));
49                 assertEquals(Integer.valueOf(0), Integer.valueOf(se.getVersion().getPatch()));
50                 assertEquals("135.144.120.218", se.getHostAddress());
51                 assertEquals("32004", se.getListenPort());
52                 assertEquals("37.7022", se.getLatitude());
53                 assertEquals("121.9358", se.getLongitude());
54                 assertEquals("/", se.getContextPath());
55                 assertEquals("edge", se.getOperationalInfo().getCreatedBy());
56                 assertEquals("edge", se.getOperationalInfo().getUpdatedBy());
57                 assertEquals("Environment", se.getProperties().get(0).getName());
58                 assertEquals("DEV", se.getProperties().get(0).getValue());
59         }
60         
61         protected String getFileContentsAsString(String fileName) {
62
63                 String content = "";
64                 try {
65                         ClassLoader classLoader = this.getClass().getClassLoader();
66                         File file = new File(classLoader.getResource(fileName).getFile());
67                         content = new String(Files.readAllBytes(file.toPath()));
68                 }
69                 catch(Exception e) {
70                         e.printStackTrace();
71                         System.out.println("Exception encountered reading " + fileName + ". Error: " + e.getMessage());
72                 }
73                 return content;
74         }
75 }