/*-
* ============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.CommonExceptionUtil;
@RunWith(MockitoJUnitRunner.class)
import org.junit.Test
class CommonExceptionUtilTest {
def aotsFault ="""
xml:space
String
http://csi.att.com
400
bad stuff
String
*** ERROR ***
String
String
String
String
String
String
String
String
String
String
String
*** ERROR ***
String
String
String
String
String
String
String
"""
@Before
public void init()
{
MockitoAnnotations.initMocks(this)
}
@Test
@Ignore
public void testMapAAIExceptionTCommonException() {
String restFault = """
SVC3002
Error writing output performing %1 on %2 (msg=%3) (ec=%4)
PUTcustomer
SubName01
Unexpected error reading/updating database:Adding this property for key [service-instance-id] and value [USSTU2CFCNC0101UJZZ01] violates a uniqueness constraint [service-instance-id]
ERR.5.4.5105
"""
def errorString = """
SVC3002
Error writing output performing %1 on %2 (msg=%3) (ec=%4)
PUTcustomer
SubName01
Unexpected error reading/updating database:Adding this property for key [service-instance-id] and value [USSTU2CFCNC0101UJZZ01] violates a uniqueness constraint [service-instance-id]
ERR.5.4.5105
""" as String
ExecutionEntity mockExecution = mock(ExecutionEntity.class)
CommonExceptionUtil util = new CommonExceptionUtil()
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)
CommonExceptionUtil util = new CommonExceptionUtil()
String msg = "Bad request"
String errorString = """
SVC2000
The following service error occurred: %1. Error code is %2.
var1
var2
"""
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")
CommonExceptionUtil util = new CommonExceptionUtil()
String errorString = """
SVC2000
The following service error occurred: %1. Error code is %2.
Received error from AOTS: bad stuff
400
"""
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)
CommonExceptionUtil util = new CommonExceptionUtil()
Assert.assertEquals("The following service error occurred: var1. Error code is var2.", util.parseError(mockExecution))
}
}