01: /**
02: * Copyright 2006-2007 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.component;
16:
17: import junit.framework.TestCase;
18: import org.araneaframework.Component;
19: import org.araneaframework.core.BaseApplicationWidget;
20: import org.araneaframework.core.BaseComponent;
21: import org.araneaframework.core.BaseWidget;
22: import org.araneaframework.core.BroadcastMessage;
23: import org.araneaframework.mock.MockInputData;
24: import org.araneaframework.mock.MockOutputData;
25: import org.araneaframework.tests.mock.MockEnvironment;
26:
27: /**
28: * {@link Component} lifecycle constraint satisfiability.
29: * @author Taimo Peelo (taimo@araneaframework.org)
30: */
31: public class LifeCycleTests extends TestCase {
32: // tests that dead component stays dead
33: public void testPermantentDeath() throws Exception {
34: BaseComponent c = new BaseComponent() {
35: };
36:
37: c._getComponent().init(null, new MockEnvironment());
38: c._getComponent().destroy();
39:
40: try {
41: c._getComponent().init(null, new MockEnvironment());
42:
43: fail("Attempted to reanimate destroyed Component -- exception should have occured.");
44: } catch (Exception e) {
45: // good
46: }
47: }
48:
49: // invalid leftover calls are those that activate the methods that directly
50: // depend on request or response
51: public void testInvalidLeftOverCalls() throws Exception {
52: BaseWidget w = new BaseWidget() {
53: };
54: w._getComponent().init(null, new MockEnvironment());
55: w._getComponent().destroy();
56:
57: try {
58: w._getComponent().destroy();
59: fail("Double destroy() is prohibited.");
60: } catch (IllegalStateException e) {
61: // fine
62: }
63: }
64:
65: // all leftover calls are considered valid
66: public void testValidLeftOverCalls() throws Exception {
67: BaseApplicationWidget w = new BaseApplicationWidget() {
68: };
69: w._getComponent().init(null, new MockEnvironment());
70: w._getComponent().destroy();
71:
72: w._getComponent().propagate(new BroadcastMessage() {
73: protected void execute(Component component)
74: throws Exception {
75: return;
76: }
77: });
78:
79: w.addWidget("new", new BaseApplicationWidget() {
80: });
81: w.removeWidget("new");
82:
83: w._getComponent().disable();
84: w._getComponent().enable();
85:
86: w._getService().action(null, new MockInputData(),
87: new MockOutputData());
88:
89: w._getWidget().update(new MockInputData());
90: w._getWidget().event(null, new MockInputData());
91: w._getWidget().render(new MockOutputData());
92: }
93: }
|