01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: **/package org.araneaframework.tests.mock;
16:
17: import javax.servlet.http.HttpServletRequest;
18: import org.araneaframework.Widget;
19: import org.araneaframework.core.ApplicationWidget;
20: import org.araneaframework.core.StandardPath;
21: import org.araneaframework.http.core.StandardServletInputData;
22: import org.springframework.mock.web.MockHttpServletRequest;
23:
24: public class MockUiLibUtil {
25: public static void emulateHandleEvent(Widget widget,
26: String eventId, String eventParameter) throws Exception {
27: MockHttpServletRequest request = new MockHttpServletRequest();
28:
29: String eventPath = "";
30: String eventListenerId = eventId;
31:
32: int lastDot = eventId.lastIndexOf(".");
33:
34: if (lastDot != -1) {
35: eventPath = eventId.substring(0, lastDot);
36: eventListenerId = eventId.substring(lastDot + 1);
37: }
38:
39: request.addParameter(ApplicationWidget.EVENT_PARAMETER_KEY,
40: eventParameter);
41: request.addParameter(ApplicationWidget.EVENT_HANDLER_ID_KEY,
42: eventListenerId);
43: StandardServletInputData input = new StandardServletInputData(
44: request);
45:
46: widget._getWidget().event(new StandardPath(eventPath), input);
47: }
48:
49: public static void emulateHandleEventForControl(Widget widget,
50: String eventId, String eventParameter) throws Exception {
51: MockHttpServletRequest request = new MockHttpServletRequest();
52:
53: request.addParameter(ApplicationWidget.EVENT_PARAMETER_KEY,
54: eventParameter);
55: StandardServletInputData input = new StandardServletInputData(
56: request);
57:
58: widget._getWidget().event(new StandardPath(eventId), input);
59: }
60:
61: public static void emulateHandleRequest(Widget widget,
62: String widgetId, HttpServletRequest request)
63: throws Exception {
64: StandardServletInputData input = new StandardServletInputData(
65: request);
66:
67: widget._getWidget().update(input);
68: }
69: }
|