1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.mail.internal.thread.context

File XWikiRequestCopierTest.java

 

Code metrics

0
18
3
1
81
46
3
0.17
6
3
1

Classes

Class Line # Actions
XWikiRequestCopierTest 38 18 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.mail.internal.thread.context;
21   
22    import org.junit.Before;
23    import org.junit.Rule;
24    import org.junit.Test;
25    import org.xwiki.test.mockito.MockitoComponentMockingRule;
26   
27    import com.xpn.xwiki.web.Utils;
28    import com.xpn.xwiki.web.XWikiRequest;
29    import com.xpn.xwiki.web.XWikiServletRequestStub;
30   
31    import static org.junit.Assert.*;
32   
33    /**
34    * Unit tests for {@link XWikiRequestCopier}.
35    *
36    * @version $Id: 23dccc9cd06d0cb572e71a9fca339fecaabf8b37 $
37    */
 
38    public class XWikiRequestCopierTest
39    {
40    @Rule
41    public MockitoComponentMockingRule<XWikiRequestCopier> mocker = new MockitoComponentMockingRule<>(
42    XWikiRequestCopier.class);
43   
44    XWikiServletRequestStub originalRequest;
45   
 
46  2 toggle @Before
47    public void setup() throws Exception
48    {
49  2 Utils.setComponentManager(mocker);
50   
51  2 this.originalRequest = new XWikiServletRequestStub();
52  2 this.originalRequest.setHost("host");
53  2 this.originalRequest.setContextPath("contextPath");
54  2 this.originalRequest.setScheme("scheme");
55  2 this.originalRequest.setAttribute("attribute", "value");
56  2 this.originalRequest.setServerName("server");
57  2 this.originalRequest.setrequestURL(new StringBuffer("url"));
58    }
59   
 
60  1 toggle @Test
61    public void copyRequest() throws Exception
62    {
63  1 XWikiRequest copy = this.mocker.getComponentUnderTest().copy(this.originalRequest);
64  1 assertNotSame(this.originalRequest, copy);
65   
66    // Check that each value on the cloned request are equal.
67  1 assertEquals(this.originalRequest.getHeader("x-forwarded-host"), copy.getHeader("x-forwarded-host"));
68  1 assertEquals(this.originalRequest.getContextPath(), copy.getContextPath());
69  1 assertEquals(this.originalRequest.getScheme(), copy.getScheme());
70  1 assertEquals(this.originalRequest.getAttributeNames(), copy.getAttributeNames());
71  1 assertEquals(this.originalRequest.getAttribute("attribute"), copy.getAttribute("attribute"));
72  1 assertEquals(this.originalRequest.getServerName(), copy.getServerName());
73  1 assertEquals(this.originalRequest.getRequestURL(), copy.getRequestURL());
74    }
75   
 
76  1 toggle @Test
77    public void copyContextWhenNull() throws Exception
78    {
79  1 assertNull(this.mocker.getComponentUnderTest().copy(null));
80    }
81    }