/*-
* ============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 = """testRequestId200OKFK/VLXM/003717//SW_INTERNETservice-configuration-operationactivatesynccompleteNLayer3ServiceActivateRequestSUPP2015-04-28T21:32:11.386Zds8Mbps2001:1890:12e3:2da::2001:1890:12e3:2da::28255.255.252.1192.168.1.15282001:1890:12e3:2da::2001:1890:12e3:2da::28255.255.252.2192.168.1.1528255.255.252.3192.168.1.1528NYN192.168.1.7192.168.1.81.1.1.128192.168.1.52.2.2.1192.168.1.6192.155.2.31.1.1.228192.168.1.62.2.2.2192.168.1.7192.155.2.4Y1:51:64:4281:13:32:20:04:4281:13:32:20:0NY0.0.0.11Y110.0.0.22Y22:0Y33:1Y44192.168.1.44192.168.1.50YN192.168.1.45192.168.1.628Y0.0.0.00.0.0.00.0.0.00.0.0.10.0.0.10.0.0.1primary162.200.3.144642001:1890:12e3:2da::2620:0:10d0:f:ffff:ffff:ffff:fffe2410.192.27.2541192.168.1.2192.168.1.1281192.168.1.72192.168.1.71281192.168.1.68192.168.1.672812001:1890:12e3:2da::2001:1890:12e3:2da::2812001:1890:12e3:2da::2001:1890:12e3:3da::2812001:1890:12e3:2da::2001:1890:12e3:4da::28noneAVPN1Active2StandbyhostnameactivecodeOOB11ZZJUNIPERMODEL11111122HYJUNIPERMODEL222222Layer3ServiceActivateRequest4281555155415ab-b4a7-4382-b4c6-d17d9sm42855https://csi-tst-q22.it.com:22443/Services/com/cingular/csi/sdn/SendManagedNetworkStatusNotification.jwsOMX1activatehttps://localhost:8443/adapters/rest/SDNCNotify5b1f3c5d-cdf9-488d-8a4b-d3f1229d7760MultiPointMTSNJA4LCP1AS/VLXM/003717//SWFK/VLXM/003717//SW_INTERNETST E2E Test42855_1300004281555SDN-ETHERNET-INTERNET10Kbps1192.168.1.15192.168.1.15282192.168.1.16192.168.1.162812001:1890:12e3:2da::2001:1890:12e3:2da::2812001:1890:12e3:2da::2001:1890:12e3:2da::28"""
String sdncAdapterRequest = """
745b1b50-e39e-4685-9cc8-c71f0bde8bf0queryservices/layer3-service-list/AS%2FVLXM%2F000199%2F%2FSB_INTERNEThttp://myhost.com:28080/mso/sdncAdapterCallbackServiceImpl12570a36-7388-4c0a-bec4-189ce3kg9956GetLayer3ServiceDetailsRequestOMXSDN-ETHERNET-INTERNETPD/VLXM/003717//SW_INTERNET"""
String sdncAdapterResponse = """39542e39-ccc3-4d1a-8b79-04ce88526613404Error 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.]5300404"""
String workflowErrorResponse1 = """Invalid Callback Response from SDNC Adapter5300"""
String enhancedCallbackRequestData =
"""FK/VLXM/003717//SW_INTERNETservice-configuration-operationactivatesynccompleteNLayer3ServiceActivateRequestSUPP2015-04-28T21:32:11.386Zds8Mbps2001:1890:12e3:2da::2001:1890:12e3:2da::28255.255.252.1192.168.1.15282001:1890:12e3:2da::2001:1890:12e3:2da::28255.255.252.2192.168.1.1528255.255.252.3192.168.1.1528NYN192.168.1.7192.168.1.81.1.1.128192.168.1.52.2.2.1192.168.1.6192.155.2.31.1.1.228192.168.1.62.2.2.2192.168.1.7192.155.2.4Y1:51:64:4281:13:32:20:04:4281:13:32:20:0NY0.0.0.11Y110.0.0.22Y22:0Y33:1Y44192.168.1.44192.168.1.50YN192.168.1.45192.168.1.628Y0.0.0.00.0.0.00.0.0.00.0.0.10.0.0.10.0.0.1primary162.200.3.144642001:1890:12e3:2da::2620:0:10d0:f:ffff:ffff:ffff:fffe2410.192.27.2541192.168.1.2192.168.1.1281192.168.1.72192.168.1.71281192.168.1.68192.168.1.672812001:1890:12e3:2da::2001:1890:12e3:2da::2812001:1890:12e3:2da::2001:1890:12e3:3da::2812001:1890:12e3:2da::2001:1890:12e3:4da::28noneAVPN1Active2StandbyhostnameactivecodeOOB11ZZJUNIPERMODEL11111122HYJUNIPERMODEL222222Layer3ServiceActivateRequest4281555155415ab-b4a7-4382-b4c6-d17d9sm42855https://csi-tst-q22.it.com:22443/Services/com/cingular/csi/sdn/SendManagedNetworkStatusNotification.jwsOMX1activatehttps://localhost:8443/adapters/rest/SDNCNotify5b1f3c5d-cdf9-488d-8a4b-d3f1229d7760MultiPointMTSNJA4LCP1AS/VLXM/003717//SWFK/VLXM/003717//SW_INTERNETST E2E Test42855_1300004281555SDN-ETHERNET-INTERNET10Kbps1192.168.1.15192.168.1.15282192.168.1.16192.168.1.162812001:1890:12e3:2da::2001:1890:12e3:2da::2812001:1890:12e3:2da::2001:1890:12e3:2da::28
"""
def sdncAdapterResponseEmpty =
""""""
def sdncAdapterResponseError =
"""39542e39-ccc3-4d1a-8b79-04ce88526613404Error 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-1f029954d1c9404Error 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-1f029954d1c9404Error 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)
}
}