1079bb48b36f02d05eda3c6f8c6bfaeff0685f5c
[so.git] / bpmn / MSOCommonBPMN / src / test / groovy / org / onap / so / bpmn / common / scripts / SDNCAdapterRestV1Test.groovy
1 /*- 
2  * ============LICENSE_START======================================================= 
3  * ONAP - SO 
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 
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0 
12  * 
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========================================================= 
19  */ 
20
21 package org.onap.so.bpmn.common.scripts
22
23 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
24 import org.junit.Before
25 import org.junit.Ignore
26 import org.junit.Test
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
33
34 import static org.mockito.Mockito.*
35
36 @RunWith(MockitoJUnitRunner.class)
37 public class SDNCAdapterRestV1Test {
38         
39         @Before
40         public void init()
41         {
42                 MockitoAnnotations.initMocks(this)
43         }
44
45         @Test
46         public void testPreProcessRequest() {
47                 // bpTimeout is empty and "mso.adapters.sdnc.timeout" is defined
48
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")
56
57                 when(mockExecution.getVariable("mso.adapters.sdnc.rest.endpoint")).thenReturn("http://localhost:18080/adapters/rest/v1/sdnc/")
58
59                 when(mockExecution.getVariable("mso.adapters.sdnc.timeout")).thenReturn("PT5M")
60
61                 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
62                 when(mockExecution.getVariable("testProcessKey")).thenReturn("testProcessKey")
63
64
65                 SDNCAdapterRestV1 sdncAdapterRestV1 = new SDNCAdapterRestV1()
66                 sdncAdapterRestV1.preProcessRequest(mockExecution)
67                 
68                 MockitoDebuggerImpl debugger = new MockitoDebuggerImpl()
69                 //debugger.printInvocations(mockExecution)
70
71
72                 verify(mockExecution).setVariable("prefix","SDNCREST_")
73
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")
79         }
80         
81         @Test
82         public void testPreProcessRequestGoodTimeout() {
83                 // bpTimeout is valid and "mso.adapters.sdnc.timeout" is undefined
84                 
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")
93
94                 when(mockExecution.getVariable("mso.adapters.sdnc.rest.endpoint")).thenReturn("http://localhost:18080/adapters/rest/v1/sdnc/")
95
96                 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
97                 when(mockExecution.getVariable("testProcessKey")).thenReturn("testProcessKey")
98
99
100                 SDNCAdapterRestV1 sdncAdapterRestV1 = new SDNCAdapterRestV1()
101                 sdncAdapterRestV1.preProcessRequest(mockExecution)
102                 
103                 MockitoDebuggerImpl debugger = new MockitoDebuggerImpl()
104                 //debugger.printInvocations(mockExecution)
105
106
107                 verify(mockExecution).setVariable("prefix","SDNCREST_")
108
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")
114         }
115
116         @Test
117         @Ignore
118         public void testPreProcessRequestBadTimeout() {
119                 // bpTimeout is invalid and "mso.adapters.sdnc.timeout" is undefined
120
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")
129
130                 when(mockExecution.getVariable("mso.adapters.sdnc.rest.endpoint")).thenReturn("http://localhost:18080/adapters/rest/v1/sdnc/")
131
132                 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
133                 when(mockExecution.getVariable("testProcessKey")).thenReturn("testProcessKey")
134
135
136                 SDNCAdapterRestV1 sdncAdapterRestV1 = new SDNCAdapterRestV1()
137                 sdncAdapterRestV1.preProcessRequest(mockExecution)
138                 
139                 MockitoDebuggerImpl debugger = new MockitoDebuggerImpl()
140                 //debugger.printInvocations(mockExecution)
141
142
143                 verify(mockExecution).setVariable("prefix","SDNCREST_")
144
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")
150         }
151 }