/*- * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= */ package org.onap.so.bpmn.common.scripts import static org.mockito.Mockito.* import org.camunda.bpm.engine.ProcessEngineServices import org.camunda.bpm.engine.RepositoryService import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity import org.camunda.bpm.engine.repository.ProcessDefinition import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.MockitoAnnotations import org.mockito.junit.MockitoJUnitRunner; import org.mockito.internal.debugging.MockitoDebuggerImpl import org.onap.so.bpmn.common.scripts.SDNCAdapter; import org.onap.so.bpmn.mock.FileUtil @RunWith(MockitoJUnitRunner.Silent.class) public class SDNCAdapterTest { @Before public void init() { MockitoAnnotations.initMocks(this) System.setProperty("jboss.qualified.host.name","myhost.com") } String workflowResponse = """ testRequestId 200 OK FK/VLXM/003717//SW_INTERNET service-configuration-operation activate synccomplete N Layer3ServiceActivateRequest SUPP 2015-04-28T21:32:11.386Z ds 8 Mbps 2001:1890:12e3:2da:: 2001:1890:12e3:2da:: 28 255.255.252.1 192.168.1.15 28 2001:1890:12e3:2da:: 2001:1890:12e3:2da:: 28 255.255.252.2 192.168.1.15 28 255.255.252.3 192.168.1.15 28 N Y N 192.168.1.7 192.168.1.8 1.1.1.1 28 192.168.1.5 2.2.2.1 192.168.1.6 192.155.2.3 1.1.1.2 28 192.168.1.6 2.2.2.2 192.168.1.7 192.155.2.4 Y 1:5 1:6 4:4 28 1:1 3:3 2:2 0:0 4:4 28 1:1 3:3 2:2 0:0 N Y 0.0.0.1 1 Y 1 1 0.0.0.2 2 Y 2 2 : 0 Y 3 3 : 1 Y 4 4 192.168.1.44 192.168.1.5 0 Y N 192.168.1.45 192.168.1.6 28 Y 0.0.0.0 0.0.0.0 0.0.0.0 0.0.0.1 0.0.0.1 0.0.0.1 primary 162.200.3.144 64 2001:1890:12e3:2da:: 2620:0:10d0:f:ffff:ffff:ffff:fffe 24 10.192.27.254 1 192.168.1.2 192.168.1.1 28 1 192.168.1.72 192.168.1.71 28 1 192.168.1.68 192.168.1.67 28 1 2001:1890:12e3:2da:: 2001:1890:12e3:2da:: 28 1 2001:1890:12e3:2da:: 2001:1890:12e3:3da:: 28 1 2001:1890:12e3:2da:: 2001:1890:12e3:4da:: 28 none AVPN 1 Active 2 Standby hostname activecode OOB 1 1 ZZ JUNIPER MODEL1 1 1 1 1 1 2 2 HY JUNIPER MODEL2 2 2 2 2 2 Layer3ServiceActivateRequest 4281555 155415ab-b4a7-4382-b4c6-d17d9sm42855 https://csi-tst-q22.it.com:22443/Services/com/cingular/csi/sdn/SendManagedNetworkStatusNotification.jws OMX 1 activate https://localhost:8443/adapters/rest/SDNCNotify 5b1f3c5d-cdf9-488d-8a4b-d3f1229d7760 MultiPoint MTSNJA4LCP1 AS/VLXM/003717//SW FK/VLXM/003717//SW_INTERNET ST E2E Test42855_1300004281555 SDN-ETHERNET-INTERNET 10 Kbps 1 192.168.1.15 192.168.1.15 28 2 192.168.1.16 192.168.1.16 28 1 2001:1890:12e3:2da:: 2001:1890:12e3:2da:: 28 1 2001:1890:12e3:2da:: 2001:1890:12e3:2da:: 28 """ String sdncAdapterRequest = """ 745b1b50-e39e-4685-9cc8-c71f0bde8bf0 query services/layer3-service-list/AS%2FVLXM%2F000199%2F%2FSB_INTERNET http://myhost.com:28080/mso/sdncAdapterCallbackServiceImpl 12570a36-7388-4c0a-bec4-189ce3kg9956 GetLayer3ServiceDetailsRequest OMX SDN-ETHERNET-INTERNET PD/VLXM/003717//SW_INTERNET """ String sdncAdapterResponse = """ 39542e39-ccc3-4d1a-8b79-04ce88526613 404 Error processing request to SDNC. Not Found. https://localhost:8443/restconf/config/L3SDN-API:services/layer3-service-list/MVM%2FVLXP%2F000855%2F%2FShakeout. SDNC Returned-[error-type:application, error-tag:data-missing, error-message:Request could not be completed because the relevant data model content does not exist.] """ String workflowErrorResponse = """ Received error from SDN-C: Error processing request to SDNC. Not Found. https://localhost:8443/restconf/config/L3SDN-API:services/layer3-service-list/MVM%2FVLXP%2F000855%2F%2FShakeout. SDNC Returned-[error-type:application, error-tag:data-missing, error-message:Request could not be completed because the relevant data model content does not exist.] 5300 404 """ String workflowErrorResponse1 = """ Invalid Callback Response from SDNC Adapter 5300 """ String enhancedCallbackRequestData = """ FK/VLXM/003717//SW_INTERNET service-configuration-operation activate synccomplete N Layer3ServiceActivateRequest SUPP 2015-04-28T21:32:11.386Z ds 8 Mbps 2001:1890:12e3:2da:: 2001:1890:12e3:2da:: 28 255.255.252.1 192.168.1.15 28 2001:1890:12e3:2da:: 2001:1890:12e3:2da:: 28 255.255.252.2 192.168.1.15 28 255.255.252.3 192.168.1.15 28 N Y N 192.168.1.7 192.168.1.8 1.1.1.1 28 192.168.1.5 2.2.2.1 192.168.1.6 192.155.2.3 1.1.1.2 28 192.168.1.6 2.2.2.2 192.168.1.7 192.155.2.4 Y 1:5 1:6 4:4 28 1:1 3:3 2:2 0:0 4:4 28 1:1 3:3 2:2 0:0 N Y 0.0.0.1 1 Y 1 1 0.0.0.2 2 Y 2 2 : 0 Y 3 3 : 1 Y 4 4 192.168.1.44 192.168.1.5 0 Y N 192.168.1.45 192.168.1.6 28 Y 0.0.0.0 0.0.0.0 0.0.0.0 0.0.0.1 0.0.0.1 0.0.0.1 primary 162.200.3.144 64 2001:1890:12e3:2da:: 2620:0:10d0:f:ffff:ffff:ffff:fffe 24 10.192.27.254 1 192.168.1.2 192.168.1.1 28 1 192.168.1.72 192.168.1.71 28 1 192.168.1.68 192.168.1.67 28 1 2001:1890:12e3:2da:: 2001:1890:12e3:2da:: 28 1 2001:1890:12e3:2da:: 2001:1890:12e3:3da:: 28 1 2001:1890:12e3:2da:: 2001:1890:12e3:4da:: 28 none AVPN 1 Active 2 Standby hostname activecode OOB 1 1 ZZ JUNIPER MODEL1 1 1 1 1 1 2 2 HY JUNIPER MODEL2 2 2 2 2 2 Layer3ServiceActivateRequest 4281555 155415ab-b4a7-4382-b4c6-d17d9sm42855 https://csi-tst-q22.it.com:22443/Services/com/cingular/csi/sdn/SendManagedNetworkStatusNotification.jws OMX 1 activate https://localhost:8443/adapters/rest/SDNCNotify 5b1f3c5d-cdf9-488d-8a4b-d3f1229d7760 MultiPoint MTSNJA4LCP1 AS/VLXM/003717//SW FK/VLXM/003717//SW_INTERNET ST E2E Test42855_1300004281555 SDN-ETHERNET-INTERNET 10 Kbps 1 192.168.1.15 192.168.1.15 28 2 192.168.1.16 192.168.1.16 28 1 2001:1890:12e3:2da:: 2001:1890:12e3:2da:: 28 1 2001:1890:12e3:2da:: 2001:1890:12e3:2da:: 28 """ def sdncAdapterResponseEmpty = """ """ def sdncAdapterResponseError = """ 39542e39-ccc3-4d1a-8b79-04ce88526613 404 Error processing request to SDNC. Not Found. https://localhost:8443/restconf/config/L3SDN-API:services/layer3-service-list/MVM%2FVLXP%2F000855%2F%2FShakeout. SDNC Returned-[error-type:application, error-tag:data-missing, error-message:Request could not be completed because the relevant data model content does not exist.] """ @Test public void testPreProcessRequest() { String sdncAdapterWorkflowRequest = FileUtil.readResourceFile("__files/SDN-ETHERNET-INTERNET/SDNCAdapterV1/sdncadapterworkflowrequest.xml"); ExecutionEntity mockExecution = mock(ExecutionEntity.class) when(mockExecution.getVariable("mso.adapters.po.auth")).thenReturn("5E12ACACBD552A415E081E29F2C4772F9835792A51C766CCFDD7433DB5220B59969CB2798C") when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7") when(mockExecution.getVariable("mso-request-id")).thenReturn("testReqId") when(mockExecution.getVariable("sdncAdapterWorkflowRequest")).thenReturn(sdncAdapterWorkflowRequest) when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://someurl.someting.com:28080/mso/sdncAdapterCallbackServiceImpl") when(mockExecution.getVariable("mso.use.qualified.host")).thenReturn("true") when(mockExecution.getProcessInstanceId()).thenReturn("745b1b50-e39e-4685-9cc8-c71f0bde8bf0") when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true") SDNCAdapter sdncAdapter = new SDNCAdapter() sdncAdapter.preProcessRequest(mockExecution) MockitoDebuggerImpl debugger = new MockitoDebuggerImpl() debugger.printInvocations(mockExecution) verify(mockExecution).setVariable("prefix","SDNCA_") verify(mockExecution).setVariable("sdncAdapterResponse","") verify(mockExecution).setVariable("asynchronousResponseTimeout",false) verify(mockExecution).setVariable("continueListening",false) verify(mockExecution).setVariable("serviceConfigActivate",false) verify(mockExecution).setVariable("SDNCA_SuccessIndicator",false) verify(mockExecution).setVariable("SDNCA_InterimNotify",false) verify(mockExecution).setVariable("BasicAuthHeaderValue","Basic dGVzdDp0ZXN0") verify(mockExecution).setVariable("source","") verify(mockExecution).setVariable("SDNCA_requestId", "745b1b50-e39e-4685-9cc8-c71f0bde8bf0") verify(mockExecution).setVariable("sdncAdapterRequest", sdncAdapterRequest) } @Test public void testProcessResponse() { String sdncAdapterCallbackResponse = FileUtil.readResourceFile("__files/SDN-ETHERNET-INTERNET/SDNCAdapterV1mock/sdncadaptercallbackrequest.xml"); ExecutionEntity mockExecution = mock(ExecutionEntity.class) when(mockExecution.getVariable("sdncAdapterCallbackRequest")).thenReturn(sdncAdapterCallbackResponse) SDNCAdapter sdncAdapter = new SDNCAdapter() sdncAdapter.postProcessResponse(mockExecution) // MockitoDebuggerImpl debugger = new MockitoDebuggerImpl() // debugger.printInvocations(mockExecution) verify(mockExecution,times(2)).getVariable("sdncAdapterCallbackRequest") // verify(mockExecution).setVariable("enhancedCallbackRequestData",enhancedCallbackRequestData) verify(mockExecution).setVariable("sdncAdapterResponse",workflowResponse) verify(mockExecution).setVariable("continueListening",false) } @Test public void testProcessResponse_ErrorCase_404() { String sdncAdapterCallbackErrorResponse = FileUtil.readResourceFile("sdncadaptercallbackrequest_404CallBack.xml"); ExecutionEntity mockExecution = mock(ExecutionEntity.class) when(mockExecution.getVariable("sdncAdapterCallbackRequest")).thenReturn(sdncAdapterCallbackErrorResponse) SDNCAdapter sdncAdapter = new SDNCAdapter() sdncAdapter.postProcessResponse(mockExecution) verify(mockExecution,times(2)).getVariable("sdncAdapterCallbackRequest") verify(mockExecution).setVariable("sdncAdapterResponse", sdncAdapterResponseError) verify(mockExecution).setVariable("enhancedCallbackRequestData", "") verify(mockExecution).setVariable("continueListening",false) } @Test public void testProcessResponse_ErrorCase_InvalidCallback() { ExecutionEntity mockExecution = mock(ExecutionEntity.class) when(mockExecution.getVariable("sdncAdapterCallbackRequest")).thenReturn("

Service Unavailable

") SDNCAdapter sdncAdapter = new SDNCAdapter() sdncAdapter.postProcessResponse(mockExecution) verify(mockExecution,times(2)).getVariable("sdncAdapterCallbackRequest") verify(mockExecution).setVariable("sdncAdapterResponse", sdncAdapterResponseEmpty) verify(mockExecution).setVariable("enhancedCallbackRequestData", "") verify(mockExecution).setVariable("continueListening",false) } @Test public void postProcessResponse() { String SDNCAdapterCallbackRequest = """ 3bb02798-b344-4d28-9bca-1f029954d1c9 404 Error processing request to SDNC. Not Found. https://localhost:8443/restconf/config/L3SDN-API:services/layer3-service-list/85%2FCSIP%2F141203%2FPT_CSI9999998693. SDNC Returned-[error-type:application, error-tag:data-missing, error-message:Request could not be completed because the relevant data model content does not exist ] """ String sdncAdapterResponse = """ 3bb02798-b344-4d28-9bca-1f029954d1c9 404 Error processing request to SDNC. Not Found. https://localhost:8443/restconf/config/L3SDN-API:services/layer3-service-list/85%2FCSIP%2F141203%2FPT_CSI9999998693. SDNC Returned-[error-type:application, error-tag:data-missing, error-message:Request could not be completed because the relevant data model content does not exist ] """ ExecutionEntity mockExecution = mock(ExecutionEntity.class) when(mockExecution.getVariable("sdncAdapterCallbackRequest")).thenReturn(SDNCAdapterCallbackRequest) SDNCAdapter sdncAdapter = new SDNCAdapter() sdncAdapter.postProcessResponse(mockExecution) verify(mockExecution,times(2)).getVariable("sdncAdapterCallbackRequest") verify(mockExecution).setVariable("sdncAdapterResponse", sdncAdapterResponse) verify(mockExecution).setVariable("enhancedCallbackRequestData", "") verify(mockExecution).setVariable("continueListening",false) } }