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 static org.junit.Assert.*;
24 import static org.mockito.Mockito.*
26 import org.junit.Before
27 import org.junit.Ignore
29 import org.camunda.bpm.engine.delegate.BpmnError
30 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
31 import org.camunda.bpm.engine.delegate.DelegateExecution
32 import org.onap.so.bpmn.core.WorkflowException
33 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
35 import org.onap.so.bpmn.mock.FileUtil
37 public class SDNCAdapterUtilsTest {
40 private ExecutionEntity svcex
41 private WorkflowException wfex
42 private AbstractServiceTaskProcessor tp
44 private SDNCAdapterUtils utils
49 map = new HashMap<String,Object>()
50 svcex = mock(ExecutionEntity.class)
52 tp = new AbstractServiceTaskProcessor() {
54 public void preProcessRequest(DelegateExecution execution) {
57 utils = new SDNCAdapterUtils(tp)
59 // svcex gets its variables from "map"
60 when(svcex.getVariable(any())).thenAnswer(
62 return map.get(invocation.getArgumentAt(0, String.class)) })
64 // svcex puts its variables into "map"
65 when(svcex.setVariable(any(), any())).thenAnswer(
68 invocation.getArgumentAt(0, String.class),
69 invocation.getArgumentAt(1, String.class)) })
71 map.put("isDebugLogEnabled", "true")
72 map.put("prefix", "mypfx-")
73 map.put("testProcessKey", "mykey")
77 public void testValidateSDNCResponse_Success_NoCode() {
78 resp = """<no-response/>"""
80 utils.validateSDNCResponse(svcex, resp, wfex, true)
82 assertEquals(true, map.get("mypfx-sdncResponseSuccess"))
83 assertEquals("0", map.get("mypfx-sdncRequestDataResponseCode"))
84 assertFalse(map.containsKey("WorkflowException"))
88 public void testValidateSDNCResponse_200() {
89 utils.validateSDNCResponse(svcex, makeResp("200", "OK", ""), wfex, true)
91 assertEquals(true, map.get("mypfx-sdncResponseSuccess"))
92 assertEquals("200", map.get("mypfx-sdncRequestDataResponseCode"))
93 assertFalse(map.containsKey("WorkflowException"))
97 public void testValidateSDNCResponse_408() {
99 utils.validateSDNCResponse(svcex, makeResp("408", "failed", ""), wfex, true)
101 // this has been commented out as, currently, the code doesn't
102 // throw an exception in this case
103 // fail("missing exception")
105 } catch(BpmnError ex) {
109 assertEquals(false, map.get("mypfx-sdncResponseSuccess"))
110 assertEquals("408", map.get("mypfx-sdncRequestDataResponseCode"))
112 wfex = map.get("WorkflowException")
115 assertEquals(5320, wfex.getErrorCode())
116 assertEquals("Received error from SDN-C: failed", wfex.getErrorMessage())
120 public void testValidateSDNCResponse_408_200() {
122 utils.validateSDNCResponse(svcex, makeResp("408", "failed", makeReq("200", "ok")), wfex, true)
124 assertEquals(true , map.get("mypfx-sdncResponseSuccess"))
125 assertEquals("200", map.get("mypfx-sdncRequestDataResponseCode"))
126 assertFalse(map.containsKey("WorkflowException"))
130 public void testValidateSDNCResponse_408_200_WithEmbeddedLt() {
132 utils.validateSDNCResponse(svcex, makeResp("408", "failed", makeReq("200", "<success> message")), wfex, true)
134 assertEquals(true, map.get("mypfx-sdncResponseSuccess"))
135 assertEquals("200", map.get("mypfx-sdncRequestDataResponseCode"))
136 assertFalse(map.containsKey("WorkflowException"))
140 public void testUpdateHomingInfo() {
141 String actual = utils.updateHomingInfo(null, "AIC3.0")
143 assertEquals("<l2-homing-information><aic-version>AIC3.0</aic-version></l2-homing-information>", actual)
147 public void testUpdateHomingInfo2() {
148 String homingInfo = "<l2-homing-information><preferred-aic-clli>TESTCLLI</preferred-aic-clli></l2-homing-information>"
149 String actual = utils.updateHomingInfo(homingInfo, "AIC3.0")
151 assertEquals("<l2-homing-information><preferred-aic-clli>TESTCLLI</preferred-aic-clli><aic-version>AIC3.0</aic-version></l2-homing-information>", actual)
154 private String makeResp(String respcode, String respmsg, String reqdata) {
159 <sdncadapterworkflow:SDNCAdapterWorkflowResponse xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
160 xmlns:tag0="http://org.onap/workflow/sdnc/adapter/schema/v1"
161 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
162 <sdncadapterworkflow:response-data>
163 <tag0:CallbackHeader>
164 <tag0:RequestId>myreq</tag0:RequestId>
165 <tag0:ResponseCode>${MsoUtils.xmlEscape(rc)}</tag0:ResponseCode>
166 <tag0:ResponseMessage>${MsoUtils.xmlEscape(rm)}</tag0:ResponseMessage>
167 </tag0:CallbackHeader>
169 </sdncadapterworkflow:response-data>
170 </sdncadapterworkflow:SDNCAdapterWorkflowResponse>
175 private String makeReq(String respcode, String respmsg) {
180 <output xmlns="org:onap:sdnc:northbound:generic-resource">
181 <svc-request-id>8b46e36e-b44f-4085-9404-427be1bc8a3</svc-request-id>
182 <response-code>${MsoUtils.xmlEscape(rc)}</response-code>
183 <response-message>${MsoUtils.xmlEscape(rm)}</response-message>
184 <ack-final-indicator>Y</ack-final-indicator>
189 return """<tag0:RequestData xsi:type="xs:string">${MsoUtils.xmlEscape(output)}</tag0:RequestData>"""