6afd179b87b4070d62a27b7788d7c9abb0996b05
[aai/esr-server.git] / esr-mgr / src / test / java / org / onap / aai / esr / wrapper / ThirdpartySdncWrapperTest.java
1 /**
2  * Copyright 2017 ZTE Corporation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.aai.esr.wrapper;
17
18 import static org.junit.Assert.assertEquals;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import javax.ws.rs.core.Response;
24
25 import org.junit.Assert;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.onap.aai.esr.common.MsbConfig;
29 import org.onap.aai.esr.entity.rest.ThirdpartySdncRegisterInfo;
30 import org.onap.aai.esr.externalservice.aai.ExternalSystemProxy;
31 import org.onap.aai.esr.util.ExtsysUtil;
32
33 public class ThirdpartySdncWrapperTest {
34
35   private static ThirdpartySdncWrapper thirdpartySdncWrapper;
36   static {
37     MsbConfig.setMsbServerAddr("http://127.0.0.1:80");
38   }
39   
40   @Before
41   public void setUp() throws Exception {
42     thirdpartySdncWrapper = ThirdpartySdncWrapper.getInstance();
43   }
44   
45   @Test
46   public void test_registerThirdpartySdnc() {
47     ExternalSystemProxy.isTest = true;
48     ThirdpartySdncRegisterInfo sdncRegisterInfo = new ThirdpartySdncRegisterInfo();
49     sdncRegisterInfo.setLocation("edge");
50     sdncRegisterInfo.setName("SDNC_TEST");
51     sdncRegisterInfo.setPassword("123987");
52     sdncRegisterInfo.setProductName("thirdparty SDNC");
53     sdncRegisterInfo.setProtocol("protocol");
54     sdncRegisterInfo.setThirdpartySdncId("123456");
55     sdncRegisterInfo.setType("SDNC");
56     sdncRegisterInfo.setUrl("http://127.0.0.1:8000");
57     sdncRegisterInfo.setUserName("nancy");
58     sdncRegisterInfo.setVendor("zte");
59     sdncRegisterInfo.setVersion("v1");
60     Response response = thirdpartySdncWrapper.registerThirdpartySdnc(sdncRegisterInfo);
61     if (response != null) {
62       Assert.assertTrue(response.getStatus() == 200);
63     }
64     ExternalSystemProxy.isTest = false;
65   }
66   
67   @Test
68   public void test_delThirdpartySdnc() {
69     ExternalSystemProxy.isTest = true;
70     Response response = thirdpartySdncWrapper.delThirdpartySdnc("123456");
71     if (response != null) {
72       Assert.assertTrue(response.getStatus() == 204);
73     }
74     ExternalSystemProxy.isTest = false;
75   }
76   
77   @Test
78   public void test_queryThirdpartySdncById() {
79     ExternalSystemProxy.isTest = true;
80     ExtsysUtil extsysUtil = new ExtsysUtil();
81     ThirdpartySdncRegisterInfo sdncRegisterInfo = new ThirdpartySdncRegisterInfo();
82     sdncRegisterInfo.setLocation("edge");
83     sdncRegisterInfo.setName("SDNC_TEST");
84     sdncRegisterInfo.setPassword("123987");
85     sdncRegisterInfo.setProductName("thirdparty SDNC");
86     sdncRegisterInfo.setProtocol("protocol");
87     sdncRegisterInfo.setThirdpartySdncId("123456");
88     sdncRegisterInfo.setType("SDNC");
89     sdncRegisterInfo.setUrl("http://127.0.0.1:8000");
90     sdncRegisterInfo.setUserName("nancy");
91     sdncRegisterInfo.setVendor("zte");
92     sdncRegisterInfo.setVersion("v1");
93     Response response = thirdpartySdncWrapper.queryThirdpartySdncById("123456");
94     if (response != null) {
95       Assert.assertTrue(response.getStatus() == 200);
96       assertEquals(extsysUtil.objectToString(sdncRegisterInfo), extsysUtil.objectToString(response.getEntity()));
97     }
98     ExternalSystemProxy.isTest = false;
99   }
100   
101   @Test
102   public void test_queryThirdpartySdncList() {
103     ExternalSystemProxy.isTest = true;
104     ExtsysUtil extsysUtil = new ExtsysUtil();
105     List<ThirdpartySdncRegisterInfo> sdncList = new ArrayList<>();
106     ThirdpartySdncRegisterInfo sdncRegisterInfo = new ThirdpartySdncRegisterInfo();
107     sdncRegisterInfo.setLocation("edge");
108     sdncRegisterInfo.setName("SDNC_TEST");
109     sdncRegisterInfo.setPassword("123987");
110     sdncRegisterInfo.setProductName("thirdparty SDNC");
111     sdncRegisterInfo.setProtocol("protocol");
112     sdncRegisterInfo.setThirdpartySdncId("123456");
113     sdncRegisterInfo.setType("SDNC");
114     sdncRegisterInfo.setUrl("http://127.0.0.1:8000");
115     sdncRegisterInfo.setUserName("nancy");
116     sdncRegisterInfo.setVendor("zte");
117     sdncRegisterInfo.setVersion("v1");
118     sdncList.add(sdncRegisterInfo);
119     Response response = thirdpartySdncWrapper.queryThirdpartySdncList();
120     if (response != null) {
121       Assert.assertTrue(response.getStatus() == 200);
122       assertEquals(extsysUtil.objectToString(sdncList), extsysUtil.objectToString(response.getEntity()));
123     }
124     ExternalSystemProxy.isTest = false;
125   }
126   
127   @Test
128   public void test_updateThirdpartySdnc() {
129     ExternalSystemProxy.isTest = true;
130     ThirdpartySdncRegisterInfo sdncRegisterInfo = new ThirdpartySdncRegisterInfo();
131     sdncRegisterInfo.setLocation("edge");
132     sdncRegisterInfo.setName("SDNC_TEST");
133     sdncRegisterInfo.setPassword("123987");
134     sdncRegisterInfo.setProductName("thirdparty SDNC");
135     sdncRegisterInfo.setProtocol("protocol");
136     sdncRegisterInfo.setThirdpartySdncId("123456");
137     sdncRegisterInfo.setType("SDNC");
138     sdncRegisterInfo.setUrl("http://127.0.0.1:8000");
139     sdncRegisterInfo.setUserName("nancy");
140     sdncRegisterInfo.setVendor("zte");
141     sdncRegisterInfo.setVersion("v1");
142     Response response = thirdpartySdncWrapper.updateThirdpartySdnc(sdncRegisterInfo, "123456");
143     if (response != null) {
144       Assert.assertTrue(response.getStatus() == 200);
145     }
146     ExternalSystemProxy.isTest = false;
147   }
148 }