Add the API of query PNF.
[aai/esr-server.git] / esr-mgr / src / test / java / org / onap / aai / esr / wrapper / PnfManagerWrapperTest.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 javax.ws.rs.core.Response;
20 import org.junit.Assert;
21 import org.junit.Test;
22 import org.mockito.Mockito;
23 import org.onap.aai.esr.common.MsbConfig;
24 import org.onap.aai.esr.entity.aai.Pnf;
25 import org.onap.aai.esr.entity.rest.PnfRegisterInfo;
26 import org.onap.aai.esr.exception.ExtsysException;
27 import org.onap.aai.esr.externalservice.aai.NetworkProxy;
28 import org.onap.aai.esr.util.ExtsysUtil;
29
30 public class PnfManagerWrapperTest {
31
32     static {
33         MsbConfig.setMsbServerAddr("http://127.0.0.1:80");
34     }
35
36     @Test
37     public void test_registerPnf() throws ExtsysException {
38         PnfRegisterInfo pnfRegisterInfo = new PnfRegisterInfo();
39         pnfRegisterInfo.setPnfId("pnf1");
40         pnfRegisterInfo.setUserLabel("PNF test");
41         pnfRegisterInfo.setSubnetId("subnetId1");
42         pnfRegisterInfo.setNeId("neId1");
43         pnfRegisterInfo.setManagementType("Test");
44         pnfRegisterInfo.setVendor("ZTE");
45         pnfRegisterInfo.setPnfdId("pnfdId1");
46         pnfRegisterInfo.setEmsId("emsId1");
47         pnfRegisterInfo.setLattitude("121.546");
48         pnfRegisterInfo.setLongitude("14.22");
49         NetworkProxy mockNetworkProxy = Mockito.mock(NetworkProxy.class);
50         Mockito.doNothing().when(mockNetworkProxy).registerPnf(Mockito.anyString(), (Pnf)Mockito.anyObject());
51         PnfManagerWrapper pnfManagerWrapper = new PnfManagerWrapper(mockNetworkProxy);
52         Response response = pnfManagerWrapper.registerPnf(pnfRegisterInfo);
53         if (response != null) {
54             Assert.assertTrue(response.getStatus() == 200);
55         }
56     }
57     
58     @Test
59     public void test_queryPnfById() throws ExtsysException {
60         ExtsysUtil extsysUtil = new ExtsysUtil();
61         PnfRegisterInfo pnfRegisterInfo = new PnfRegisterInfo();
62         pnfRegisterInfo.setPnfId("pnf1");
63         pnfRegisterInfo.setUserLabel("PNF test");
64         pnfRegisterInfo.setSubnetId("subnetId1");
65         pnfRegisterInfo.setNeId("neId1");
66         pnfRegisterInfo.setManagementType("Test");
67         pnfRegisterInfo.setVendor("ZTE");
68         pnfRegisterInfo.setPnfdId("pnfdId1");
69         pnfRegisterInfo.setEmsId("emsId1");
70         pnfRegisterInfo.setLattitude("121.546");
71         pnfRegisterInfo.setLongitude("14.22");
72         String PnfStr = "{\"pnf-name\": \"pnf1\","
73                 + "\"pnf-name2\": \"PNF test\","
74                 + "\"pnf-id\": \"subnetId1-neId1\","
75                 + "\"equip-type\": \"Test\","
76                 + "\"equip-vendor\": \"ZTE\","
77                 + "\"equip-model\": \"pnfdId1\","
78                 + "\"management-option\": \"emsId1\","
79                 + "\"in-maint\": false,"
80                 + "\"frame-id\": \"121.546-14.22\"}";
81         NetworkProxy mockNetworkProxy = Mockito.mock(NetworkProxy.class);
82         Mockito.when(mockNetworkProxy.queryPNF(Mockito.anyString())).thenReturn(PnfStr);
83         PnfManagerWrapper pnfManagerWrapper = new PnfManagerWrapper(mockNetworkProxy);
84         Response response = pnfManagerWrapper.queryPnfById("pnf1");
85         if (response != null) {
86             Assert.assertTrue(response.getStatus() == 200);
87             assertEquals(extsysUtil.objectToString(pnfRegisterInfo), extsysUtil.objectToString(response.getEntity()));
88         }
89     }
90 }