2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.common.scripts
23 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
24 import org.junit.Before
25 import org.junit.Ignore
27 import org.junit.runner.RunWith
28 import org.mockito.MockitoAnnotations
29 import org.mockito.internal.debugging.MockitoDebuggerImpl
30 import org.mockito.runners.MockitoJUnitRunner
31 import org.onap.so.bpmn.mock.FileUtil
32 import org.onap.so.bpmn.core.json.JsonUtils
34 import static org.mockito.Mockito.*
36 @RunWith(MockitoJUnitRunner.class)
37 public class SDNCAdapterRestV2Test {
42 MockitoAnnotations.initMocks(this)
46 public void testPreProcessRequest() {
47 // bpTimeout is empty and "mso.adapters.sdnc.timeout" is defined
49 String sdncAdapterWorkflowRequest = FileUtil.readResourceFile("__files/SDN-ETHERNET-INTERNET/SDNCAdapterRestV1/sdnc_request.json");
50 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
51 when(mockExecution.getVariable("prefix")).thenReturn("SDNCREST_")
52 when(mockExecution.getVariable("mso-request-id")).thenReturn("testMsoRequestId")
53 when(mockExecution.getVariable("SDNCREST_Request")).thenReturn(sdncAdapterWorkflowRequest)
54 when(mockExecution.getVariable("mso.adapters.po.auth")).thenReturn("3141634BF7E070AA289CF2892C986C0B")
55 when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7")
57 when(mockExecution.getVariable("mso.adapters.sdnc.rest.endpoint")).thenReturn("http://localhost:18080/adapters/rest/v1/sdnc/")
59 when(mockExecution.getVariable("mso.adapters.sdnc.timeout")).thenReturn("PT5M")
61 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
62 when(mockExecution.getVariable("testProcessKey")).thenReturn("testProcessKey")
65 SDNCAdapterRestV2 sdncAdapterRestV2 = new SDNCAdapterRestV2()
66 sdncAdapterRestV2.preProcessRequest(mockExecution)
68 MockitoDebuggerImpl debugger = new MockitoDebuggerImpl()
69 //debugger.printInvocations(mockExecution)
72 verify(mockExecution).setVariable("prefix","SDNCREST_")
74 verify(mockExecution).setVariable("SDNCREST_SuccessIndicator",false)
75 verify(mockExecution).setVariable("SDNCREST_requestType","SDNCServiceRequest")
76 verify(mockExecution).setVariable("SDNCAResponse_CORRELATOR","0d883b7f-dd34-4e1b-9ed5-341d33052360-1511808197479")
77 verify(mockExecution).setVariable("SDNCREST_sdncAdapterMethod","POST")
78 verify(mockExecution).setVariable("SDNCREST_timeout","PT5M")
82 public void testPreProcessRequestGoodTimeout() {
83 // bpTimeout is valid and "mso.adapters.sdnc.timeout" is undefined
85 String sdncAdapterWorkflowRequest = FileUtil.readResourceFile("__files/SDN-ETHERNET-INTERNET/SDNCAdapterRestV1/sdnc_request.json");
86 sdncAdapterWorkflowRequest = JsonUtils.addJsonValue(sdncAdapterWorkflowRequest, "SDNCServiceRequest.bpTimeout", "PT20S")
87 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
88 when(mockExecution.getVariable("prefix")).thenReturn("SDNCREST_")
89 when(mockExecution.getVariable("mso-request-id")).thenReturn("testMsoRequestId")
90 when(mockExecution.getVariable("SDNCREST_Request")).thenReturn(sdncAdapterWorkflowRequest)
91 when(mockExecution.getVariable("mso.adapters.po.auth")).thenReturn("3141634BF7E070AA289CF2892C986C0B")
92 when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7")
94 when(mockExecution.getVariable("mso.adapters.sdnc.rest.endpoint")).thenReturn("http://localhost:18080/adapters/rest/v1/sdnc/")
96 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
97 when(mockExecution.getVariable("testProcessKey")).thenReturn("testProcessKey")
100 SDNCAdapterRestV2 sdncAdapterRestV2 = new SDNCAdapterRestV2()
101 sdncAdapterRestV2.preProcessRequest(mockExecution)
103 MockitoDebuggerImpl debugger = new MockitoDebuggerImpl()
104 //debugger.printInvocations(mockExecution)
107 verify(mockExecution).setVariable("prefix","SDNCREST_")
109 verify(mockExecution).setVariable("SDNCREST_SuccessIndicator",false)
110 verify(mockExecution).setVariable("SDNCREST_requestType","SDNCServiceRequest")
111 verify(mockExecution).setVariable("SDNCAResponse_CORRELATOR","0d883b7f-dd34-4e1b-9ed5-341d33052360-1511808197479")
112 verify(mockExecution).setVariable("SDNCREST_sdncAdapterMethod","POST")
113 verify(mockExecution).setVariable("SDNCREST_timeout","PT20S")
118 public void testPreProcessRequestBadTimeout() {
119 // bpTimeout is invalid and "mso.adapters.sdnc.timeout" is undefined
121 String sdncAdapterWorkflowRequest = FileUtil.readResourceFile("__files/SDN-ETHERNET-INTERNET/SDNCAdapterRestV1/sdnc_request.json");
122 sdncAdapterWorkflowRequest = JsonUtils.addJsonValue(sdncAdapterWorkflowRequest, "SDNCServiceRequest.bpTimeout", "badTimeout")
123 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
124 when(mockExecution.getVariable("prefix")).thenReturn("SDNCREST_")
125 when(mockExecution.getVariable("mso-request-id")).thenReturn("testMsoRequestId")
126 when(mockExecution.getVariable("SDNCREST_Request")).thenReturn(sdncAdapterWorkflowRequest)
127 when(mockExecution.getVariable("mso.adapters.po.auth")).thenReturn("3141634BF7E070AA289CF2892C986C0B")
128 when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7")
130 when(mockExecution.getVariable("mso.adapters.sdnc.rest.endpoint")).thenReturn("http://localhost:18080/adapters/rest/v1/sdnc/")
132 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
133 when(mockExecution.getVariable("testProcessKey")).thenReturn("testProcessKey")
136 SDNCAdapterRestV2 sdncAdapterRestV2 = new SDNCAdapterRestV2()
137 sdncAdapterRestV2.preProcessRequest(mockExecution)
139 MockitoDebuggerImpl debugger = new MockitoDebuggerImpl()
140 //debugger.printInvocations(mockExecution)
143 verify(mockExecution).setVariable("prefix","SDNCREST_")
145 verify(mockExecution).setVariable("SDNCREST_SuccessIndicator",false)
146 verify(mockExecution).setVariable("SDNCREST_requestType","SDNCServiceRequest")
147 verify(mockExecution).setVariable("SDNCAResponse_CORRELATOR","0d883b7f-dd34-4e1b-9ed5-341d33052360-1511808197479")
148 verify(mockExecution).setVariable("SDNCREST_sdncAdapterMethod","POST")
149 verify(mockExecution).setVariable("SDNCREST_timeout","PT10S")