View Javadoc
1   package ch.qos.logback.access.spi;
2   
3   import static org.junit.Assert.*;
4   
5   import java.util.Map;
6   
7   import org.junit.After;
8   import org.junit.Before;
9   import org.junit.Test;
10  
11  import ch.qos.logback.access.dummy.DummyAccessEventBuilder;
12  import ch.qos.logback.access.dummy.DummyRequest;
13  import ch.qos.logback.core.testUtil.RandomUtil;
14  
15  public class AccessEventTest {
16  
17      int diff = RandomUtil.getPositiveInt();
18      
19      @Before
20      public void setUp() throws Exception {
21      }
22  
23      @After
24      public void tearDown() throws Exception {
25      }
26  
27      // See LOGBACK-1189
28      @Test
29      public void callingPrepareForDeferredProcessingShouldBeIdempotent() {
30          String key = "key-"+diff;
31          String val = "val-"+diff;
32          
33          IAccessEvent ae = DummyAccessEventBuilder.buildNewAccessEvent();
34          DummyRequest request = (DummyRequest) ae.getRequest();
35          Map<String, String> headersMap = request.getHeaders();
36          Map<String, String[]> parametersMap = request.getParameterMap();
37          
38          headersMap.put(key, val);
39          request.setAttribute(key, val);
40          parametersMap.put(key, new String[] {val});
41          ae.prepareForDeferredProcessing();
42          assertEquals(val, ae.getAttribute(key));
43          assertEquals(val, ae.getRequestHeader(key));
44          assertEquals(val, ae.getRequestParameter(key)[0]);
45          
46          
47          request.setAttribute(key, "change");
48          headersMap.put(key, "change");
49          parametersMap.put(key, new String[] {"change"});
50          ae.prepareForDeferredProcessing();
51          assertEquals(val, ae.getAttribute(key));
52          assertEquals(val, ae.getRequestHeader(key));
53          assertEquals(val, ae.getRequestParameter(key)[0]);
54          
55      }
56  
57  }