Merge "Reorder modifiers"
[so.git] / common / src / test / java / org / openecomp / mso / client / grm / ServiceEndPointRequestTest.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 static org.junit.Assert.assertEquals;
24 import java.util.ArrayList;
25 import java.util.List;
26 import org.junit.Test;
27 import org.openecomp.mso.client.grm.beans.OperationalInfo;
28 import org.openecomp.mso.client.grm.beans.Property;
29 import org.openecomp.mso.client.grm.beans.ServiceEndPoint;
30 import org.openecomp.mso.client.grm.beans.ServiceEndPointRequest;
31 import org.openecomp.mso.client.grm.beans.Version;
32
33 import com.fasterxml.jackson.databind.ObjectMapper;
34
35 public class ServiceEndPointRequestTest {
36
37         private ObjectMapper mapper = new ObjectMapper();
38         
39         @Test
40         public void testMarshall() throws Exception {
41                 
42                 String expected = 
43                                 "{\"serviceEndPoint\":{\"name\":\"TEST.ECOMP_PSL.Inventory\",\"version\":{\"major\":1,\"minor\":0,\"patch\":\"0\"}," +
44                                 "\"hostAddress\":\"127.0.0.1\",\"listenPort\":\"8080\",\"latitude\":\"37.7022\",\"longitude\":\"121.9358\"," + 
45                                 "\"contextPath\":\"/\",\"routeOffer\":\"TEST\",\"operationalInfo\":{\"createdBy\":\"edge\",\"updatedBy\":\"edge\"}," + 
46                                 "\"properties\":[{\"name\":\"Environment\",\"value\":\"TEST\"},{\"name\":\"cpfrun_cluster_name\"," + 
47                                 "\"value\":\"testcase_cluster_no_cluster\"}]},\"env\":\"DEV\"}";
48                 
49                 Version ver = new Version();
50                 ver.setMajor(1);
51                 ver.setMinor(0);
52                 ver.setPatch("0");
53                 
54                 ServiceEndPoint sep = new ServiceEndPoint();
55                 sep.setName("TEST.ECOMP_PSL.Inventory");
56                 sep.setVersion(ver);
57                 sep.setHostAddress("127.0.0.1");
58                 sep.setListenPort("8080");
59                 sep.setLatitude("37.7022");
60                 sep.setLongitude("121.9358");
61                 sep.setContextPath("/");
62                 sep.setRouteOffer("TEST");
63                 
64                 OperationalInfo operInfo = new OperationalInfo();
65                 operInfo.setCreatedBy("edge");
66                 operInfo.setUpdatedBy("edge");
67                 
68                 sep.setOperationalInfo(operInfo);
69                 
70                 Property prop1 = new Property();
71                 prop1.setName("Environment");
72                 prop1.setValue("TEST");
73                 
74                 Property prop2 = new Property();
75                 prop2.setName("cpfrun_cluster_name");
76                 prop2.setValue("testcase_cluster_no_cluster");
77                 
78                 List<Property> props = new ArrayList<Property>();
79                 props.add(prop1);
80                 props.add(prop2);
81                 
82                 sep.setProperties(props);
83
84                 ServiceEndPointRequest request = new ServiceEndPointRequest();
85                 request.setEnv("DEV");
86                 request.setServiceEndPoint(sep);
87                 
88                 assertEquals(expected, mapper.writeValueAsString(request));
89         }
90 }