Deal the sonar issue.
[aai/esr-server.git] / esr-mgr / src / test / java / org / onap / aai / esr / wrapper / ThirdpartySdncWrapperTest.java
1 /**
2  * Copyright 2018 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 import java.util.ArrayList;
20 import java.util.List;
21 import javax.ws.rs.core.Response;
22 import org.junit.AfterClass;
23 import org.junit.Assert;
24 import org.junit.Before;
25 import org.junit.BeforeClass;
26 import org.junit.Test;
27 import org.onap.aai.esr.common.MsbConfig;
28 import org.onap.aai.esr.entity.rest.ThirdpartySdncRegisterInfo;
29 import org.onap.aai.esr.externalservice.aai.ExternalSystemProxy;
30 import org.onap.aai.esr.util.ExtsysUtil;
31
32 public class ThirdpartySdncWrapperTest {
33
34     private static ThirdpartySdncWrapper thirdpartySdncWrapper;
35     static {
36         MsbConfig.setMsbServerAddr("http://127.0.0.1:80");
37     }
38
39     @BeforeClass  
40     public static void beforeClass() {  
41         ExternalSystemProxy.isTest = true;
42     };  
43     
44     @AfterClass  
45     public static void afterClass() {  
46         ExternalSystemProxy.isTest = false;
47     };
48     
49     @Before
50     public void setUp() throws Exception {
51         thirdpartySdncWrapper = ThirdpartySdncWrapper.getInstance();
52     }
53
54     @Test
55     public void test_registerThirdpartySdnc() {
56         ThirdpartySdncRegisterInfo sdncRegisterInfo = new ThirdpartySdncRegisterInfo();
57         sdncRegisterInfo.setLocation("edge");
58         sdncRegisterInfo.setName("SDNC_TEST");
59         sdncRegisterInfo.setPassword("123987");
60         sdncRegisterInfo.setProductName("thirdparty SDNC");
61         sdncRegisterInfo.setProtocol("protocol");
62         sdncRegisterInfo.setThirdpartySdncId("123456");
63         sdncRegisterInfo.setType("SDNC");
64         sdncRegisterInfo.setUrl("http://ip:8000");
65         sdncRegisterInfo.setUserName("nancy");
66         sdncRegisterInfo.setVendor("zte");
67         sdncRegisterInfo.setVersion("v1");
68         Response response = thirdpartySdncWrapper.registerThirdpartySdnc(sdncRegisterInfo);
69         if (response != null) {
70             Assert.assertTrue(response.getStatus() == 200);
71         }
72     }
73
74     @Test
75     public void test_delThirdpartySdnc() {
76         Response response = thirdpartySdncWrapper.delThirdpartySdnc("123456");
77         if (response != null) {
78             Assert.assertTrue(response.getStatus() == 204);
79         }
80     }
81
82     @Test
83     public void test_queryThirdpartySdncById() {
84         ExtsysUtil extsysUtil = new ExtsysUtil();
85         ThirdpartySdncRegisterInfo sdncRegisterInfo = new ThirdpartySdncRegisterInfo();
86         sdncRegisterInfo.setLocation("edge");
87         sdncRegisterInfo.setName("SDNC_TEST");
88         sdncRegisterInfo.setPassword("123987");
89         sdncRegisterInfo.setProductName("thirdparty SDNC");
90         sdncRegisterInfo.setProtocol("protocol");
91         sdncRegisterInfo.setThirdpartySdncId("123456");
92         sdncRegisterInfo.setType("SDNC");
93         sdncRegisterInfo.setUrl("http://ip:8000");
94         sdncRegisterInfo.setUserName("nancy");
95         sdncRegisterInfo.setVendor("zte");
96         sdncRegisterInfo.setVersion("v1");
97         Response response = thirdpartySdncWrapper.queryThirdpartySdncById("123456");
98         if (response != null) {
99             Assert.assertTrue(response.getStatus() == 200);
100             assertEquals(extsysUtil.objectToString(sdncRegisterInfo), extsysUtil.objectToString(response.getEntity()));
101         }
102     }
103
104     @Test
105     public void test_queryThirdpartySdncList() {
106         ExtsysUtil extsysUtil = new ExtsysUtil();
107         List<ThirdpartySdncRegisterInfo> sdncList = new ArrayList<>();
108         ThirdpartySdncRegisterInfo sdncRegisterInfo = new ThirdpartySdncRegisterInfo();
109         sdncRegisterInfo.setLocation("edge");
110         sdncRegisterInfo.setName("SDNC_TEST");
111         sdncRegisterInfo.setPassword("123987");
112         sdncRegisterInfo.setProductName("thirdparty SDNC");
113         sdncRegisterInfo.setProtocol("protocol");
114         sdncRegisterInfo.setThirdpartySdncId("123456");
115         sdncRegisterInfo.setType("SDNC");
116         sdncRegisterInfo.setUrl("http://ip:8000");
117         sdncRegisterInfo.setUserName("nancy");
118         sdncRegisterInfo.setVendor("zte");
119         sdncRegisterInfo.setVersion("v1");
120         sdncList.add(sdncRegisterInfo);
121         Response response = thirdpartySdncWrapper.queryThirdpartySdncList();
122         if (response != null) {
123             Assert.assertTrue(response.getStatus() == 200);
124             assertEquals(extsysUtil.objectToString(sdncList), extsysUtil.objectToString(response.getEntity()));
125         }
126     }
127
128     @Test
129     public void test_updateThirdpartySdnc() {
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://ip: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     }
147 }