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.runner.RunWith;
25 import org.mockito.runners.MockitoJUnitRunner;
28 import org.junit.Ignore;
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.ExceptionUtil;
39 @RunWith(MockitoJUnitRunner.class)
44 class ExceptionUtilTest {
50 MockitoAnnotations.initMocks(this)
54 public void testErrorMessageDetails() {
58 String restFault = """
62 <messageId>SVC3002</messageId>
63 <text>Error writing output performing %1 on %2 (msg=%3) (ec=%4)</text>
65 <variable>PUTcustomer</variable>
66 <variable>SubName01</variable>
67 <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>
68 <variable>ERR.5.4.5105</variable>
74 def errorString = """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
75 <aetgt:ErrorMessage>Received error from A&AI (Error writing output performing PUTcustomer on SubName01 (msg=Unexpected error reading/updating database:Adding this property for key [service-instance-id] and value [USSTU2CFCNC0101UJZZ01] violates a uniqueness constraint [service-instance-id]) (ec=ERR.5.4.5105))</aetgt:ErrorMessage>
76 <aetgt:ErrorCode>5000</aetgt:ErrorCode>
77 </aetgt:WorkflowException>""" as String
79 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
81 ExceptionUtil util = new ExceptionUtil()
82 Assert.assertEquals(errorString, util.MapAAIExceptionToWorkflowExceptionOld(restFault, mockExecution))
87 public void testErrorMessage() {
88 String restFault = """
89 <rest:RESTFault xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd"
90 errorType="transport">
91 <rest:errorCode>500</rest:errorCode>
92 <rest:message>HTTP method: GET Internal Server Error </rest:message>
95 def errorString = """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
96 <aetgt:ErrorMessage>Received error from A&AI (HTTP method: GET Internal Server Error)</aetgt:ErrorMessage>
97 <aetgt:ErrorCode>5000</aetgt:ErrorCode>
98 </aetgt:WorkflowException>""" as String
100 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
101 when(mockExecution.getVariable("prefix")).thenReturn("test_")
102 when(mockExecution.getVariable("test_ErrorResponse")).thenReturn("HTTP method: GET Internal Server Error")
104 ExceptionUtil util = new ExceptionUtil()
105 String msg = "HTTP method: GET Internal Server Error"
106 Assert.assertEquals(errorString, util.MapAAIExceptionToWorkflowExceptionOld(restFault, mockExecution))
110 public void testBadResponseErrorMessage() {
111 String restFault = "asfafasfasfd"
112 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
113 when(mockExecution.getVariable("prefix")).thenReturn("test_")
114 when(mockExecution.getVariable("test_ErrorResponse")).thenReturn(null)
115 ExceptionUtil util = new ExceptionUtil()
116 String expected = "<aetgt:WorkflowException xmlns:aetgt=\"http://org.openecomp/mso/workflow/schema/v1\">"+
117 "\n <aetgt:ErrorMessage>Received error from A&AI ()</aetgt:ErrorMessage>"+
118 "\n <aetgt:ErrorCode>5000</aetgt:ErrorCode>"+
119 "\n </aetgt:WorkflowException>";
120 Assert.assertEquals(expected,util.MapAAIExceptionToWorkflowExceptionOld(restFault, mockExecution))
124 public void testMapErrorCode5010(){
125 String msg = "Connect to njcdtl20ew2988:8070 failed: Connection refused: connect"
126 ExceptionUtil util = new ExceptionUtil()
127 Assert.assertEquals("5010",util.MapErrorCode(msg))
131 public void testMapErrorCode5020(){
132 String msg = "Connection timed out"
133 ExceptionUtil util = new ExceptionUtil()
134 Assert.assertEquals("5020",util.MapErrorCode(msg))
138 public void testMapCategoryToErrorCode5100 () {
139 String errorCategory = "OPENSTACK"
140 ExceptionUtil util = new ExceptionUtil()
141 Assert.assertEquals('5100', util.MapCategoryToErrorCode(errorCategory))
145 public void testMapCategoryToErrorCode5110 () {
146 String errorCategory = "IO"
147 ExceptionUtil util = new ExceptionUtil()
148 Assert.assertEquals('5110', util.MapCategoryToErrorCode(errorCategory))
152 public void testMapCategoryToErrorCode7020 () {
153 String errorCategory = "USERDATA"
154 ExceptionUtil util = new ExceptionUtil()
155 Assert.assertEquals('7020', util.MapCategoryToErrorCode(errorCategory))
160 public void testMapAdapterExecptionToWorkflowException_UserDataErrorMessage () {
161 String response = """<ns2:TenantException xmlns:ns2=\"http://org.openecomp.mso/tenant\"><category>USERDATA</category><message>Cloud Site [CHCGILNE001] not found</message></ns2:TenantException>""" as String
162 String expected = """WorkflowException[processKey=ExceptionUtil,errorCode=7020,errorMessage=Received error from Tenant Adapter: Cloud Site [CHCGILNE001] not found]""" as String
164 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
165 when(mockExecution.getVariable("prefix")).thenReturn("test_")
166 when(mockExecution.getVariable("testProcessKey")).thenReturn("ExceptionUtil")
168 ExceptionUtil util = new ExceptionUtil()
169 String actual = util.MapAdapterExecptionToWorkflowException(response, mockExecution, "Tenant Adapter")
171 verify(mockExecution).setVariable("WorkflowException",expected)
176 public void testMapAdapterExecptionToWorkflowException_IOErrorMessage () {
177 String response = """<ns2:TenantException xmlns:ns2=\"http://org.openecomp.mso/tenant\"><category>IO</category><message>[TokenAuth] Connect to test.aic.cip.att.com:5000 [test.aic.cip.att.com/300.200.100.100] failed: Connection refused</message></ns2:TenantException>""" as String
178 String expected = """WorkflowException[processKey=ExceptionUtil,errorCode=5110,errorMessage=Could not communicate with Platform Orchestrator]""" as String
180 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
181 when(mockExecution.getVariable("prefix")).thenReturn("test_")
182 when(mockExecution.getVariable("testProcessKey")).thenReturn("ExceptionUtil")
184 ExceptionUtil util = new ExceptionUtil()
185 String actual = util.MapAdapterExecptionToWorkflowException(response, mockExecution, "Tenant Adapter")
187 verify(mockExecution).setVariable("WorkflowException",expected)