[MSO-8] Update the maven dependency
[so.git] / bpmn / MSOCommonBPMN / src / test / groovy / org / openecomp / mso / bpmn / common / scripts / CommonExceptionUtilTest.groovy
1 /*- 
2  * ============LICENSE_START======================================================= 
3  * OPENECOMP - MSO 
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 
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0 
12  * 
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========================================================= 
19  */ 
20
21 package org.openecomp.mso.bpmn.common.scripts
22
23 import org.junit.Assert
24 import org.junit.Ignore
25 import org.junit.runner.RunWith;
26 import org.mockito.runners.MockitoJUnitRunner;
27
28
29
30 import static org.mockito.Mockito.*
31
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)
40 import org.junit.Test
41
42 class CommonExceptionUtilTest {
43         
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>
48         <n1:detail>
49                 <n1:CSIApplicationException>
50                         <cer:Response>
51                                 <cer:code>400</cer:code>
52                                 <cer:description>bad stuff</cer:description>
53                         </cer:Response>
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>
64                                         <cer:BISError>
65                                                 <cer:code>String</cer:code>
66                                                 <cer:description>String</cer:description>
67                                                 <cer:origination>String</cer:origination>
68                                                 <cer:severity>String</cer:severity>
69                                         </cer:BISError>
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>
84         </n1:detail>
85 </n1:Fault>"""
86
87         
88         @Before
89         public void init()
90         {
91                 MockitoAnnotations.initMocks(this)
92         }
93         
94         @Test
95         @Ignore
96         public void testMapAAIExceptionTCommonException() {
97                 
98                 
99                 
100                 String restFault = """
101                                 <Fault>
102 <requestError>
103 <serviceException>
104 <messageId>SVC3002</messageId>
105 <text>Error writing output performing %1 on %2 (msg=%3) (ec=%4)</text>
106 <variables>
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>
111 </variables>
112 </serviceException>
113 </requestError>
114 </Fault>
115                         """     
116                 def errorString = """<requestError>
117 <serviceException>
118 <messageId>SVC3002</messageId>
119 <text>Error writing output performing %1 on %2 (msg=%3) (ec=%4)</text>
120 <variables>
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>
125 </variables>
126 </serviceException>
127 </requestError>""" as String
128
129
130                         
131                 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
132
133                 CommonExceptionUtil util = new CommonExceptionUtil()
134                 Assert.assertEquals(errorString, util.mapAAIExceptionTCommonException(restFault, mockExecution))
135         }
136         
137         
138         
139         
140         @Test
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()
146                 msgVars.add("var1")
147                 msgVars.add("var2")
148                 when(mockExecution.getVariable("test_errVariables")).thenReturn(msgVars)
149
150                 
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))
162         }
163         
164         @Test
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")
169                 
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))
180         }
181         
182         
183         @Test
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()
188         msgVars.add("var1")
189         msgVars.add("var2")
190         when(mockExecution.getVariable("prefix")).thenReturn("test_")
191         when(mockExecution.getVariable("test_errTxt")).thenReturn(errorString)
192         when(mockExecution.getVariable("test_errVariables")).thenReturn(msgVars)
193                 
194         CommonExceptionUtil util = new CommonExceptionUtil()
195
196         Assert.assertEquals("The following service error occurred: var1. Error code is var2.", util.parseError(mockExecution))
197 }
198
199         
200         
201 }