001: /**
002: * Copyright 2006 Webmedia Group Ltd.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: **/package org.araneaframework.tests.integration;
016:
017: import junit.framework.TestCase;
018:
019: /**
020: * @author "Toomas Römer" <toomas@webmedia.ee>
021: * XXX: why is the whole test commented out?
022: */
023: public class SmokeTests extends TestCase {
024: /*private MockServlet servlet;
025: private ServletServiceAdapterComponent adapter;
026:
027: private Map initedAdapters = new HashMap();
028:
029: private MockHttpServletRequest req;
030: private MockHttpServletResponse resp;
031:
032: public SmokeTests(String name) {
033: super(name);
034: }
035:
036: public ServletServiceAdapterComponent initAdapter(String configFile) throws Exception {
037:
038: if (servlet == null ) {
039: servlet = new MockServlet();
040: }
041:
042: ServletServiceAdapterComponent comp =
043: (ServletServiceAdapterComponent)initedAdapters.get(configFile);
044:
045: if (comp == null) {
046: servlet.setConfFile(configFile);
047: servlet.init(new MockServletConfig(new MockServletContext()));
048:
049: initedAdapters.put(configFile, comp);
050:
051: return servlet.getBuiltComponent();
052: }
053:
054: return comp;
055: }
056:
057: public void setUp() throws Exception {
058: servlet = new MockServlet();
059:
060: req = new MockHttpServletRequest();
061: resp = new MockHttpServletResponse();
062: }
063:
064: public void testSmoke() throws Exception {
065: adapter = (ServletServiceAdapterComponent)initAdapter("smokeTest.xml");
066: adapter.service(req, resp);
067: //success if no exception thrown
068: fail();
069: }
070: //
071:
072: public void testSerialization() throws Exception {
073: adapter = (ServletServiceAdapterComponent)initAdapter("serializationTestsConf.xml");
074:
075: BeanFactory factory = servlet.getFactory();
076: MockViewPortWidget widget = (MockViewPortWidget)factory.getBean("rootWidget");
077: widget.setChild(new MockStandardWidget());
078: adapter.service(req, resp);
079: //success if no exception thrown
080: }
081:
082: public void testRepeatedRequestCatching() throws Exception {
083: String event = "theEvent";
084: String widgetKey =StandardViewPortWidget.CHILD_KEY;
085:
086: adapter = (ServletServiceAdapterComponent)initAdapter("repeatedRequest.xml");
087: // lets get reference to the bean doing the heavy-lifting
088: // its a singleton, so we're cool
089: BeanFactory factory = servlet.getFactory();
090: MockViewPortWidget widget = (MockViewPortWidget)factory.getBean("rootWidget");
091:
092: req.addParameter(StandardWidget.EVENT_HANDLER_ID_KEY, event);
093: req.addParameter(StandardContainerWidget.EVENT_PATH_KEY, widgetKey);
094:
095: // first request, transactionId will get intialized
096: adapter.service(req, resp);
097: // helper returns true on null transactionId
098:
099: MockEventfulStandardWidget child1 =
100: (MockEventfulStandardWidget)widget.getChildren().get(widgetKey);
101: req.addParameter(StandardTransactionFilterWidget.TRANSACTION_ID_KEY, ""+child1.getTransactionId());
102:
103: // second request with the valid transactionId
104: adapter.service(req, resp);
105:
106: assertTrue(child1.getEventProcessed());
107: child1.setEventProcessed(false);
108:
109: req.addParameter(StandardTransactionFilterWidget.TRANSACTION_ID_KEY, ""+child1.getTransactionId());
110: adapter.service(req, resp);
111: // transactionId used 2nd time, should not process the event
112: assertFalse(child1.getEventProcessed());
113: }
114:
115: public void testDestroyPropagates() throws Exception {
116: adapter = (ServletServiceAdapterComponent)initAdapter("repeatedRequest.xml");
117:
118: MockViewPortWidget widget = (MockViewPortWidget)servlet.getFactory().getBean("rootWidget");
119: // initializes everything
120: adapter.service(req, resp);
121: adapter._getComponent().destroy();
122:
123: MockEventfulStandardWidget child = (MockEventfulStandardWidget)widget.getChildren().get(StandardViewPortWidget.CHILD_KEY);
124: assertTrue(child.getDestroyCalled());
125: }
126:
127: public void testRequestRoutingComposite() throws Exception {
128:
129: String childKey = "aWidget";
130: String event = "tehEvent";
131:
132: adapter = (ServletServiceAdapterComponent)initAdapter("simpleFilters.xml");
133:
134: MockViewPortWidget widget = (MockViewPortWidget)servlet.getFactory().getBean("rootWidget");
135: MockStandardWidget childWidget = new MockStandardWidget();
136: childWidget.addEventListener(event, childWidget.new MockEventListener());
137:
138: widget.addWidget(childKey, childWidget);
139:
140: req.addParameter(StandardWidget.EVENT_HANDLER_ID_KEY, event);
141: req.addParameter(StandardContainerWidget.EVENT_PATH_KEY, childKey);
142: // initializes everything
143: adapter.service(req, resp);
144: adapter.service(req, resp);
145:
146: assertTrue(((MockStandardWidget)widget.getChildren().get(childKey)).getEventProcessed());
147: }
148:
149: public static Test suite() {
150: return new TestSuite(SmokeTests.class);
151: }
152:
153: public static void main(String args[]) {
154: junit.textui.TestRunner.run(suite());
155: }
156: */
157: }
|