001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tctest.wicket;
005:
006: import java.util.Collections;
007: import java.util.Date;
008:
009: import junit.framework.Test;
010:
011: import org.apache.commons.logging.LogFactory;
012: import org.apache.log4j.Logger;
013: import org.apache.wicket.Page;
014: import org.apache.wicket.markup.html.WebPage;
015: import org.apache.wicket.markup.html.basic.Label;
016: import org.apache.wicket.markup.html.link.Link;
017: import org.apache.wicket.model.PropertyModel;
018: import org.apache.wicket.protocol.http.WebApplication;
019: import org.apache.wicket.protocol.http.WicketServlet;
020:
021: import com.meterware.httpunit.WebConversation;
022: import com.meterware.httpunit.WebLink;
023: import com.meterware.httpunit.WebResponse;
024: import com.tc.test.server.appserver.deployment.AbstractTwoServerDeploymentTest;
025: import com.tc.test.server.appserver.deployment.DeploymentBuilder;
026: import com.tc.test.server.appserver.deployment.WebApplicationServer;
027: import com.tc.test.server.util.TcConfigBuilder;
028: import com.tc.util.TIMUtil;
029: import com.tc.util.runtime.Vm;
030:
031: /**
032: * An in-container smoke test for Wicket framework
033: *
034: * @author Eugene Kuleshov
035: */
036: public class ContainerWicketTest extends
037: AbstractTwoServerDeploymentTest {
038: private static final String CONFIG_FILE_FOR_TEST = "/tc-config-files/wicket-tc-config.xml";
039:
040: public static Test suite() {
041: return new ContainerWicketTestSetup();
042: }
043:
044: public ContainerWicketTest() {
045: if (Vm.isIBM()) {
046: this .disableAllUntil(new Date(Long.MAX_VALUE));
047: }
048: }
049:
050: public boolean shouldDisable() {
051: return super .shouldDisable() || Vm.isIBM();
052: }
053:
054: public void testWicketInitialization() throws Exception {
055:
056: WebConversation webConversation1 = new WebConversation();
057:
058: WebResponse response1 = request(server0, webConversation1, "");
059: WebLink[] links1 = response1.getLinks();
060: assertEquals(1, links1.length);
061: assertEquals("Action link clicked 0 times", links1[0].getText());
062:
063: WebResponse response2 = request(server0, webConversation1,
064: links1[0].getURLString());
065: WebLink[] links2 = response2.getLinks();
066: assertEquals(1, links2.length);
067: assertEquals("Action link clicked 1 times", links2[0].getText());
068:
069: WebResponse response3 = request(server1, webConversation1, "?"
070: + response2.getURL().getQuery());
071: WebLink[] links3 = response3.getLinks();
072: assertEquals(1, links3.length);
073: assertEquals("Action link clicked 1 times", links3[0].getText());
074:
075: WebResponse response4 = request(server1, webConversation1,
076: links3[0].getURLString());
077: WebLink[] links4 = response4.getLinks();
078: assertEquals(1, links4.length);
079: assertEquals("Action link clicked 2 times", links4[0].getText());
080:
081: WebResponse response5 = request(server0, webConversation1, "?"
082: + response4.getURL().getQuery());
083: WebLink[] links5 = response5.getLinks();
084: assertEquals(1, links5.length);
085: assertEquals("Action link clicked 2 times", links5[0].getText());
086:
087: }
088:
089: private WebResponse request(WebApplicationServer server,
090: WebConversation conversation, String params)
091: throws Exception {
092: return server.ping("/wicket-test/clickcounter/" + params,
093: conversation);
094: }
095:
096: private static class ContainerWicketTestSetup extends
097: TwoServerTestSetup {
098: private ContainerWicketTestSetup() {
099: super (ContainerWicketTest.class, CONFIG_FILE_FOR_TEST,
100: "wicket-test");
101: }
102:
103: protected void configureWar(DeploymentBuilder builder) {
104: // builder.addBeanDefinitionFile(BEAN_DEFINITION_FILE_FOR_TEST);
105: // builder.addRemoteService(REMOTE_SERVICE_NAME, "singleton",
106: // ISingleton.class);
107:
108: builder.addDirectoryOrJARContainingClass(Page.class); // wicket*.jar
109: builder.addDirectoryOrJARContainingClass(Logger.class); // log4j
110: builder.addDirectoryOrJARContainingClass(LogFactory.class); // common-loggings
111: builder
112: .addDirectoryContainingResource("/com/tctest/wicket/ContainerWicketTest$ClickCounter.html");
113:
114: builder.addServlet("ClickCounter", "/clickcounter/*",
115: WicketServlet.class, Collections.singletonMap(
116: "applicationClassName",
117: ClickCounterApp.class.getName()), true);
118: }
119:
120: protected void configureTcConfig(TcConfigBuilder clientConfig) {
121: clientConfig.addModule(TIMUtil.WICKET_1_3, TIMUtil
122: .getVersion(TIMUtil.WEBSPHERE_6_1_0_7));
123: }
124:
125: }
126:
127: public static final class ClickCounterApp extends WebApplication {
128: public Class getHomePage() {
129: return ClickCounter.class;
130: }
131: }
132:
133: public static class ClickCounter extends WebPage {
134: private static final long serialVersionUID = 1L;
135:
136: private int linkClickCount;
137:
138: public ClickCounter() {
139: final Link actionLink = new Link("actionLink") {
140: private static final long serialVersionUID = 1L;
141:
142: public void onClick() {
143: linkClickCount++;
144: }
145: };
146: actionLink.add(new Label("linkClickCount",
147: new PropertyModel(this , "linkClickCount")));
148: add(actionLink);
149: }
150: }
151:
152: }
|