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