001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.test.theme;
023:
024: import org.jboss.mx.util.MBeanProxy;
025: import org.jboss.mx.util.MBeanServerLocator;
026: import org.jboss.portal.test.framework.driver.TestDriverContainer;
027: import org.jboss.portal.test.theme.dyna.tests.dnd.DnDTest;
028: import org.jboss.portal.test.theme.model.WindowObject;
029:
030: import javax.management.MBeanServer;
031: import javax.management.ObjectName;
032: import javax.servlet.ServletException;
033: import javax.servlet.http.HttpServlet;
034: import javax.servlet.http.HttpServletRequest;
035: import javax.servlet.http.HttpServletResponse;
036: import java.io.IOException;
037:
038: /** @author <a href="mailto:roy@jboss.org">Roy Russo</a> */
039:
040: public class TestServlet extends HttpServlet {
041:
042: /** . */
043: private TestDriverContainer testServer;
044:
045: /** . */
046: DynaTestContext testContext;
047:
048: public void init() throws ServletException {
049: try {
050: MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
051: testServer = (TestDriverContainer) MBeanProxy.get(
052: TestDriverContainer.class, new ObjectName(
053: "portal.test:service=TestDriverServer"),
054: mbeanServer);
055:
056: // addTest(new LinkPartialRefreshWindowTest("A", Boolean.TRUE, Boolean.TRUE, true));
057: // addTest(new LinkPartialRefreshWindowTest("B", Boolean.TRUE, Boolean.FALSE, false));
058: // addTest(new LinkPartialRefreshWindowTest("C", Boolean.TRUE, null, true));
059: // addTest(new LinkPartialRefreshWindowTest("D", Boolean.FALSE, Boolean.TRUE, false));
060: // addTest(new LinkPartialRefreshWindowTest("E", Boolean.FALSE, Boolean.FALSE, false));
061: // addTest(new LinkPartialRefreshWindowTest("F", Boolean.FALSE, null, false));
062: // addTest(new LinkPartialRefreshWindowTest("G", null, Boolean.TRUE, true));
063: // addTest(new LinkPartialRefreshWindowTest("H", null, Boolean.FALSE, false));
064: // addTest(new LinkPartialRefreshWindowTest("I", null, null, false));
065:
066: // todo use test parametrization
067: // addTest(new FormPartialRefreshWindowTest("A", Boolean.TRUE, Boolean.TRUE, true));
068: // addTest(new FormPartialRefreshWindowTest("B", Boolean.TRUE, Boolean.FALSE, false));
069: // addTest(new FormPartialRefreshWindowTest("C", Boolean.TRUE, null, true));
070: // addTest(new FormPartialRefreshWindowTest("D", Boolean.FALSE, Boolean.TRUE, false));
071: // addTest(new FormPartialRefreshWindowTest("E", Boolean.FALSE, Boolean.FALSE, false));
072: // addTest(new FormPartialRefreshWindowTest("F", Boolean.FALSE, null, false));
073: // addTest(new FormPartialRefreshWindowTest("G", null, Boolean.TRUE, true));
074: // addTest(new FormPartialRefreshWindowTest("H", null, Boolean.FALSE, false));
075: // addTest(new FormPartialRefreshWindowTest("I", null, null, false));
076:
077: // addTest(new FormGetRefreshIsNotPartialWindowTest("A", Boolean.TRUE, Boolean.TRUE));
078: // addTest(new FormGetRefreshIsNotPartialWindowTest("B", Boolean.TRUE, Boolean.FALSE));
079: // addTest(new FormGetRefreshIsNotPartialWindowTest("C", Boolean.TRUE, null));
080: // addTest(new FormGetRefreshIsNotPartialWindowTest("D", Boolean.FALSE, Boolean.TRUE));
081: // addTest(new FormGetRefreshIsNotPartialWindowTest("E", Boolean.FALSE, Boolean.FALSE));
082: // addTest(new FormGetRefreshIsNotPartialWindowTest("F", Boolean.FALSE, null));
083: // addTest(new FormGetRefreshIsNotPartialWindowTest("G", null, Boolean.TRUE));
084: // addTest(new FormGetRefreshIsNotPartialWindowTest("H", null, Boolean.FALSE));
085: // addTest(new FormGetRefreshIsNotPartialWindowTest("I", null, null));
086:
087: addTest(new DnDTest("A"));
088: } catch (Exception e) {
089: throw new ServletException(e);
090: }
091: }
092:
093: private void addTest(DynaTest dynaTest) throws Exception {
094: testServer.addDriver(new DynaTestContext(this , dynaTest,
095: "http://localhost:8080/theme-test/selenium/invoke/"));
096: }
097:
098: /** Generates a portal page with windows, using the theme api. */
099: protected void service(HttpServletRequest request,
100: HttpServletResponse response) throws ServletException,
101: IOException {
102: try {
103: proceed(request, response);
104: } catch (Exception e) {
105: throw new ServletException(e);
106: }
107: }
108:
109: public void proceed(HttpServletRequest request,
110: HttpServletResponse response) throws Exception {
111: String pathInfo = request.getPathInfo();
112: if (pathInfo != null) {
113: if (pathInfo.startsWith("/window/")) {
114: String windowId = pathInfo.substring("/window/"
115: .length());
116: WindowObject window = testContext.getPage().getWindow(
117: windowId);
118: TestPhase phase = TestPhase.createAction(testContext
119: .getRequestCount());
120: RequestContext requestContext = new RequestContext(
121: window, phase, request, response);
122: testContext.invoke(requestContext);
123: } else if ("/ajax".equals(pathInfo)) {
124: TestPhase phase = TestPhase.createAjax(testContext
125: .getRequestCount());
126: RequestContext requestContext = new RequestContext(
127: null, phase, request, response);
128: testContext.invoke(requestContext);
129: }
130: }
131:
132: //
133: TestPhase phase = TestPhase.createRender(testContext
134: .getRequestCount());
135: RequestContext requestContext = new RequestContext(null, phase,
136: request, response);
137: testContext.invoke(requestContext);
138: }
139: }
|