Search in sources :

Example 6 with FatalBeanException

use of org.springframework.beans.FatalBeanException in project spring-framework by spring-projects.

the class BeanFactoryTransactionTests method testNoTransactionAttributeSource.

/**
	 * Check that we fail gracefully if the user doesn't set any transaction attributes.
	 */
@Test
public void testNoTransactionAttributeSource() {
    try {
        DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
        new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource("noTransactionAttributeSource.xml", getClass()));
        bf.getBean("noTransactionAttributeSource");
        fail("Should require TransactionAttributeSource to be set");
    } catch (FatalBeanException ex) {
    // Ok
    }
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) FatalBeanException(org.springframework.beans.FatalBeanException) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 7 with FatalBeanException

use of org.springframework.beans.FatalBeanException in project spring-framework by spring-projects.

the class RollbackRuleTests method alwaysTrueForThrowable.

@Test
public void alwaysTrueForThrowable() {
    RollbackRuleAttribute rr = new RollbackRuleAttribute(java.lang.Throwable.class.getName());
    assertTrue(rr.getDepth(new MyRuntimeException("")) > 0);
    assertTrue(rr.getDepth(new IOException()) > 0);
    assertTrue(rr.getDepth(new FatalBeanException(null, null)) > 0);
    assertTrue(rr.getDepth(new RuntimeException()) > 0);
}
Also used : FatalBeanException(org.springframework.beans.FatalBeanException) IOException(java.io.IOException) Test(org.junit.Test)

Example 8 with FatalBeanException

use of org.springframework.beans.FatalBeanException in project spring-boot by spring-projects.

the class NoSuchBeanDefinitionFailureAnalyzerTests method failureAnalysisForExcludedAutoConfigurationType.

@Test
public void failureAnalysisForExcludedAutoConfigurationType() {
    FatalBeanException failure = createFailure(StringHandler.class);
    addExclusions(this.analyzer, TestPropertyAutoConfiguration.class);
    FailureAnalysis analysis = analyzeFailure(failure);
    assertDescriptionConstructorMissingType(analysis, StringHandler.class, 0, String.class);
    String configClass = ClassUtils.getShortName(TestPropertyAutoConfiguration.class.getName());
    assertClassDisabled(analysis, String.format("auto-configuration '%s' was excluded", configClass), "string");
    assertActionMissingType(analysis, String.class);
}
Also used : FatalBeanException(org.springframework.beans.FatalBeanException) FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) Test(org.junit.Test)

Example 9 with FatalBeanException

use of org.springframework.beans.FatalBeanException in project spring-boot by spring-projects.

the class NoSuchBeanDefinitionFailureAnalyzerTests method createFailure.

private FatalBeanException createFailure(Class<?> config, String... environment) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    this.analyzer.setBeanFactory(context.getBeanFactory());
    EnvironmentTestUtils.addEnvironment(context, environment);
    context.register(config);
    try {
        context.refresh();
        return null;
    } catch (FatalBeanException ex) {
        return ex;
    } finally {
        context.close();
    }
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) FatalBeanException(org.springframework.beans.FatalBeanException)

Example 10 with FatalBeanException

use of org.springframework.beans.FatalBeanException in project spring-framework by spring-projects.

the class ControllerAdviceTests method resolveExceptionWithAssertionErrorAsRootCause.

@Test
public void resolveExceptionWithAssertionErrorAsRootCause() throws Exception {
    AssertionError cause = new AssertionError("argh");
    FatalBeanException exception = new FatalBeanException("wrapped", cause);
    testException(exception, cause.toString());
}
Also used : FatalBeanException(org.springframework.beans.FatalBeanException) Test(org.junit.Test)

Aggregations

FatalBeanException (org.springframework.beans.FatalBeanException)17 Test (org.junit.Test)10 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)4 BeansException (org.springframework.beans.BeansException)2 BeanFactory (org.springframework.beans.factory.BeanFactory)2 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 ReversePropertySourcesStandardServletEnvironment (com.hevelian.activemq.support.ReversePropertySourcesStandardServletEnvironment)1 ConfigObject (groovy.util.ConfigObject)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 PostConstruct (javax.annotation.PostConstruct)1 ResourceXmlApplicationContext (org.apache.xbean.spring.context.ResourceXmlApplicationContext)1 BeanInstantiationException (org.springframework.beans.BeanInstantiationException)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)1