1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.container.servlet.filters

File SavedRequestManagerTest.java

 

Code metrics

0
27
6
1
100
61
6
0.22
4.5
6
1

Classes

Class Line # Actions
SavedRequestManagerTest 41 27 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 3 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.container.servlet.filters;
21   
22    import java.util.HashMap;
23    import java.util.Map;
24   
25    import javax.servlet.http.HttpServletRequest;
26    import javax.servlet.http.HttpSession;
27   
28    import org.jmock.Expectations;
29    import org.jmock.Mockery;
30    import org.junit.Assert;
31    import org.junit.Before;
32    import org.junit.Test;
33    import org.xwiki.container.servlet.filters.SavedRequestManager.SavedRequest;
34   
35    /**
36    * Test for {@link SavedRequestManager}.
37    *
38    * @version $Id: dfc5dc74f7b81e6e2f59bf3fa1a015c3a3c7b6c4 $
39    * @since 2.5M1
40    */
 
41    public class SavedRequestManagerTest
42    {
43    /** Fake test URL. */
44    private static final String TEST_URL = "http://localhost/xwiki/bin/view/Test/Page";
45   
46    /** Mocked request. */
47    private HttpServletRequest request;
48   
 
49  3 toggle @Before
50    public void setUp()
51    {
52  3 Mockery mockery = new Mockery();
53  3 final HttpSession mockSession = mockery.mock(HttpSession.class);
54  3 final HttpServletRequest mockRequest = mockery.mock(HttpServletRequest.class);
55  3 final Map<String, String[]> params = new HashMap<String, String[]>();
56  3 params.put("aaa", new String[]{"bbb"});
57  3 params.put("srid", new String[]{"r4Nd0m"});
58    // request
 
59  3 toggle mockery.checking(new Expectations() {{
60  3 allowing(mockRequest).getSession();
61  3 will(returnValue(mockSession));
62  3 allowing(mockRequest).getParameterMap();
63  3 will(returnValue(params));
64  3 allowing(mockRequest).getRequestURL();
65  3 will(returnValue(new StringBuffer(TEST_URL)));
66  3 allowing(mockRequest).getParameter("srid");
67  3 will(returnValue("r4Nd0m"));
68    }});
69  3 final Map<String, SavedRequest> saveMap = new HashMap<String, SavedRequest>();
70  3 saveMap.put("r4Nd0m", new SavedRequest(mockRequest));
71    // session
 
72  3 toggle mockery.checking(new Expectations() {{
73  3 allowing(mockSession).getAttribute(with(any(String.class)));
74  3 will(returnValue(saveMap));
75    }});
76  3 this.request = mockRequest;
77    }
78   
 
79  1 toggle @Test
80    public void testGetters()
81    {
82  1 Assert.assertEquals("srid", SavedRequestManager.getSavedRequestIdentifier());
83  1 Assert.assertEquals(SavedRequest.class.getCanonicalName() + "_SavedRequests", SavedRequestManager.getSavedRequestKey());
84    }
85   
 
86  1 toggle @Test
87    public void testSave()
88    {
89  1 String srid = SavedRequestManager.saveRequest(this.request);
90  1 Assert.assertNotNull(srid);
91  1 Assert.assertFalse("".equals(srid));
92    }
93   
 
94  1 toggle @Test
95    public void testSavedUrl()
96    {
97  1 Assert.assertEquals(TEST_URL + "?srid=r4Nd0m", SavedRequestManager.getOriginalUrl(this.request));
98    }
99    }
100