1 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 29 30 public class TestApplicationSpecification extends TapestryTestCase 31 { 32 33 public void testBasicExtension() throws Exception 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 48 { 49 IApplicationSpecification spec = parseApp("BasicExtension.application"); 50 51 PropertyBean extension = (PropertyBean) spec.getExtension("testBean", Object .class); 52 53 assertNotNull(extension); 54 } 55 56 public void testExtensionTypeFailClass() throws Exception 57 { 58 IApplicationSpecification spec = parseApp("BasicExtension.application"); 59 60 try 61 { 62 spec.getExtension("testBean", Number .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 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 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 98 { 99 assertEquals("instanceCount", 0, ImmediateExtension.getInstanceCount()); 100 101 parseApp("ImmediateExtension.application"); 102 103 assertEquals("instanceCount", 1, ImmediateExtension.getInstanceCount()); 104 } 105 } 106 | Popular Tags |