3

As per official document How to Debug, I need to add following to the property file to enable logging

logging.level.org.apache.http.wire=DEBUG
logging.level.com.github.tomakehurst.wiremock=DEBUG

But, I don't see any logs visible on the console when request sent to wiremock server. I'm getting 500 Internal Server Error only specific platform. So, to troubleshoot I'm trying to intercept activity when request reached to wiremock server.

In my pom file

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-test</artifactId>
  <scope>test</scope>
</dependency>

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-contract-stub-runner</artifactId>
  <scope>test</scope>
</dependency>

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-webflux</artifactId>
  <scope>test</scope>
</dependency>

I also tried adding logback-test.xml file with following content. But, this is not logging anything as well.

<logger name="com.github.tomakehurst.wiremock" level="DEBUG"/> 
<logger name="wiremock.org" level="DEBUG"/> 
<logger name="WireMock" level="DEBUG"/> 
<logger name="/" level="DEBUG"/> 

My test class

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
    classes = MyApplication.class)
@AutoConfigureMockMvc
@TestPropertySource(
    locations = "/application-integration-test.properties"
)
@AutoConfigureWireMock(port = 0)
@AutoConfigureWebTestClient(timeout = "100000")
public class MyApplicationTest {

  private WebTestClient client;

  @LocalServerPort
  private int port;


  @Before
  public void setUp() throws Exception {

    client = WebTestClient.bindToServer().baseUrl("http://localhost:" + port).build();
  }

  /// Test code 

}

Anyone suggest what am missing ?

cool_ravi
  • 165
  • 1
  • 9
  • Did you try add `ConsoleNotifier` from official docs [WIREMOCK](http://wiremock.org/docs/configuration/) see section Notification (logging) – borino Feb 15 '21 at 08:10
  • could you share the example, which be fit for above code. This existing code and I don't know how to use `ConsoleNotifier` in this case. I can't change the entire flow for enabling the log. That will impact whole flow. – cool_ravi Feb 16 '21 at 12:26
  • try to add in your `setUp` method `WireMockConfiguration.options() .notifier(new ConsoleNotifier(true));` – borino Feb 16 '21 at 12:43

1 Answers1

4

If you are using WireMock via Spring annotation @AutoConfigureWireMock, best way to see WireMock (verbose) logs in test console output should be to add this bean in your test class:

@TestConfiguration
static class WireMockTestConfiguration {
    @Bean
    WireMockConfigurationCustomizer optionsCustomizer() {
        return config -> config.notifier(new ConsoleNotifier(true));
    }
}

You may use @Import to add WireMockTestConfiguration to Spring context.

Andrija
  • 367
  • 3
  • 14