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.openecomp.mso.bpmn.common.scripts
23 import org.junit.Assert
24 import org.junit.Ignore
25 import org.junit.runner.RunWith;
26 import org.mockito.runners.MockitoJUnitRunner;
30 import static org.mockito.Mockito.*
32 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
33 import org.junit.Before
34 import org.junit.runner.RunWith
35 import org.mockito.MockitoAnnotations
36 import org.mockito.internal.debugging.MockitoDebuggerImpl
37 import org.mockito.runners.MockitoJUnitRunner
38 import org.openecomp.mso.bpmn.common.scripts.CommonExceptionUtil;
39 @RunWith(MockitoJUnitRunner.class)
42 class CommonExceptionUtilTest {
44 def aotsFault ="""<n1:Fault xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:n1="http://csi.cingular.com/CSI/Namespaces/ATTOneTicketingSystem/InfrastructureCommon/Types/Public/SoapFault.xsd" xmlns:cer="http://csi.cingular.com/CSI/Namespaces/ATTOneTicketingSystem/InfrastructureCommon/Types/Public/ErrorResponse.xsd" xsi:schemaLocation="http://csi.cingular.com/CSI/Namespaces/ATTOneTicketingSystem/InfrastructureCommon/Types/Public/SoapFault.xsd SoapFault-CDM.xsd">
45 <n1:faultcode>xml:space</n1:faultcode>
46 <n1:faultstring>String</n1:faultstring>
47 <n1:faultactor>http://csi.att.com</n1:faultactor>
49 <n1:CSIApplicationException>
51 <cer:code>400</cer:code>
52 <cer:description>bad stuff</cer:description>
54 <cer:ServiceProviderEntity>
55 <cer:reportingServiceEntity>String</cer:reportingServiceEntity>
56 <cer:faultDate>*** ERROR ***</cer:faultDate>
57 <cer:faultSequenceNumber>String</cer:faultSequenceNumber>
58 <cer:faultLevel>String</cer:faultLevel>
59 <cer:faultCode>String</cer:faultCode>
60 <cer:faultDescription>String</cer:faultDescription>
61 <cer:ServiceProviderRawError>
62 <cer:code>String</cer:code>
63 <cer:description>String</cer:description>
65 <cer:code>String</cer:code>
66 <cer:description>String</cer:description>
67 <cer:origination>String</cer:origination>
68 <cer:severity>String</cer:severity>
70 </cer:ServiceProviderRawError>
71 </cer:ServiceProviderEntity>
72 </n1:CSIApplicationException>
73 <n1:CSIInternalException>
74 <cer:reportingServiceEntity>String</cer:reportingServiceEntity>
75 <cer:faultDate>*** ERROR ***</cer:faultDate>
76 <cer:faultSequenceNumber>String</cer:faultSequenceNumber>
77 <cer:faultLevel>String</cer:faultLevel>
78 <cer:faultCode>String</cer:faultCode>
79 <cer:faultDescription>String</cer:faultDescription>
80 <cer:cingularErrorCode>String</cer:cingularErrorCode>
81 <cer:cingularErrorDescription>String</cer:cingularErrorDescription>
82 <cer:cingularErrorCategory>String</cer:cingularErrorCategory>
83 </n1:CSIInternalException>
91 MockitoAnnotations.initMocks(this)
96 public void testMapAAIExceptionTCommonException() {
100 String restFault = """
104 <messageId>SVC3002</messageId>
105 <text>Error writing output performing %1 on %2 (msg=%3) (ec=%4)</text>
107 <variable>PUTcustomer</variable>
108 <variable>SubName01</variable>
109 <variable>Unexpected error reading/updating database:Adding this property for key [service-instance-id] and value [USSTU2CFCNC0101UJZZ01] violates a uniqueness constraint [service-instance-id]</variable>
110 <variable>ERR.5.4.5105</variable>
116 def errorString = """<requestError>
118 <messageId>SVC3002</messageId>
119 <text>Error writing output performing %1 on %2 (msg=%3) (ec=%4)</text>
121 <variable>PUTcustomer</variable>
122 <variable>SubName01</variable>
123 <variable>Unexpected error reading/updating database:Adding this property for key [service-instance-id] and value [USSTU2CFCNC0101UJZZ01] violates a uniqueness constraint [service-instance-id]</variable>
124 <variable>ERR.5.4.5105</variable>
127 </requestError>""" as String
131 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
133 CommonExceptionUtil util = new CommonExceptionUtil()
134 Assert.assertEquals(errorString, util.mapAAIExceptionTCommonException(restFault, mockExecution))
141 public void testBuildException() {
142 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
143 when(mockExecution.getVariable("prefix")).thenReturn("test_")
144 when(mockExecution.getVariable("test_ResponseCode")).thenReturn("400")
145 ArrayList msgVars = new ArrayList()
148 when(mockExecution.getVariable("test_errVariables")).thenReturn(msgVars)
151 CommonExceptionUtil util = new CommonExceptionUtil()
152 String msg = "Bad request"
153 String errorString = """<tns:requestError xmlns:tns="http://org.openecomp/mso/request/types/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://org.openecomp/mso/request/types/v1 MsoServiceInstanceTypesV1.xsd">
154 <tns:serviceException>
155 <tns:messageId>SVC2000</tns:messageId>
156 <tns:text>The following service error occurred: %1. Error code is %2.</tns:text>
157 <tns:variables>var1</tns:variables>
158 <tns:variables>var2</tns:variables>
159 </tns:serviceException>
160 </tns:requestError>"""
161 Assert.assertEquals(errorString, util.buildException(msg, mockExecution))
165 public void testMapAOTSExecptionToCommonException() {
166 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
167 when(mockExecution.getVariable("prefix")).thenReturn("test_")
168 when(mockExecution.getVariable("test_ResponseCode")).thenReturn("400")
170 CommonExceptionUtil util = new CommonExceptionUtil()
171 String errorString = """<tns:requestError xmlns:tns="http://org.openecomp/mso/request/types/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://org.openecomp/mso/request/types/v1 MsoServiceInstanceTypesV1.xsd">
172 <tns:serviceException>
173 <tns:messageId>SVC2000</tns:messageId>
174 <tns:text>The following service error occurred: %1. Error code is %2.</tns:text>
175 <tns:variables>Received error from AOTS: bad stuff</tns:variables>
176 <tns:variables>400</tns:variables>
177 </tns:serviceException>
178 </tns:requestError>"""
179 Assert.assertEquals(errorString, util.mapAOTSExecptionToCommonException(aotsFault, mockExecution))
184 public void testParseError() {
185 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
186 String errorString = "The following service error occurred: %1. Error code is %2."
187 ArrayList msgVars = new ArrayList()
190 when(mockExecution.getVariable("prefix")).thenReturn("test_")
191 when(mockExecution.getVariable("test_errTxt")).thenReturn(errorString)
192 when(mockExecution.getVariable("test_errVariables")).thenReturn(msgVars)
194 CommonExceptionUtil util = new CommonExceptionUtil()
196 Assert.assertEquals("The following service error occurred: var1. Error code is var2.", util.parseError(mockExecution))