1 package org.sonar.server.platform.web.requestid;
3 import org.apache.log4j.MDC;
4 import org.junit.After;
7 import org.junit.rules.ExpectedException;
9 import static org.assertj.core.api.Assertions.assertThat;
11 public class RequestUidMDCStorageTest {
13 public ExpectedException expectedException = ExpectedException.none();
16 public void tearDown() throws Exception {
21 public void constructor_fails_with_NPE_when_argument_is_null() {
22 expectedException.expect(NullPointerException.class);
23 expectedException.expectMessage("Request UID can't be null");
25 new RequestUidMDCStorage(null);
29 public void constructor_adds_specified_value_in_MDC_under_HTTP_REQUEST_ID_key() {
30 new RequestUidMDCStorage("toto");
32 assertThat(MDC.get("HTTP_REQUEST_ID")).isEqualTo("toto");
36 public void close_removes_value_from_MDC() {
37 RequestUidMDCStorage underTest = new RequestUidMDCStorage("boum");
38 assertThat(MDC.get("HTTP_REQUEST_ID")).isEqualTo("boum");
42 assertThat(MDC.get("HTTP_REQUEST_ID")).isNull();