2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.mso.bpmn.common.scripts;
\r
23 import static org.junit.Assert.*;
\r
24 import static org.mockito.Mockito.*
\r
26 import org.junit.Before
\r
27 import org.junit.Test
\r
28 import org.camunda.bpm.engine.delegate.BpmnError
\r
29 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
\r
30 import org.camunda.bpm.engine.runtime.Execution
\r
31 import org.openecomp.mso.bpmn.core.WorkflowException
\r
32 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
\r
34 import org.openecomp.mso.bpmn.mock.FileUtil
\r
36 public class SDNCAdapterUtilsTest {
\r
39 private ExecutionEntity svcex
\r
40 private WorkflowException wfex
\r
41 private AbstractServiceTaskProcessor tp
\r
43 private SDNCAdapterUtils utils
\r
48 map = new HashMap<String,Object>()
\r
49 svcex = mock(ExecutionEntity.class)
\r
51 tp = new AbstractServiceTaskProcessor() {
\r
53 public void preProcessRequest(Execution execution) {
\r
56 utils = new SDNCAdapterUtils(tp)
\r
58 // svcex gets its variables from "map"
\r
59 when(svcex.getVariable(any())).thenAnswer(
\r
61 return map.get(invocation.getArgumentAt(0, String.class)) })
\r
63 // svcex puts its variables into "map"
\r
64 when(svcex.setVariable(any(), any())).thenAnswer(
\r
67 invocation.getArgumentAt(0, String.class),
\r
68 invocation.getArgumentAt(1, String.class)) })
\r
70 map.put("isDebugLogEnabled", "true")
\r
71 map.put("prefix", "mypfx-")
\r
72 map.put("testProcessKey", "mykey")
\r
76 public void testValidateSDNCResponse_Success_NoCode() {
\r
77 resp = """<no-response/>"""
\r
79 utils.validateSDNCResponse(svcex, resp, wfex, true)
\r
81 assertEquals(true, map.get("mypfx-sdncResponseSuccess"))
\r
82 assertEquals("0", map.get("mypfx-sdncRequestDataResponseCode"))
\r
83 assertFalse(map.containsKey("WorkflowException"))
\r
87 public void testValidateSDNCResponse_200() {
\r
88 utils.validateSDNCResponse(svcex, makeResp("200", "OK", ""), wfex, true)
\r
90 assertEquals(true, map.get("mypfx-sdncResponseSuccess"))
\r
91 assertEquals("200", map.get("mypfx-sdncRequestDataResponseCode"))
\r
92 assertFalse(map.containsKey("WorkflowException"))
\r
96 public void testValidateSDNCResponse_408() {
\r
98 utils.validateSDNCResponse(svcex, makeResp("408", "failed", ""), wfex, true)
\r
100 // this has been commented out as, currently, the code doesn't
\r
101 // throw an exception in this case
\r
102 // fail("missing exception")
\r
104 } catch(BpmnError ex) {
\r
105 ex.printStackTrace()
\r
108 assertEquals(false, map.get("mypfx-sdncResponseSuccess"))
\r
109 assertEquals("408", map.get("mypfx-sdncRequestDataResponseCode"))
\r
111 wfex = map.get("WorkflowException")
\r
112 assertNotNull(wfex)
\r
114 assertEquals(5320, wfex.getErrorCode())
\r
115 assertEquals("Received error from SDN-C: failed", wfex.getErrorMessage())
\r
119 public void testValidateSDNCResponse_408_200() {
\r
121 utils.validateSDNCResponse(svcex, makeResp("408", "failed", makeReq("200", "ok")), wfex, true)
\r
123 assertEquals(true, map.get("mypfx-sdncResponseSuccess"))
\r
124 assertEquals("200", map.get("mypfx-sdncRequestDataResponseCode"))
\r
125 assertFalse(map.containsKey("WorkflowException"))
\r
129 public void testValidateSDNCResponse_408_200_WithEmbeddedLt() {
\r
131 utils.validateSDNCResponse(svcex, makeResp("408", "failed", makeReq("200", "<success> message")), wfex, true)
\r
133 assertEquals(true, map.get("mypfx-sdncResponseSuccess"))
\r
134 assertEquals("200", map.get("mypfx-sdncRequestDataResponseCode"))
\r
135 assertFalse(map.containsKey("WorkflowException"))
\r
139 private String makeResp(String respcode, String respmsg, String reqdata) {
\r
140 def rc = encodeXml(respcode)
\r
141 def rm = encodeXml(respmsg)
\r
144 <sdncadapterworkflow:SDNCAdapterWorkflowResponse xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
\r
145 xmlns:tag0="http://org.openecomp/workflow/sdnc/adapter/schema/v1"
\r
146 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
\r
147 <sdncadapterworkflow:response-data>
\r
148 <tag0:CallbackHeader>
\r
149 <tag0:RequestId>myreq</tag0:RequestId>
\r
150 <tag0:ResponseCode>${rc}</tag0:ResponseCode>
\r
151 <tag0:ResponseMessage>${rm}</tag0:ResponseMessage>
\r
152 </tag0:CallbackHeader>
\r
154 </sdncadapterworkflow:response-data>
\r
155 </sdncadapterworkflow:SDNCAdapterWorkflowResponse>
\r
160 private String makeReq(String respcode, String respmsg) {
\r
161 def rc = encodeXml(respcode)
\r
162 def rm = encodeXml(respmsg)
\r
165 <output xmlns="org:onap:sdnc:northbound:generic-resource">
\r
166 <svc-request-id>8b46e36e-b44f-4085-9404-427be1bc8a3</svc-request-id>
\r
167 <response-code>${rc}</response-code>
\r
168 <response-message>${rm}</response-message>
\r
169 <ack-final-indicator>Y</ack-final-indicator>
\r
172 output = encodeXml(output)
\r
174 return """<tag0:RequestData xsi:type="xs:string">${output}</tag0:RequestData>"""
\r
177 private String encodeXml(String txt) {
\r
178 return txt.replace("&", "&").replace("<", "<")
\r