]> source.dussan.org Git - sonarqube.git/blob
81d991f3813ce373c8a3c3ac3b1cee5b0f3ce074
[sonarqube.git] /
1 package org.sonar.server.platform.web.requestid;
2
3 import org.apache.log4j.MDC;
4 import org.junit.After;
5 import org.junit.Rule;
6 import org.junit.Test;
7 import org.junit.rules.ExpectedException;
8
9 import static org.assertj.core.api.Assertions.assertThat;
10
11 public class RequestUidMDCStorageTest {
12   @Rule
13   public ExpectedException expectedException = ExpectedException.none();
14
15   @After
16   public void tearDown() throws Exception {
17     MDC.clear();
18   }
19
20   @Test
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");
24
25     new RequestUidMDCStorage(null);
26   }
27
28   @Test
29   public void constructor_adds_specified_value_in_MDC_under_HTTP_REQUEST_ID_key() {
30     new RequestUidMDCStorage("toto");
31
32     assertThat(MDC.get("HTTP_REQUEST_ID")).isEqualTo("toto");
33   }
34
35   @Test
36   public void close_removes_value_from_MDC() {
37     RequestUidMDCStorage underTest = new RequestUidMDCStorage("boum");
38     assertThat(MDC.get("HTTP_REQUEST_ID")).isEqualTo("boum");
39
40     underTest.close();
41
42     assertThat(MDC.get("HTTP_REQUEST_ID")).isNull();
43   }
44 }