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.junit.runner.RunWith
30 import org.camunda.bpm.engine.delegate.BpmnError
31 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
32 import org.camunda.bpm.engine.delegate.DelegateExecution
33 import org.onap.so.bpmn.core.WorkflowException
34 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
36 import org.onap.so.bpmn.mock.FileUtil
38 import org.mockito.junit.MockitoJUnitRunner;
40 @RunWith(MockitoJUnitRunner.Silent.class)
41 public class SDNCAdapterUtilsTest {
44 private ExecutionEntity svcex
45 private WorkflowException wfex
46 private AbstractServiceTaskProcessor tp
48 private SDNCAdapterUtils utils
53 map = new HashMap<String,Object>()
54 svcex = mock(ExecutionEntity.class)
56 tp = new AbstractServiceTaskProcessor() {
58 public void preProcessRequest(DelegateExecution execution) {
61 utils = new SDNCAdapterUtils(tp)
63 // svcex gets its variables from "map"
64 when(svcex.getVariable(any())).thenAnswer(
66 return map.get(invocation.getArgument(0)) })
68 // svcex puts its variables into "map"
69 when(svcex.setVariable(any(), any())).thenAnswer(
72 invocation.getArgument(0),
73 invocation.getArgument(1)) })
75 map.put("isDebugLogEnabled", "true")
76 map.put("prefix", "mypfx-")
77 map.put("testProcessKey", "mykey")
81 public void testValidateSDNCResponse_Success_NoCode() {
82 resp = """<no-response/>"""
84 utils.validateSDNCResponse(svcex, resp, wfex, true)
86 assertEquals(true, map.get("mypfx-sdncResponseSuccess"))
87 assertEquals("0", map.get("mypfx-sdncRequestDataResponseCode"))
88 assertFalse(map.containsKey("WorkflowException"))
92 public void testValidateSDNCResponse_200() {
93 utils.validateSDNCResponse(svcex, makeResp("200", "OK", ""), wfex, true)
95 assertEquals(true, map.get("mypfx-sdncResponseSuccess"))
96 assertEquals("200", map.get("mypfx-sdncRequestDataResponseCode"))
97 assertFalse(map.containsKey("WorkflowException"))
101 public void testValidateSDNCResponse_408() {
103 utils.validateSDNCResponse(svcex, makeResp("408", "failed", ""), wfex, true)
105 // this has been commented out as, currently, the code doesn't
106 // throw an exception in this case
107 // fail("missing exception")
109 } catch(BpmnError ex) {
113 assertEquals(false, map.get("mypfx-sdncResponseSuccess"))
114 assertEquals("408", map.get("mypfx-sdncRequestDataResponseCode"))
116 wfex = map.get("WorkflowException")
119 assertEquals(5320, wfex.getErrorCode())
120 assertEquals("Received error from SDN-C: failed", wfex.getErrorMessage())
124 public void testValidateSDNCResponse_408_200() {
126 utils.validateSDNCResponse(svcex, makeResp("408", "failed", makeReq("200", "ok")), wfex, true)
128 assertEquals(true , map.get("mypfx-sdncResponseSuccess"))
129 assertEquals("200", map.get("mypfx-sdncRequestDataResponseCode"))
130 assertFalse(map.containsKey("WorkflowException"))
134 public void testValidateSDNCResponse_408_200_WithEmbeddedLt() {
136 utils.validateSDNCResponse(svcex, makeResp("408", "failed", makeReq("200", "<success> message")), wfex, true)
138 assertEquals(true, map.get("mypfx-sdncResponseSuccess"))
139 assertEquals("200", map.get("mypfx-sdncRequestDataResponseCode"))
140 assertFalse(map.containsKey("WorkflowException"))
144 public void testUpdateHomingInfo() {
145 String actual = utils.updateHomingInfo(null, "AIC3.0")
147 assertEquals("<l2-homing-information><aic-version>AIC3.0</aic-version></l2-homing-information>", actual)
151 public void testUpdateHomingInfo2() {
152 String homingInfo = "<l2-homing-information><preferred-aic-clli>TESTCLLI</preferred-aic-clli></l2-homing-information>"
153 String actual = utils.updateHomingInfo(homingInfo, "AIC3.0")
155 assertEquals("<l2-homing-information><preferred-aic-clli>TESTCLLI</preferred-aic-clli><aic-version>AIC3.0</aic-version></l2-homing-information>", actual)
158 private String makeResp(String respcode, String respmsg, String reqdata) {
163 <sdncadapterworkflow:SDNCAdapterWorkflowResponse xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
164 xmlns:tag0="http://org.onap/workflow/sdnc/adapter/schema/v1"
165 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
166 <sdncadapterworkflow:response-data>
167 <tag0:CallbackHeader>
168 <tag0:RequestId>myreq</tag0:RequestId>
169 <tag0:ResponseCode>${MsoUtils.xmlEscape(rc)}</tag0:ResponseCode>
170 <tag0:ResponseMessage>${MsoUtils.xmlEscape(rm)}</tag0:ResponseMessage>
171 </tag0:CallbackHeader>
173 </sdncadapterworkflow:response-data>
174 </sdncadapterworkflow:SDNCAdapterWorkflowResponse>
179 private String makeReq(String respcode, String respmsg) {
184 <output xmlns="org:onap:sdnc:northbound:generic-resource">
185 <svc-request-id>8b46e36e-b44f-4085-9404-427be1bc8a3</svc-request-id>
186 <response-code>${MsoUtils.xmlEscape(rc)}</response-code>
187 <response-message>${MsoUtils.xmlEscape(rm)}</response-message>
188 <ack-final-indicator>Y</ack-final-indicator>
193 return """<tag0:RequestData xsi:type="xs:string">${MsoUtils.xmlEscape(output)}</tag0:RequestData>"""