alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Spring Framework example source code file (RollbackRuleTests.java)

This example Spring Framework source code file (RollbackRuleTests.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Spring Framework tags/keywords

cannot, cannot, exception, fatalbeanexception, illegalargumentexception, illegalargumentexception, mailsendexception, mailsendexception, rollbackruleattribute, rollbackruleattribute, rollbackruletests, runtimeexception, servlet, servletexception, testcase

The Spring Framework RollbackRuleTests.java source code

/*
 * Copyright 2002-2007 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.transaction.interceptor;

import javax.servlet.ServletException;

import junit.framework.TestCase;

import org.springframework.beans.FatalBeanException;
import org.springframework.mail.MailSendException;

/**
 * Unit tests for the {@link RollbackRuleAttribute} class.
 *
 * @author Rod Johnson
 * @author Rick Evans
 * @since 09.04.2003
 */
public class RollbackRuleTests extends TestCase {

	public void testFoundImmediatelyWithString() {
		RollbackRuleAttribute rr = new RollbackRuleAttribute("java.lang.Exception");
		assertTrue(rr.getDepth(new Exception()) == 0);
	}
	
	public void testFoundImmediatelyWithClass() {
		RollbackRuleAttribute rr = new RollbackRuleAttribute(Exception.class);
		assertTrue(rr.getDepth(new Exception()) == 0);
	}
	
	public void testNotFound() {
		RollbackRuleAttribute rr = new RollbackRuleAttribute("javax.servlet.ServletException");
		assertTrue(rr.getDepth(new MailSendException("")) == -1);
	}
	
	public void testAncestry() {
		RollbackRuleAttribute rr = new RollbackRuleAttribute("java.lang.Exception");
		// Exception -> Runtime -> NestedRuntime -> MailException -> MailSendException
		assertTrue(rr.getDepth(new MailSendException("")) == 4);
	}

	public void testAlwaysTrueForThrowable() {
		RollbackRuleAttribute rr = new RollbackRuleAttribute("java.lang.Throwable");
		assertTrue(rr.getDepth(new MailSendException("")) > 0);
		assertTrue(rr.getDepth(new ServletException()) > 0);
		assertTrue(rr.getDepth(new FatalBeanException(null,null)) > 0);
		assertTrue(rr.getDepth(new RuntimeException()) > 0);
	}

	public void testCtorArgMustBeAThrowableClassWithNonThrowableType() {
		try {
			new RollbackRuleAttribute(StringBuffer.class);
			fail("Cannot construct a RollbackRuleAttribute with a non-Throwable type");
		}
		catch (IllegalArgumentException expected) {
		}
	}

	public void testCtorArgMustBeAThrowableClassWithNullThrowableType() {
		try {
			new RollbackRuleAttribute((Class) null);
			fail("Cannot construct a RollbackRuleAttribute with a null-Throwable type");
		}
		catch (IllegalArgumentException expected) {
		}
	}

	public void testCtorArgExceptionStringNameVersionWithNull() {
		try {
			new RollbackRuleAttribute((String) null);
			fail("Cannot construct a RollbackRuleAttribute with a null-Throwable type");
		}
		catch (IllegalArgumentException expected) {
		}
	}

}

Other Spring Framework examples (source code examples)

Here is a short list of links related to this Spring Framework RollbackRuleTests.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.