001 // Copyright 2004, 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.junit.spec; 016 017 import org.apache.hivemind.ApplicationRuntimeException; 018 import org.apache.tapestry.junit.TapestryTestCase; 019 import org.apache.tapestry.spec.IApplicationSpecification; 020 import org.apache.tapestry.spec.IExtensionSpecification; 021 import org.testng.annotations.Test; 022 023 /** 024 * Tests related to {@link org.apache.tapestry.spec.ApplicationSpecification}. 025 * 026 * @author Howard Lewis Ship 027 * @since 2.2 028 */ 029 @Test 030 public class TestApplicationSpecification extends TapestryTestCase 031 { 032 033 public void testBasicExtension() throws Exception 034 { 035 IApplicationSpecification spec = parseApp("BasicExtension.application"); 036 037 PropertyBean extension = (PropertyBean) spec.getExtension("testBean"); 038 039 assertEquals(true, extension.getBooleanProperty()); 040 assertEquals(18, extension.getIntProperty()); 041 assertEquals(383838L, extension.getLongProperty()); 042 assertEquals(-3.14, extension.getDoubleProperty(), 0.0); 043 assertEquals("Tapestry: Java Web Components", extension 044 .getStringProperty()); 045 } 046 047 public void testExtensionType() throws Exception 048 { 049 IApplicationSpecification spec = parseApp("BasicExtension.application"); 050 051 PropertyBean extension = (PropertyBean) spec.getExtension("testBean", Object.class); 052 053 assertNotNull(extension); 054 } 055 056 public void testExtensionTypeFailClass() throws Exception 057 { 058 IApplicationSpecification spec = parseApp("BasicExtension.application"); 059 060 try 061 { 062 spec.getExtension("testBean", Number.class); 063 unreachable(); 064 } 065 catch (ApplicationRuntimeException ex) 066 { 067 checkException(ex, "does not inherit from class java.lang.Number"); 068 } 069 070 } 071 072 public void testExtensionProperty() throws Exception 073 { 074 IApplicationSpecification a = parseApp("ExtensionProperty.application"); 075 076 IExtensionSpecification e = a.getExtensionSpecification("testBean"); 077 078 assertEquals("flintstone", e.getProperty("fred")); 079 } 080 081 public void testImmediateExtension() throws Exception 082 { 083 assertEquals(0, ImmediateExtension.getInstanceCount()); 084 085 parseApp("ImmediateExtension.application"); 086 087 assertEquals( 1, ImmediateExtension.getInstanceCount()); 088 } 089 }