aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/TrinityExceptionUtilTest.groovy
blob: b5259675696c9415017b34f9c7ef3e20d12d533d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*- 
 * ============LICENSE_START======================================================= 
 * OPENECOMP - MSO 
 * ================================================================================ 
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. 
 * ================================================================================ 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 * ============LICENSE_END========================================================= 
 */ 

package org.openecomp.mso.bpmn.common.scripts

import org.junit.Assert
import org.junit.Ignore
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;



import static org.mockito.Mockito.*

import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
import org.junit.Before
import org.junit.runner.RunWith
import org.mockito.MockitoAnnotations
import org.mockito.internal.debugging.MockitoDebuggerImpl
import org.mockito.runners.MockitoJUnitRunner
import org.openecomp.mso.bpmn.common.scripts.TrinityExceptionUtil;
@RunWith(MockitoJUnitRunner.class)
import org.junit.Test

class TrinityExceptionUtilTest {
	
	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">
	<n1:faultcode>xml:space</n1:faultcode>
	<n1:faultstring>String</n1:faultstring>
	<n1:faultactor>http://test.com</n1:faultactor>
	<n1:detail>
		<n1:CSIApplicationException>
			<cer:Response>
				<cer:code>400</cer:code>
				<cer:description>bad stuff</cer:description>
			</cer:Response>
			<cer:ServiceProviderEntity>
				<cer:reportingServiceEntity>String</cer:reportingServiceEntity>
				<cer:faultDate>*** ERROR ***</cer:faultDate>
				<cer:faultSequenceNumber>String</cer:faultSequenceNumber>
				<cer:faultLevel>String</cer:faultLevel>
				<cer:faultCode>String</cer:faultCode>
				<cer:faultDescription>String</cer:faultDescription>
				<cer:ServiceProviderRawError>
					<cer:code>String</cer:code>
					<cer:description>String</cer:description>
					<cer:BISError>
						<cer:code>String</cer:code>
						<cer:description>String</cer:description>
						<cer:origination>String</cer:origination>
						<cer:severity>String</cer:severity>
					</cer:BISError>
				</cer:ServiceProviderRawError>
			</cer:ServiceProviderEntity>
		</n1:CSIApplicationException>
		<n1:CSIInternalException>
			<cer:reportingServiceEntity>String</cer:reportingServiceEntity>
			<cer:faultDate>*** ERROR ***</cer:faultDate>
			<cer:faultSequenceNumber>String</cer:faultSequenceNumber>
			<cer:faultLevel>String</cer:faultLevel>
			<cer:faultCode>String</cer:faultCode>
			<cer:faultDescription>String</cer:faultDescription>
			<cer:cingularErrorCode>String</cer:cingularErrorCode>
			<cer:cingularErrorDescription>String</cer:cingularErrorDescription>
			<cer:cingularErrorCategory>String</cer:cingularErrorCategory>
		</n1:CSIInternalException>
	</n1:detail>
</n1:Fault>"""

	
	@Before
	public void init()
	{
		MockitoAnnotations.initMocks(this)
	}
	
	@Test
	@Ignore
	public void testMapAAIExceptionTCommonException() {
		
		
		
		String restFault = """
				<Fault>
<requestError>
<serviceException>
<messageId>SVC3002</messageId>
<text>Error writing output performing %1 on %2 (msg=%3) (ec=%4)</text>
<variables>
<variable>PUTcustomer</variable>
<variable>SubName01</variable>
<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>
<variable>ERR.5.4.5105</variable>
</variables>
</serviceException>
</requestError>
</Fault>
			"""	
		def errorString = """<requestError>
<serviceException>
<messageId>SVC3002</messageId>
<text>Error writing output performing %1 on %2 (msg=%3) (ec=%4)</text>
<variables>
<variable>PUTcustomer</variable>
<variable>SubName01</variable>
<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>
<variable>ERR.5.4.5105</variable>
</variables>
</serviceException>
</requestError>""" as String


			
		ExecutionEntity mockExecution = mock(ExecutionEntity.class)

		TrinityExceptionUtil util = new TrinityExceptionUtil()
		Assert.assertEquals(errorString, util.mapAAIExceptionTCommonException(restFault, mockExecution))
	}
	
	
	
	
	@Test
	public void testBuildException() {				
		ExecutionEntity mockExecution = mock(ExecutionEntity.class)
		when(mockExecution.getVariable("prefix")).thenReturn("test_")
		when(mockExecution.getVariable("test_ResponseCode")).thenReturn("400")
		ArrayList msgVars = new ArrayList()
		msgVars.add("var1")
		msgVars.add("var2")
		when(mockExecution.getVariable("test_errVariables")).thenReturn(msgVars)

		
		TrinityExceptionUtil util = new TrinityExceptionUtil()
		String msg = "Bad request"
		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">
	<tns:serviceException>
		<tns:messageId>SVC2000</tns:messageId>
		<tns:text>The following service error occurred: %1. Error code is %2.</tns:text>
			<tns:variables>var1</tns:variables>
			<tns:variables>var2</tns:variables>
	</tns:serviceException>
</tns:requestError>"""
		Assert.assertEquals(errorString, util.buildException(msg, mockExecution))
	}
	
	@Test
	public void testMapAOTSExecptionToCommonException() {
		ExecutionEntity mockExecution = mock(ExecutionEntity.class)
		when(mockExecution.getVariable("prefix")).thenReturn("test_")
		when(mockExecution.getVariable("test_ResponseCode")).thenReturn("400")
		
		TrinityExceptionUtil util = new TrinityExceptionUtil()
		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">
	<tns:serviceException>
		<tns:messageId>SVC2000</tns:messageId>
		<tns:text>The following service error occurred: %1. Error code is %2.</tns:text>
			<tns:variables>Received error from AOTS: bad stuff</tns:variables>
			<tns:variables>400</tns:variables>
	</tns:serviceException>
</tns:requestError>"""
		Assert.assertEquals(errorString, util.mapAOTSExecptionToCommonException(aotsFault, mockExecution))
	}
	
	
	@Test
	public void testParseError() {
	ExecutionEntity mockExecution = mock(ExecutionEntity.class)
	String errorString = "The following service error occurred: %1. Error code is %2."
	ArrayList msgVars = new ArrayList()
	msgVars.add("var1")
	msgVars.add("var2")
	when(mockExecution.getVariable("prefix")).thenReturn("test_")
	when(mockExecution.getVariable("test_errTxt")).thenReturn(errorString)
	when(mockExecution.getVariable("test_errVariables")).thenReturn(msgVars)
		
	TrinityExceptionUtil util = new TrinityExceptionUtil()

	Assert.assertEquals("The following service error occurred: var1. Error code is var2.", util.parseError(mockExecution))
}

	
	
}