Search in sources :

Example 16 with IAccessEvent

use of ch.qos.logback.access.spi.IAccessEvent in project logback-access-spring-boot-starter by akihyro.

the class AbstractLogbackAccessEventsTest method logbackAccessEventWithRequestHeader.

/**
     * Tests a Logback-access event with a request header.
     */
@Test
public void logbackAccessEventWithRequestHeader() {
    RequestEntity<Void> request = RequestEntity.get(rest.getRestTemplate().getUriTemplateHandler().expand("/test/text")).header("X-Test-Header", "TEST-HEADER").build();
    ResponseEntity<String> response = rest.exchange(request, String.class);
    IAccessEvent event = LogbackAccessEventQueuingAppender.appendedEventQueue.pop();
    LogbackAccessEventQueuingListener.appendedEventQueue.pop();
    assertThat(response).hasStatusCode(HttpStatus.OK);
    assertThat(event).hasRequestHeaderName("X-Test-Header").hasRequestHeader("X-Test-Header", "TEST-HEADER").hasRequestHeaderInMap("X-Test-Header", "TEST-HEADER");
}
Also used : IAccessEvent(ch.qos.logback.access.spi.IAccessEvent) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with IAccessEvent

use of ch.qos.logback.access.spi.IAccessEvent in project logback-access-spring-boot-starter by akihyro.

the class AbstractLogbackAccessEventsTest method logbackAccessEventWithResponseHeader.

/**
     * Tests a Logback-access event with a response header.
     */
@Test
public void logbackAccessEventWithResponseHeader() {
    ResponseEntity<String> response = rest.getForEntity("/test/text-with-header", String.class);
    IAccessEvent event = LogbackAccessEventQueuingAppender.appendedEventQueue.pop();
    LogbackAccessEventQueuingListener.appendedEventQueue.pop();
    assertThat(response).hasStatusCode(HttpStatus.OK);
    assertThat(event).hasResponseHeaderName("X-Test-Header").hasResponseHeader("X-Test-Header", "TEST-HEADER").hasResponseHeaderInMap("X-Test-Header", "TEST-HEADER");
}
Also used : IAccessEvent(ch.qos.logback.access.spi.IAccessEvent) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 18 with IAccessEvent

use of ch.qos.logback.access.spi.IAccessEvent in project logback-access-spring-boot-starter by akihyro.

the class UndertowServerPortUnusingTest method logbackAccessEvent.

/** {@inheritDoc} */
@Override
public void logbackAccessEvent() {
    RequestEntity<Void> request = RequestEntity.get(rest.getRestTemplate().getUriTemplateHandler().expand("/test/text")).header("X-Forwarded-Host", "forwarded-host").header("X-Forwarded-Port", "12345").build();
    ResponseEntity<String> response = rest.exchange(request, String.class);
    IAccessEvent event = LogbackAccessEventQueuingAppender.appendedEventQueue.pop();
    LogbackAccessEventQueuingListener.appendedEventQueue.pop();
    assertThat(response).hasStatusCode(HttpStatus.OK);
    assertThat(event).hasLocalPort(port);
}
Also used : IAccessEvent(ch.qos.logback.access.spi.IAccessEvent)

Aggregations

IAccessEvent (ch.qos.logback.access.spi.IAccessEvent)18 Test (org.junit.Test)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)10 Logger (ch.qos.logback.classic.Logger)1 LoggerContext (ch.qos.logback.classic.LoggerContext)1 NullLevelFilterFactory (io.dropwizard.logging.filter.NullLevelFilterFactory)1 AsyncAccessEventAppenderFactory (io.dropwizard.request.logging.async.AsyncAccessEventAppenderFactory)1 LogbackAccessRequestLayoutFactory (io.dropwizard.request.logging.layout.LogbackAccessRequestLayoutFactory)1 LocalDateTime (java.time.LocalDateTime)1