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.framework.container;
16:
17: import java.util.HashMap;
18: import java.util.Map;
19: import junit.framework.TestCase;
20: import org.araneaframework.InputData;
21: import org.araneaframework.Path;
22: import org.araneaframework.core.ApplicationService;
23: import org.araneaframework.framework.container.StandardWidgetAdapterService;
24: import org.araneaframework.mock.MockInputData;
25: import org.araneaframework.mock.MockLifeCycle;
26: import org.araneaframework.mock.MockUtil;
27: import org.araneaframework.mock.core.MockEventfulStandardWidget;
28:
29: /**
30: * @author "Toomas Römer" <toomas@webmedia.ee>
31: */
32: public class StandardWidgetAdapterServiceTests extends TestCase {
33: private StandardWidgetAdapterService adapter;
34: private MockEventfulStandardWidget widget;
35:
36: public void setUp() throws Exception {
37: widget = new MockEventfulStandardWidget();
38:
39: adapter = new StandardWidgetAdapterService();
40: adapter.setChildWidget(widget);
41: MockLifeCycle.begin(adapter);
42: }
43:
44: public void testActionUpdatesEventsRendersOnSecondRequest()
45: throws Exception {
46: adapter._getService().action(MockUtil.getPath(),
47: MockUtil.getInput(), MockUtil.getOutput());
48: adapter._getService().action(MockUtil.getPath(),
49: MockUtil.getInput(), MockUtil.getOutput());
50:
51: assertTrue(widget.getUpdateCalled());
52: assertTrue(!widget.getEventProcessed());
53: assertTrue(widget.getRenderCalled());
54:
55: assertFalse(widget.getActionCalled());
56: }
57:
58: public void testDoesNotActionUpdatesEventsRendersOnFirstRequest()
59: throws Exception {
60: Map globalData = new HashMap();
61: globalData.put(ApplicationService.ACTION_PATH_KEY, "");
62: MockInputData input = new MockInputData(globalData);
63: adapter._getService().action(MockUtil.getPath(), input,
64: MockUtil.getOutput());
65:
66: assertTrue(widget.getActionCalled());
67: assertFalse(widget.getUpdateCalled());
68: assertFalse(widget.getEventProcessed());
69: assertFalse(widget.getRenderCalled());
70: }
71:
72: public void testActionPropagates() throws Exception {
73: adapter = new StandardWidgetAdapterService() {
74: protected boolean hasAction(InputData input) {
75: return true;
76: }
77:
78: protected Path getActionPath(InputData input) {
79: return null;
80: }
81: };
82: widget = new MockEventfulStandardWidget();
83: adapter.setChildWidget(widget);
84: MockLifeCycle.begin(adapter);
85:
86: adapter._getService().action(MockUtil.getPath(),
87: MockUtil.getInput(), MockUtil.getOutput());
88:
89: assertTrue(widget.getActionCalled());
90: }
91:
92: public void testDestroyDestroysChild() throws Exception {
93: adapter._getComponent().destroy();
94: assertTrue(widget.getDestroyCalled());
95: }
96: }
|