Example usage for org.springframework.core NestedRuntimeException getRootCause

List of usage examples for org.springframework.core NestedRuntimeException getRootCause

Introduction

In this page you can find the example usage for org.springframework.core NestedRuntimeException getRootCause.

Prototype

@Nullable
public Throwable getRootCause() 

Source Link

Document

Retrieve the innermost cause of this exception, if any.

Usage

From source file:com.cisco.cta.taxii.adapter.settings.BindExceptionHandlerTest.java

@Test
public void invalidPollEndpoint() throws Exception {
    try (AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext()) {
        ctx.register(SettingsConfiguration.class);
        ctx.getEnvironment().getPropertySources()
                .addFirst(exclude(validProperties(), "taxiiService.pollEndpoint"));
        ctx.refresh();//from ww w . j  av a  2 s.c  o  m
        fail("The context creation must fail because of invalid configuration.");
    } catch (NestedRuntimeException e) {
        BindException be = (BindException) e.getRootCause();
        handler.handle(be);
        verify(err).println(contains("pollEndpoint has illegal value"));
    }
}

From source file:com.cisco.cta.taxii.adapter.settings.SettingsConfigurationTest.java

@Test
public void refuseMissingConfiguration() throws Exception {
    try (AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
            SettingsConfiguration.class)) {
        fail("The context creation must fail because of missing configuration.");
    } catch (NestedRuntimeException e) {
        BindException be = (BindException) e.getRootCause();
        assertThat(be.getFieldErrors(), is(not(emptyCollectionOf(FieldError.class))));
    }/*from w w w  .  j a v  a2 s  .  c  o  m*/
}

From source file:com.cisco.cta.taxii.adapter.settings.SettingsConfigurationTest.java

@Test
public void resfuseMissingPollEndpoint() throws Exception {
    try (ConfigurableApplicationContext ctx = context(
            exclude(validProperties(), "taxiiService.pollEndpoint"))) {
        fail("The context creation must fail because of invalid configuration.");
    } catch (NestedRuntimeException e) {
        BindException be = (BindException) e.getRootCause();
        assertThat(be.getFieldErrors(), hasSize(1));
        assertThat(be.getFieldError().getObjectName(), is("taxiiService"));
        assertThat(be.getFieldError().getField(), is("pollEndpoint"));
        assertThat(be.getFieldError().getRejectedValue(), is(nullValue()));
        assertThat(be.getFieldError().getDefaultMessage(), is("may not be null"));
    }/*from   ww  w. j  a  va 2 s  .  c o m*/
}