KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > junit > spec > TestApplicationSpecification


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.junit.spec;
16
17 import org.apache.hivemind.ApplicationRuntimeException;
18 import org.apache.tapestry.engine.IMonitor;
19 import org.apache.tapestry.junit.TapestryTestCase;
20 import org.apache.tapestry.spec.IApplicationSpecification;
21 import org.apache.tapestry.spec.IExtensionSpecification;
22
23 /**
24  * Tests related to {@link org.apache.tapestry.spec.ApplicationSpecification}.
25  *
26  * @author Howard Lewis Ship
27  * @since 2.2
28  */

29
30 public class TestApplicationSpecification extends TapestryTestCase
31 {
32
33     public void testBasicExtension() throws Exception JavaDoc
34     {
35         IApplicationSpecification spec = parseApp("BasicExtension.application");
36
37         PropertyBean extension = (PropertyBean) spec.getExtension("testBean");
38
39         assertEquals("booleanProperty", true, extension.getBooleanProperty());
40         assertEquals("intProperty", 18, extension.getIntProperty());
41         assertEquals("longProperty", 383838L, extension.getLongProperty());
42         assertEquals("doubleProperty", -3.14, extension.getDoubleProperty(), 0.0);
43         assertEquals("stringProperty", "Tapestry: Java Web Components", extension
44                 .getStringProperty());
45     }
46
47     public void testExtensionType() throws Exception JavaDoc
48     {
49         IApplicationSpecification spec = parseApp("BasicExtension.application");
50
51         PropertyBean extension = (PropertyBean) spec.getExtension("testBean", Object JavaDoc.class);
52
53         assertNotNull(extension);
54     }
55
56     public void testExtensionTypeFailClass() throws Exception JavaDoc
57     {
58         IApplicationSpecification spec = parseApp("BasicExtension.application");
59
60         try
61         {
62             spec.getExtension("testBean", Number JavaDoc.class);
63             unreachable();
64         }
65         catch (ApplicationRuntimeException ex)
66         {
67             checkException(ex, "does not inherit from class java.lang.Number");
68         }
69
70     }
71
72     public void testExtensionTypeFailInterface() throws Exception JavaDoc
73     {
74         IApplicationSpecification spec = parseApp("BasicExtension.application");
75
76         try
77         {
78             spec.getExtension("testBean", IMonitor.class);
79             unreachable();
80         }
81         catch (ApplicationRuntimeException ex)
82         {
83             checkException(ex, "does not implement interface org.apache.tapestry.engine.IMonitor");
84         }
85
86     }
87
88     public void testExtensionProperty() throws Exception JavaDoc
89     {
90         IApplicationSpecification a = parseApp("ExtensionProperty.application");
91
92         IExtensionSpecification e = a.getExtensionSpecification("testBean");
93
94         assertEquals("Property fred.", "flintstone", e.getProperty("fred"));
95     }
96
97     public void testImmediateExtension() throws Exception JavaDoc
98     {
99         assertEquals("instanceCount", 0, ImmediateExtension.getInstanceCount());
100
101         parseApp("ImmediateExtension.application");
102
103         assertEquals("instanceCount", 1, ImmediateExtension.getInstanceCount());
104     }
105 }
106
Popular Tags