2 * ============LICENSE_START========================================================================
3 * ONAP : tr-069-adapter
4 * =================================================================================================
5 * Copyright (C) 2020 CommScope Inc Intellectual Property.
6 * =================================================================================================
7 * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You
9 * may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14 * either express or implied. See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ===============LICENSE_END=======================================================================
19 package org.commscope.tr069adapter.mapper;
21 import static org.junit.Assert.assertFalse;
23 import java.util.ArrayList;
25 import java.util.concurrent.Semaphore;
27 import org.commscope.tr069adapter.acs.common.DeviceDetails;
28 import org.commscope.tr069adapter.acs.common.DeviceRPCResponse;
29 import org.commscope.tr069adapter.acs.common.OperationResponse;
30 import org.commscope.tr069adapter.acs.common.ParameterDTO;
31 import org.commscope.tr069adapter.mapper.acs.ACSRequestSender;
32 import org.commscope.tr069adapter.mapper.boot.MapperServiceBooter;
33 import org.commscope.tr069adapter.mapper.model.NetConfRequest;
34 import org.commscope.tr069adapter.mapper.model.NetConfResponse;
35 import org.commscope.tr069adapter.mapper.model.NetConfServerDetails;
36 import org.commscope.tr069adapter.mapper.netconf.controller.NetConfRequestReceiver;
37 import org.commscope.tr069adapter.mapper.sync.SynchronizedRequestHandler;
38 import org.junit.Assert;
39 import org.junit.Test;
40 import org.junit.runner.RunWith;
41 import org.mockito.Mockito;
42 import org.springframework.beans.factory.annotation.Autowired;
43 import org.springframework.boot.test.context.SpringBootTest;
44 import org.springframework.boot.test.mock.mockito.MockBean;
45 import org.springframework.test.context.junit4.SpringRunner;
47 @SpringBootTest(classes = {MapperServiceBooter.class})
48 @RunWith(SpringRunner.class)
49 public class NetConfRequestReceiverTest {
52 NetConfRequestReceiver receiver;
55 ACSRequestSender tr069RequestSender;
61 SynchronizedRequestHandler sync;
64 Map<Long, DeviceRPCResponse> opResultMap;
67 public void getConfigRequestTest() {
68 Mockito.when(tr069RequestSender.sendRequest(Mockito.anyObject())).thenReturn(10001L);
69 Mockito.when(sync.performDeviceOperation(Mockito.anyObject()))
70 .thenReturn(prepareDeviceResponseSucess());
72 NetConfRequest req = prepareNetConfRequest(
73 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><get-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><source><running /></source><filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\"><device xmlns=\"urn:onf:otcc:wireless:yang:radio-access-186\"><services><fap-service xmlns=\"urn:onf:otcc:wireless:yang:radio-access\"><index>1</index><cell-config><lte><epc/></lte></cell-config></fap-service></services></device></filter></get-config>");
74 NetConfResponse nfres = receiver.getConfigRequest(req);
75 Assert.assertEquals("0", nfres.getErrorCode().getFaultCode());
76 Assert.assertNotNull(nfres.getNetconfResponseXml());
80 public void getConfigRequestTestTimeOut() throws InterruptedException {
81 Mockito.when(tr069RequestSender.sendRequest(Mockito.anyObject())).thenReturn(10001L);
82 Mockito.when(semaphore.tryAcquire(Mockito.anyInt(), Mockito.anyObject())).thenReturn(true);
83 Mockito.when(opResultMap.remove(Mockito.anyLong())).thenReturn(prepareDeviceResponseSucess());
85 NetConfRequest req = prepareNetConfRequest(
86 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><get-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><source><running /></source><filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\"><device xmlns=\"urn:onf:otcc:wireless:yang:radio-access-186\"><services><fap-service xmlns=\"urn:onf:otcc:wireless:yang:radio-access\"><index>1</index><cell-config><lte><epc/></lte></cell-config></fap-service></services></device></filter></get-config>");
87 NetConfResponse nfres = receiver.getConfigRequest(req);
88 Assert.assertEquals("8006", nfres.getErrorCode().getFaultCode());
89 Assert.assertNull(nfres.getNetconfResponseXml());
90 Assert.assertEquals("Operation Timed out", nfres.getErrorCode().getErrorMessage());
94 public void getConfigRequestWithNoParamTest() {
95 NetConfRequest req = prepareNetConfRequest(
96 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><get-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><source><running /></source><filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\"></filter></get-config>");
97 NetConfResponse nfres = receiver.getConfigRequest(req);
98 Assert.assertNull(nfres.getNetconfResponseXml());
99 Assert.assertEquals("0", nfres.getErrorCode().getFaultCode());
104 public void getConfigRequestWithUnknownParamTest() {
105 NetConfRequest req = prepareNetConfRequest(
106 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><get-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><source><running /></source><filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\"><Intergateway xmlns=\"urn:onf:otcc:wireless:yang:radio-access-186\"><services><fap-service xmlns=\"urn:onf:otcc:wireless:yang:radio-access\"><index>1</index><cell-config><lte><epc/></lte></cell-config></fap-service></services></Intergateway></filter></get-config>");
107 NetConfResponse nfres = receiver.getRequest(req);
108 Assert.assertNull(nfres.getNetconfResponseXml());
109 Assert.assertEquals("0", nfres.getErrorCode().getFaultCode());
110 Assert.assertEquals("Success", nfres.getErrorCode().getErrorMessage());
114 public void getRequestTest() {
115 Mockito.when(tr069RequestSender.sendRequest(Mockito.anyObject())).thenReturn(10001L);
116 Mockito.when(sync.performDeviceOperation(Mockito.anyObject()))
117 .thenReturn(prepareDeviceResponseSucess());
118 NetConfRequest req = prepareNetConfRequest(
119 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><get xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><source><running /></source><filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\"><device xmlns=\"urn:onf:otcc:wireless:yang:radio-access-186\"><services><fap-service xmlns=\"urn:onf:otcc:wireless:yang:radio-access\"><index>1</index><cell-config><lte><epc/></lte></cell-config></fap-service></services></device></filter></get>");
120 NetConfResponse nfres = receiver.getRequest(req);
121 Assert.assertEquals("0", nfres.getErrorCode().getFaultCode());
122 Assert.assertNotNull(nfres.getNetconfResponseXml());
126 public void getRequestWithNoParamTest() {
127 NetConfRequest req = prepareNetConfRequest(
128 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><get xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><source><running /></source><filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\"></filter></get>");
129 NetConfResponse nfres = receiver.getRequest(req);
130 Assert.assertNull(nfres.getNetconfResponseXml());
131 Assert.assertEquals("0", nfres.getErrorCode().getFaultCode());
132 Assert.assertEquals("Success", nfres.getErrorCode().getErrorMessage());
136 public void getRequestWithUnknownParamTest() {
137 NetConfRequest req = prepareNetConfRequest(
138 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><get xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><source><running /></source><filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\"><Intergateway xmlns=\"urn:onf:otcc:wireless:yang:radio-access-186\"><services><fap-service xmlns=\"urn:onf:otcc:wireless:yang:radio-access\"><index>1</index><cell-config><lte><epc/></lte></cell-config></fap-service></services></Intergateway></filter></get>");
139 NetConfResponse nfres = receiver.getRequest(req);
140 Assert.assertNull(nfres.getNetconfResponseXml());
141 Assert.assertEquals("0", nfres.getErrorCode().getFaultCode());
142 Assert.assertEquals("Success", nfres.getErrorCode().getErrorMessage());
146 public void setConfigRequestTest() {
147 Mockito.when(tr069RequestSender.sendRequest(Mockito.anyObject())).thenReturn(10001L);
148 Mockito.when(sync.performDeviceOperation(Mockito.anyObject()))
149 .thenReturn(prepareSPVDeviceResponseSucess());
150 NetConfRequest req = prepareNetConfRequest(
151 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><edit-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><target><candidate/></target><config><device xmlns=\"urn:onf:otcc:wireless:yang:radio-access-186\"><services><fap-service xmlns=\"urn:onf:otcc:wireless:yang:radio-access\"><index>1</index><cell-config><lte><epc xmlns:a=\"urn:ietf:params:xml:ns:netconf:base:1.0\" a:operation=\"replace\"><plmn-list><index>1</index><plmnid>310767</plmnid><is-primary>false</is-primary><cell-reserved-for-operator-use>true</cell-reserved-for-operator-use><alias>cpe-131</alias><enable>true</enable></plmn-list></epc></lte></cell-config></fap-service></services></device></config></edit-config>");
152 NetConfResponse nfres = receiver.setConfigRequest(req);
153 Assert.assertNull(nfres.getNetconfResponseXml());
154 Assert.assertEquals("0", nfres.getErrorCode().getFaultCode());
155 Assert.assertEquals("Success", nfres.getErrorCode().getErrorMessage());
159 public void setConfigRequestWithErrorResTest() {
160 Mockito.when(tr069RequestSender.sendRequest(Mockito.anyObject())).thenReturn(10001L);
161 Mockito.when(sync.performDeviceOperation(Mockito.anyObject()))
162 .thenReturn(prepareDeviceResponseError());
163 NetConfRequest req = prepareNetConfRequest(
164 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><edit-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><target><candidate/></target><config><device xmlns=\"urn:onf:otcc:wireless:yang:radio-access-186\"><services><fap-service xmlns=\"urn:onf:otcc:wireless:yang:radio-access\"><index>1</index><cell-config><lte><epc xmlns:a=\"urn:ietf:params:xml:ns:netconf:base:1.0\" a:operation=\"replace\"><plmn-list><index>1</index><plmnid>310767</plmnid><is-primary>false</is-primary><cell-reserved-for-operator-use>true</cell-reserved-for-operator-use><alias>cpe-131</alias><enable>true</enable></plmn-list></epc></lte></cell-config></fap-service></services></device></config></edit-config>");
165 NetConfResponse nfres = receiver.setConfigRequest(req);
166 Assert.assertNull(nfres.getNetconfResponseXml());
167 Assert.assertEquals("9001", nfres.getErrorCode().getFaultCode());
168 Assert.assertEquals("Request denied", nfres.getErrorCode().getErrorMessage());
172 public void setConfigRequestWithNoParamTest() {
173 NetConfRequest req = prepareNetConfRequest(
174 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><edit-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><target><candidate/></target><config></config></edit-config>");
175 NetConfResponse nfres = receiver.setConfigRequest(req);
176 Assert.assertNull(nfres.getNetconfResponseXml());
177 Assert.assertEquals("0", nfres.getErrorCode().getFaultCode());
178 Assert.assertEquals("Success", nfres.getErrorCode().getErrorMessage());
182 public void setConfigRequestWithUnknowParatmerTest() {
183 NetConfRequest req = prepareNetConfRequest(
184 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><edit-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><target><candidate/></target><config><InternetGateway xmlns=\"urn:onf:otcc:wireless:yang:radio-access-186\"><services><fap-service xmlns=\"urn:onf:otcc:wireless:yang:radio-access\"><index>1</index><cell-config><lte><epc xmlns:a=\"urn:ietf:params:xml:ns:netconf:base:1.0\" a:operation=\"replace\"><plmn-list><index>1</index><plmnid>310767</plmnid><is-primary>false</is-primary><cell-reserved-for-operator-use>true</cell-reserved-for-operator-use><alias>cpe-131</alias><enable>true</enable></plmn-list></epc></lte></cell-config></fap-service></services></InternetGateway></config></edit-config>");
185 NetConfResponse nfres = receiver.setConfigRequest(req);
186 Assert.assertNull(nfres.getNetconfResponseXml());
187 Assert.assertEquals("0", nfres.getErrorCode().getFaultCode());
188 Assert.assertEquals("Success", nfres.getErrorCode().getErrorMessage());
192 public void setConfigRequestInvalidRequestXMLTest() {
193 NetConfRequest req = prepareNetConfRequest(
194 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><edit-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><target><candidate/></target><confg><device xmlns=\"urn:onf:otcc:wireless:yang:radio-access-186\"><services><fap-service xmlns=\"urn:onf:otcc:wireless:yang:radio-access\"><index>1</index><cell-config><lte><epc xmlns:a=\"urn:ietf:params:xml:ns:netconf:base:1.0\" a:operation=\"replace\"><plmn-list><index>1</index><plmnid>310767</plmnid><is-primary>false<is-primary><cell-reserved-for-operator-use>true<cell-reserved-for-operator-use><name>cpe-131</name><trust>true</trust></plmn-list></epc></lte></cell-config></fap-service></services></device></config></edit-config>");
195 NetConfResponse nfres = receiver.setConfigRequest(req);
196 Assert.assertNull(nfres.getNetconfResponseXml());
197 Assert.assertEquals("0", nfres.getErrorCode().getFaultCode());
201 public void delConfigRequestTest() {
202 Mockito.when(tr069RequestSender.sendRequest(Mockito.anyObject())).thenReturn(10001L);
203 Mockito.when(sync.performDeviceOperation(Mockito.anyObject()))
204 .thenReturn(prepareSPVDeviceResponseSucess());
205 NetConfRequest req = prepareNetConfRequest(
206 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><edit-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><target><candidate/></target><config><device xmlns=\"urn:onf:otcc:wireless:yang:radio-access-186\"><services><fap-service xmlns=\"urn:onf:otcc:wireless:yang:radio-access\"><index>1</index><cell-config><lte><epc xmlns:a=\"urn:ietf:params:xml:ns:netconf:base:1.0\" a:operation=\"replace\"><plmn-list><index>1</index><plmnid>310767</plmnid><is-primary>false</is-primary><cell-reserved-for-operator-use>true</cell-reserved-for-operator-use><name>cpe-131</name><trust>true</trust></plmn-list></epc></lte></cell-config></fap-service></services></device></config></edit-config>");
207 NetConfResponse nfres = receiver.delConfigRequest(req);
208 Assert.assertNull(nfres.getNetconfResponseXml());
209 Assert.assertEquals("0", nfres.getErrorCode().getFaultCode());
210 Assert.assertEquals("Success", nfres.getErrorCode().getErrorMessage());
214 public void delConfigwithUnknownParamterRequestTest() {
215 NetConfRequest req = prepareNetConfRequest(
216 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><edit-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><target><candidate/></target><config><InternetGateway xmlns=\"urn:onf:otcc:wireless:yang:radio-access-186\"><services><fap-service xmlns=\"urn:onf:otcc:wireless:yang:radio-access\"><index>1</index><cell-config><lte><epc xmlns:a=\"urn:ietf:params:xml:ns:netconf:base:1.0\" a:operation=\"replace\"><plmn-list><index>1</index><plmnid>310767</plmnid><is-primary>false</is-primary><cell-reserved-for-operator-use>true</cell-reserved-for-operator-use><name>cpe-131</name><trust>true</trust></plmn-list></epc></lte></cell-config></fap-service></services></InternetGateway></config></edit-config>");
217 NetConfResponse nfres = receiver.delConfigRequest(req);
218 Assert.assertNull(nfres.getNetconfResponseXml());
219 Assert.assertEquals("0", nfres.getErrorCode().getFaultCode());
220 Assert.assertEquals("Success", nfres.getErrorCode().getErrorMessage());
224 public void handelRegisterEventTest() {
227 .handelRegisterEvent(new NetConfServerDetails("00005BA1", "10.211.55.14", "17830")));
228 } catch (Exception e) {
233 private NetConfRequest prepareNetConfRequest(String requestXml) {
234 NetConfRequest req = new NetConfRequest();
235 req.setDeviceId("0005B9A1");
236 req.setRequestXml(requestXml);
237 req.setSwVersion("4.3.0.0");
238 req.setHwVersion("*");
242 private DeviceRPCResponse prepareDeviceResponseError() {
243 DeviceRPCResponse opResult = new DeviceRPCResponse();
244 opResult.setFaultKey("9001");
245 opResult.setFaultString("Request denied");
246 opResult.setDeviceDetails(new DeviceDetails());
247 OperationResponse opr = new OperationResponse();
248 // opr.setParameterDTOs(getGeneralParams());
249 opResult.setOperationResponse(opr);
253 private DeviceRPCResponse prepareDeviceResponseSucess() {
254 DeviceRPCResponse opResult = new DeviceRPCResponse();
255 opResult.setFaultKey("0");
256 opResult.setDeviceDetails(new DeviceDetails());
257 OperationResponse opr = new OperationResponse();
258 opr.setParameterDTOs(getGeneralParams());
259 opResult.setOperationResponse(opr);
263 private DeviceRPCResponse prepareSPVDeviceResponseSucess() {
264 DeviceRPCResponse opResult = new DeviceRPCResponse();
265 opResult.setFaultKey("0");
266 opResult.setDeviceDetails(new DeviceDetails());
267 OperationResponse opr = new OperationResponse();
268 opResult.setOperationResponse(opr);
272 private ArrayList<ParameterDTO> getGeneralParams() {
273 ArrayList<ParameterDTO> params = new ArrayList<>();
274 params.add(new ParameterDTO("Device.DeviceInfo.ManufacturerOUI", "0005B9"));
275 params.add(new ParameterDTO("Device.DeviceInfo.ProductClass", "LTE_Enterprise_C-RANSC_Cntrl"));
276 params.add(new ParameterDTO("Device.Services.FAPService.1.CellConfig.LTE.EPC.PLMNList.1.PLMNID",