Add exception translator for EclipseLink exceptions

Issue: SPR-9541
This commit is contained in:
Jan Stamer
2012-06-25 12:52:59 +02:00
committed by Stephane Nicoll
parent 658f7f58df
commit 371e3a7ac0
6 changed files with 266 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2002-2012 the original author or authors.
*
* 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.
*/
package org.springframework.orm.eclipselink;
import junit.framework.TestCase;
import org.eclipse.persistence.exceptions.DatabaseException;
import org.springframework.dao.DataAccessException;
/**
* @author Jan Stamer
* @since 3.2
*/
public class EclipseLinkExceptionTranslatorTests extends TestCase {
public void testWithWrongException() {
EclipseLinkExceptionTranslator exceptionTranslator = new EclipseLinkExceptionTranslator();
assertNull(exceptionTranslator.translateExceptionIfPossible(new IllegalArgumentException()));
}
public void testWithEclipseLinkException() {
EclipseLinkExceptionTranslator exceptionTranslator = new EclipseLinkExceptionTranslator();
assertNotNull(exceptionTranslator.translateExceptionIfPossible(DatabaseException.databaseAccessorNotConnected()));
assertTrue(exceptionTranslator.translateExceptionIfPossible(DatabaseException.databaseAccessorNotConnected()) instanceof DataAccessException);
}
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright 2002-2012 the original author or authors.
*
* 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.
*/
package org.springframework.orm.eclipselink;
import junit.framework.TestCase;
import org.eclipse.persistence.exceptions.DatabaseException;
import org.hibernate.HibernateException;
/**
* @author Jan Stamer
* @since 3.2
*/
public class EclipseLinkSytemExceptionTests extends TestCase {
public void testWithNull() {
EclipseLinkSystemException exception = new EclipseLinkSystemException(null);
assertNull(exception.getCause());
assertNull(exception.getMessage());
}
public void testCreateWithCause() {
DatabaseException dbExceptionWithCause = new DatabaseException("my custom exception cause") {
};
EclipseLinkSystemException elSystemException = new EclipseLinkSystemException(dbExceptionWithCause);
assertEquals(dbExceptionWithCause, elSystemException.getCause());
assertTrue(elSystemException.getMessage().contains("my custom exception cause"));
}
public void testCreateWithNullCause() throws HibernateException {
DatabaseException dbExceptionWithCause = new DatabaseException((String) null) {
};
EclipseLinkSystemException elSystemException = new EclipseLinkSystemException(dbExceptionWithCause);
assertEquals(dbExceptionWithCause, elSystemException.getCause());
assertTrue(elSystemException.getMessage().contains("null"));
}
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright 2002-2012 the original author or authors.
*
* 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.
*/
package org.springframework.orm.eclipselink;
import junit.framework.TestCase;
import org.eclipse.persistence.exceptions.DatabaseException;
import org.springframework.dao.DataAccessException;
/**
* @author Jan Stamer
* @since 3.2
*/
public class EclipseLinkUtilsTests extends TestCase {
public void testWithNull() {
assertTrue(EclipseLinkUtils.convertEclipseLinkAccessException(null) instanceof DataAccessException);
}
public void testWithEclipseLinkException() {
assertTrue(EclipseLinkUtils.convertEclipseLinkAccessException(DatabaseException.databaseAccessorNotConnected()) instanceof DataAccessException);
}
}