Example usage for org.springframework.context ApplicationContextException getMessage

List of usage examples for org.springframework.context ApplicationContextException getMessage

Introduction

In this page you can find the example usage for org.springframework.context ApplicationContextException getMessage.

Prototype

@Override
@Nullable
public String getMessage() 

Source Link

Document

Return the detail message, including the message from the nested exception if there is one.

Usage

From source file:org.hdiv.web.servlet.view.freemarker.FreeMarkerViewTests.java

@Test
public void testNoFreeMarkerConfig() throws Exception {
    FreeMarkerView fv = new FreeMarkerView();

    MockControl wmc = MockControl.createControl(WebApplicationContext.class);
    WebApplicationContext wac = (WebApplicationContext) wmc.getMock();
    wac.getBeansOfType(FreeMarkerConfig.class, true, false);
    wmc.setReturnValue(new HashMap());
    wac.getParentBeanFactory();//from   ww  w . j  a v a2s.c  om
    wmc.setReturnValue(null);
    wac.getServletContext();
    wmc.setReturnValue(new MockServletContext());
    wmc.replay();

    fv.setUrl("anythingButNull");
    try {
        fv.setApplicationContext(wac);
        fv.afterPropertiesSet();
        fail("Should have thrown BeanDefinitionStoreException");
    } catch (ApplicationContextException ex) {
        // Check there's a helpful error message
        assertTrue(ex.getMessage().indexOf("FreeMarkerConfig") != -1);
    }

    wmc.verify();
}

From source file:org.springframework.data.gemfire.support.SpringContextBootstrappingInitializerTest.java

@Test(expected = IllegalArgumentException.class)
public void testInitWhenBasePackagesAndContextConfigLocationsParametersAreUnspecified() throws Throwable {
    assertNull(SpringContextBootstrappingInitializer.applicationContext);

    try {/* ww  w . j a  va  2s . c o  m*/
        new SpringContextBootstrappingInitializer().init(createParameters(
                createParameters(SpringContextBootstrappingInitializer.CONTEXT_CONFIG_LOCATIONS_PARAMETER, ""),
                SpringContextBootstrappingInitializer.BASE_PACKAGES_PARAMETER, "  "));
    } catch (ApplicationContextException expected) {
        assertTrue(expected.getMessage().contains("Failed to bootstrap the Spring ApplicationContext!"));
        assertTrue(expected.getCause() instanceof IllegalArgumentException);
        assertEquals("'basePackages', 'configLocations' or 'AnnotatedClasses' must be specified"
                + " in order to construct and configure an instance of the ConfigurableApplicationContext",
                expected.getCause().getMessage());
        throw expected.getCause();
    }
}

From source file:org.springframework.data.gemfire.support.SpringContextBootstrappingInitializerTest.java

@Test(expected = IllegalStateException.class)
public void testInitWhenApplicationContextIsNotRunning() {
    assertNull(SpringContextBootstrappingInitializer.applicationContext);

    final ConfigurableApplicationContext mockApplicationContext = mock(ConfigurableApplicationContext.class,
            "testInitWhenApplicationContextIsNotRunning");

    when(mockApplicationContext.getId()).thenReturn("testInitWhenApplicationContextIsNotRunning");
    when(mockApplicationContext.isRunning()).thenReturn(false);

    SpringContextBootstrappingInitializer initializer = new SpringContextBootstrappingInitializer() {
        @Override/*from w  ww .  j  av  a  2 s .com*/
        protected ConfigurableApplicationContext createApplicationContext(final String[] basePackages,
                final String[] configLocations) {
            return mockApplicationContext;
        }
    };

    try {
        initializer.init(createParameters(SpringContextBootstrappingInitializer.BASE_PACKAGES_PARAMETER,
                "org.example.app, org.example.plugins"));

        SpringContextBootstrappingInitializer.getApplicationContext();
    } catch (ApplicationContextException expected) {
        assertTrue(expected.getMessage().contains("Failed to bootstrap the Spring ApplicationContext!"));
        assertTrue(expected.getCause() instanceof IllegalStateException);
        assertEquals(
                "The Spring ApplicationContext (testInitWhenApplicationContextIsNotRunning) failed to be properly initialized with the context config files ([]) or base packages ([org.example.app, org.example.plugins])!",
                expected.getCause().getMessage());
        throw (IllegalStateException) expected.getCause();
    } finally {
        verify(mockApplicationContext, times(1)).addApplicationListener(same(initializer));
        verify(mockApplicationContext, times(1)).registerShutdownHook();
        verify(mockApplicationContext, times(1)).refresh();

        assertNull(SpringContextBootstrappingInitializer.applicationContext);
    }
}

From source file:org.springframework.data.gemfire.support.SpringContextBootstrappingInitializerTest.java

@Test(expected = IllegalStateException.class)
public void testInitLogsErrors() throws Throwable {
    final Log mockLog = mock(Log.class, "testInitLogsErrors.MockLog");

    SpringContextBootstrappingInitializer initializer = new SpringContextBootstrappingInitializer() {
        @Override/*from w ww  . j  a va  2  s .co m*/
        protected Log initLogger() {
            return mockLog;
        }

        @Override
        protected ConfigurableApplicationContext createApplicationContext(final String[] basePackages,
                final String[] configLocations) {
            throw new IllegalStateException("TEST");
        }
    };

    try {
        initializer
                .init(createParameters(SpringContextBootstrappingInitializer.CONTEXT_CONFIG_LOCATIONS_PARAMETER,
                        "classpath/to/spring/application/context.xml"));
    } catch (ApplicationContextException expected) {
        assertTrue(expected.getMessage().contains("Failed to bootstrap the Spring ApplicationContext!"));
        assertTrue(expected.getCause() instanceof IllegalStateException);
        assertEquals("TEST", expected.getCause().getMessage());
        throw expected.getCause();
    } finally {
        verify(mockLog, times(1)).error(eq("Failed to bootstrap the Spring ApplicationContext!"),
                any(RuntimeException.class));
    }
}