1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.portletbridge.portlet;
17  
18  import java.io.IOException;
19  import java.net.URI;
20  import java.net.URISyntaxException;
21  import java.net.URL;
22  
23  import javax.servlet.ServletException;
24  
25  import junit.framework.TestCase;
26  
27  import org.portletbridge.mock.MockHttpClientTemplate;
28  import org.portletbridge.mock.MockHttpServletRequest;
29  import org.portletbridge.mock.MockHttpServletResponse;
30  import org.portletbridge.mock.MockHttpSession;
31  import org.portletbridge.mock.MockPerPortletMemento;
32  import org.portletbridge.mock.MockPortletBridgeMemento;
33  import org.portletbridge.mock.MockServletConfig;
34  import org.portletbridge.mock.MockServletContext;
35  
36  /***
37   * @author JMcCrindle
38   */
39  public class PortletBridgeServletTest extends TestCase {
40  
41      /*
42       * @see TestCase#setUp()
43       */
44      protected void setUp() throws Exception {
45          super.setUp();
46      }
47  
48      /*
49       * @see TestCase#tearDown()
50       */
51      protected void tearDown() throws Exception {
52          super.tearDown();
53      }
54  
55      /***
56       * Constructor for PortletBridgeServletTest.
57       * @param name
58       */
59      public PortletBridgeServletTest(String name) {
60          super(name);
61      }
62  
63      /*
64       * Class under test for void doGet(HttpServletRequest, HttpServletResponse)
65       */
66      public void testDoGetHttpServletRequestHttpServletResponse() throws ServletException, IOException, URISyntaxException {
67          PortletBridgeServlet servlet = new PortletBridgeServlet();
68          MockServletConfig config = new MockServletConfig();
69          config.setupParam("mementoSessionKey", "mementoSessionKey");
70          config.setupContext(new MockServletContext());
71          servlet.init(config);
72          MockHttpServletRequest request = new MockHttpServletRequest();
73          request.setupContextPath("");
74          request.setupUrl(new URL("http://www.test.com/blah/123/"));
75          MockHttpSession session = new MockHttpSession();
76          MockPortletBridgeMemento memento = new MockPortletBridgeMemento();
77          memento.setupBridgeRequest("123", new DefaultBridgeRequest("1", "portletid", "pageurl", new URI("http://www.bob.com")));
78          memento.setupMemento("portletid", new MockPerPortletMemento());
79          session.setAttribute("mementoSessionKey", memento);
80          request.setupSession(session);
81          MockHttpClientTemplate mockHttpClientTemplate = new MockHttpClientTemplate();
82          mockHttpClientTemplate.setupResponseHeader("Content-Type", "text/html");
83          servlet.setHttpClientTemplate(mockHttpClientTemplate);
84          servlet.doGet(request, new MockHttpServletResponse());
85      }
86  
87      public void testUrl() throws Exception {
88          URL url = new URL("http://www.test.com/blah/blah.html?test=one");
89          assertEquals("/blah/blah.html", url.getPath());
90      }
91  
92  }