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.Ignore
\r
28 import org.junit.Test
\r
29 import org.camunda.bpm.engine.delegate.BpmnError
\r
30 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
\r
31 import org.camunda.bpm.engine.delegate.DelegateExecution
\r
32 import org.openecomp.mso.bpmn.core.WorkflowException
\r
33 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
\r
35 import org.openecomp.mso.bpmn.mock.FileUtil
\r
37 public class SDNCAdapterUtilsTest {
\r
40 private ExecutionEntity svcex
\r
41 private WorkflowException wfex
\r
42 private AbstractServiceTaskProcessor tp
\r
44 private SDNCAdapterUtils utils
\r
49 map = new HashMap<String,Object>()
\r
50 svcex = mock(ExecutionEntity.class)
\r
52 tp = new AbstractServiceTaskProcessor() {
\r
54 public void preProcessRequest(DelegateExecution execution) {
\r
57 utils = new SDNCAdapterUtils(tp)
\r
59 // svcex gets its variables from "map"
\r
60 when(svcex.getVariable(any())).thenAnswer(
\r
62 return map.get(invocation.getArgumentAt(0, String.class)) })
\r
64 // svcex puts its variables into "map"
\r
65 when(svcex.setVariable(any(), any())).thenAnswer(
\r
68 invocation.getArgumentAt(0, String.class),
\r
69 invocation.getArgumentAt(1, String.class)) })
\r
71 map.put("isDebugLogEnabled", "true")
\r
72 map.put("prefix", "mypfx-")
\r
73 map.put("testProcessKey", "mykey")
\r
77 public void testValidateSDNCResponse_Success_NoCode() {
\r
78 resp = """<no-response/>"""
\r
80 utils.validateSDNCResponse(svcex, resp, wfex, true)
\r
82 assertEquals(true, map.get("mypfx-sdncResponseSuccess"))
\r
83 assertEquals("0", map.get("mypfx-sdncRequestDataResponseCode"))
\r
84 assertFalse(map.containsKey("WorkflowException"))
\r
88 public void testValidateSDNCResponse_200() {
\r
89 utils.validateSDNCResponse(svcex, makeResp("200", "OK", ""), wfex, true)
\r
91 assertEquals(true, map.get("mypfx-sdncResponseSuccess"))
\r
92 assertEquals("200", map.get("mypfx-sdncRequestDataResponseCode"))
\r
93 assertFalse(map.containsKey("WorkflowException"))
\r
97 public void testValidateSDNCResponse_408() {
\r
99 utils.validateSDNCResponse(svcex, makeResp("408", "failed", ""), wfex, true)
\r
101 // this has been commented out as, currently, the code doesn't
\r
102 // throw an exception in this case
\r
103 // fail("missing exception")
\r
105 } catch(BpmnError ex) {
\r
106 ex.printStackTrace()
\r
109 assertEquals(false, map.get("mypfx-sdncResponseSuccess"))
\r
110 assertEquals("408", map.get("mypfx-sdncRequestDataResponseCode"))
\r
112 wfex = map.get("WorkflowException")
\r
113 assertNotNull(wfex)
\r
115 assertEquals(5320, wfex.getErrorCode())
\r
116 assertEquals("Received error from SDN-C: failed", wfex.getErrorMessage())
\r
120 public void testValidateSDNCResponse_408_200() {
\r
122 utils.validateSDNCResponse(svcex, makeResp("408", "failed", makeReq("200", "ok")), wfex, true)
\r
124 assertEquals(true, map.get("mypfx-sdncResponseSuccess"))
\r
125 assertEquals("200", map.get("mypfx-sdncRequestDataResponseCode"))
\r
126 assertFalse(map.containsKey("WorkflowException"))
\r
129 @Ignore // 1802 merge
\r
131 public void testValidateSDNCResponse_408_200_WithEmbeddedLt() {
\r
133 utils.validateSDNCResponse(svcex, makeResp("408", "failed", makeReq("200", "<success> message")), wfex, true)
\r
135 assertEquals(true, map.get("mypfx-sdncResponseSuccess"))
\r
136 assertEquals("200", map.get("mypfx-sdncRequestDataResponseCode"))
\r
137 assertFalse(map.containsKey("WorkflowException"))
\r
141 public void testUpdateHomingInfo() {
\r
142 String actual = utils.updateHomingInfo(null, "AIC3.0")
\r
144 assertEquals("<l2-homing-information><aic-version>AIC3.0</aic-version></l2-homing-information>", actual)
\r
148 public void testUpdateHomingInfo2() {
\r
149 String homingInfo = "<l2-homing-information><preferred-aic-clli>TESTCLLI</preferred-aic-clli></l2-homing-information>"
\r
150 String actual = utils.updateHomingInfo(homingInfo, "AIC3.0")
\r
152 assertEquals("<l2-homing-information><preferred-aic-clli>TESTCLLI</preferred-aic-clli><aic-version>AIC3.0</aic-version></l2-homing-information>", actual)
\r
155 @Ignore // 1802 merge - testing method that doesn't exist
\r
157 public void testUpdateServiceInfo() {
\r
158 String actual = utils.updateServiceInfo(null, "96688f6f-ab06-4ef6-ae55-9d3af28ae909")
\r
160 assertEquals("<service-information><infra-service-instance-id>96688f6f-ab06-4ef6-ae55-9d3af28ae909</infra-service-instance-id></service-information>", actual)
\r
163 @Ignore // 1802 merge - testing method that doesn't exist
\r
165 public void testUpdateServiceInfo2() {
\r
166 String serviceInfo = "<service-information><service-type>SDN-ETHERNET-INTERNET</service-type><service-instance-id>MIS/1602/00029/SB_INTERNET</service-instance-id></service-information>"
\r
167 String actual = utils.updateServiceInfo(serviceInfo, "96688f6f-ab06-4ef6-ae55-9d3af28ae909")
\r
169 assertEquals("<service-information><service-type>SDN-ETHERNET-INTERNET</service-type><service-instance-id>MIS/1602/00029/SB_INTERNET</service-instance-id><infra-service-instance-id>96688f6f-ab06-4ef6-ae55-9d3af28ae909</infra-service-instance-id></service-information>", actual)
\r
172 private String makeResp(String respcode, String respmsg, String reqdata) {
\r
173 def rc = encodeXml(respcode)
\r
174 def rm = encodeXml(respmsg)
\r
177 <sdncadapterworkflow:SDNCAdapterWorkflowResponse xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
\r
178 xmlns:tag0="http://org.openecomp/workflow/sdnc/adapter/schema/v1"
\r
179 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
\r
180 <sdncadapterworkflow:response-data>
\r
181 <tag0:CallbackHeader>
\r
182 <tag0:RequestId>myreq</tag0:RequestId>
\r
183 <tag0:ResponseCode>${rc}</tag0:ResponseCode>
\r
184 <tag0:ResponseMessage>${rm}</tag0:ResponseMessage>
\r
185 </tag0:CallbackHeader>
\r
187 </sdncadapterworkflow:response-data>
\r
188 </sdncadapterworkflow:SDNCAdapterWorkflowResponse>
\r
193 private String makeReq(String respcode, String respmsg) {
\r
194 def rc = encodeXml(respcode)
\r
195 def rm = encodeXml(respmsg)
\r
198 <output xmlns="org:onap:sdnc:northbound:generic-resource">
\r
199 <svc-request-id>8b46e36e-b44f-4085-9404-427be1bc8a3</svc-request-id>
\r
200 <response-code>${rc}</response-code>
\r
201 <response-message>${rm}</response-message>
\r
202 <ack-final-indicator>Y</ack-final-indicator>
\r
205 output = encodeXml(output)
\r
207 return """<tag0:RequestData xsi:type="xs:string">${output}</tag0:RequestData>"""
\r
210 private String encodeXml(String txt) {
\r
211 return txt.replace("&", "&").replace("<", "<")
\r