001: /*
002: * $Id: SortableTableHeadersTest.java 461192 2006-06-28 06:37:16Z ehillenius $
003: * $Revision: 461192 $ $Date: 2006-06-28 08:37:16 +0200 (Wed, 28 Jun 2006) $
004: *
005: * ==================================================================== Licensed
006: * under the Apache License, Version 2.0 (the "License"); you may not use this
007: * file except in compliance with the License. You may obtain a copy of the
008: * License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
014: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
015: * License for the specific language governing permissions and limitations under
016: * the License.
017: */
018: package wicket.examples.displaytag.list;
019:
020: import org.apache.commons.logging.Log;
021: import org.apache.commons.logging.LogFactory;
022:
023: import wicket.examples.WicketTestCase;
024: import wicket.markup.html.link.Link;
025: import wicket.protocol.http.MockHttpServletResponse;
026: import wicket.protocol.http.MockWebApplication;
027: import wicket.settings.IRequestCycleSettings;
028: import wicket.util.diff.DiffUtil;
029:
030: /**
031: * Test for simple table behavior.
032: */
033: public class SortableTableHeadersTest extends WicketTestCase {
034: private static final Log log = LogFactory
035: .getLog(SortableTableHeadersTest.class);
036:
037: /**
038: * Construct.
039: *
040: * @param name
041: * name of test
042: */
043: public SortableTableHeadersTest(String name) {
044: super (name);
045: }
046:
047: /**
048: * Test simple table behavior.
049: *
050: * @throws Exception
051: */
052: public void testPagedTable() throws Exception {
053: MockWebApplication application = new MockWebApplication(null);
054: application.getRequestCycleSettings().setRenderStrategy(
055: IRequestCycleSettings.REDIRECT_TO_BUFFER);
056: application.setHomePage(SortableTableHeadersPage.class);
057: application.setupRequestAndResponse();
058: application.processRequestCycle();
059: SortableTableHeadersPage page = (SortableTableHeadersPage) application
060: .getLastRenderedPage();
061: String document = application.getServletResponse()
062: .getDocument();
063: assertTrue(DiffUtil.validatePage(document, this .getClass(),
064: "SortableTableHeadersExpectedResult_1.html"));
065:
066: Link link = (Link) page.get("header:id:actionLink");
067: assertTrue(link.isEnabled());
068:
069: link = (Link) page.get("header:name:actionLink");
070: assertTrue(link.isEnabled());
071:
072: link = (Link) page.get("header:email:actionLink");
073: assertNull(link);
074:
075: link = (Link) page.get("header:name:actionLink");
076: application.setupRequestAndResponse();
077: application.getServletRequest().setRequestToComponent(link);
078: application.processRequestCycle();
079:
080: // Check that redirect was set as expected and invoke it
081: MockHttpServletResponse redirectResponse = application
082: .getServletResponse();
083:
084: assertTrue("Response should be a redirect", redirectResponse
085: .isRedirect());
086: String redirect = application.getServletResponse()
087: .getRedirectLocation();
088: application.setupRequestAndResponse();
089: application.getServletRequest().setRequestToRedirectString(
090: redirect);
091: application.processRequestCycle();
092:
093: document = application.getServletResponse().getDocument();
094: assertTrue(DiffUtil.validatePage(document, this .getClass(),
095: "SortableTableHeadersExpectedResult_2.html"));
096:
097: // reverse sorting
098: link = (Link) page.get("header:name:actionLink");
099: application.setupRequestAndResponse();
100: application.getServletRequest().setRequestToComponent(link);
101: application.processRequestCycle();
102:
103: // Check that redirect was set as expected and invoke it
104: // Check that wicket:border tag gets removed
105: assertTrue("Response should be a redirect", application
106: .getServletResponse().isRedirect());
107: application.getMarkupSettings().setStripWicketTags(true);
108: redirect = application.getServletResponse()
109: .getRedirectLocation();
110: application.setupRequestAndResponse();
111: application.getServletRequest().setRequestToRedirectString(
112: redirect);
113: application.processRequestCycle();
114:
115: document = application.getServletResponse().getDocument();
116: assertTrue(DiffUtil.validatePage(document, this .getClass(),
117: "SortableTableHeadersExpectedResult_3.html"));
118: }
119: }
|