001 // Copyright 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.annotations; 016 017 import org.apache.hivemind.ApplicationRuntimeException; 018 import org.apache.hivemind.Location; 019 import org.apache.tapestry.enhance.EnhancementOperation; 020 import org.apache.tapestry.spec.ComponentSpecification; 021 import org.apache.tapestry.spec.IComponentSpecification; 022 import org.testng.annotations.Test; 023 024 /** 025 * Tests for {@link org.apache.tapestry.annotations.ComponentClassAnnotationWorker}. 026 * 027 * @author Howard Lewis Ship 028 * @since 4.0 029 */ 030 @Test 031 public class TestComponentClassAnnotationWorker extends BaseAnnotationTestCase 032 { 033 private IComponentSpecification attempt(Class baseClass, Location location) 034 { 035 EnhancementOperation op = newOp(); 036 IComponentSpecification spec = new ComponentSpecification(); 037 038 replay(); 039 040 new ComponentClassAnnotationWorker().performEnhancement(op, spec, baseClass, location); 041 042 verify(); 043 044 return spec; 045 } 046 047 public void testBasic() 048 { 049 Location l = newLocation(); 050 IComponentSpecification spec = attempt(BasicComponent.class, l); 051 052 assertEquals(true, spec.getAllowBody()); 053 assertEquals(true, spec.getAllowInformalParameters()); 054 assertEquals(false, spec.isReservedParameterName("foo")); 055 assertEquals(false, spec.isReservedParameterName("bar")); 056 assertEquals(false, spec.isDeprecated()); 057 assertSame(l, spec.getLocation()); 058 } 059 060 public void testSubclass() 061 { 062 Location l = newLocation(); 063 IComponentSpecification spec = attempt(BasicComponentSubclass.class, l); 064 065 assertEquals(true, spec.getAllowBody()); 066 assertEquals(true, spec.getAllowInformalParameters()); 067 assertEquals(false, spec.isReservedParameterName("foo")); 068 assertEquals(false, spec.isReservedParameterName("bar")); 069 assertEquals(false, spec.isDeprecated()); 070 assertSame(l, spec.getLocation()); 071 } 072 073 public void testFormalOnly() 074 { 075 IComponentSpecification spec = attempt(FormalOnlyComponent.class, null); 076 077 assertEquals(false, spec.getAllowBody()); 078 assertEquals(false, spec.getAllowInformalParameters()); 079 assertEquals(false, spec.isDeprecated()); 080 } 081 082 public void testDeprecated() 083 { 084 IComponentSpecification spec = attempt(DeprecatedComponent.class, null); 085 086 assertEquals(true, spec.isDeprecated()); 087 } 088 089 public void testReservedParameters() 090 { 091 IComponentSpecification spec = attempt(ReservedParametersComponent.class, null); 092 093 assertEquals(true, spec.isReservedParameterName("foo")); 094 assertEquals(true, spec.isReservedParameterName("bar")); 095 } 096 097 public void testComponentClassNotAllowed() 098 { 099 EnhancementOperation op = newOp(); 100 IComponentSpecification spec = new ComponentSpecification(); 101 102 replay(); 103 104 try 105 { 106 new ComponentClassAnnotationWorker().performEnhancement( 107 op, spec, PageAnnotatedAsComponent.class, null); 108 unreachable(); 109 } 110 catch (ApplicationRuntimeException ex) 111 { 112 } 113 114 verify(); 115 } 116 }