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.IComponentSpecification; 021 import org.testng.annotations.Test; 022 023 /** 024 * Test case for {@link org.apache.tapestry.annotations.MetaAnnotationWorker}. 025 * 026 * @author Howard M. Lewis Ship 027 * @since 4.0 028 */ 029 @Test 030 public class MetaAnnotationWorkerTest extends BaseAnnotationTestCase 031 { 032 033 public void testMeta() 034 { 035 EnhancementOperation op = newOp(); 036 IComponentSpecification spec = newSpec(); 037 Location l = newLocation(); 038 039 spec.setProperty("foo", "bar"); 040 spec.setProperty("biff", "bazz"); 041 042 replay(); 043 044 new MetaAnnotationWorker().performEnhancement(op, spec, MetaPage.class, l); 045 046 verify(); 047 } 048 049 public void testMetaInSubclass() 050 { 051 EnhancementOperation op = newOp(); 052 IComponentSpecification spec = newSpec(); 053 Location l = newLocation(); 054 055 // From MetaPage 056 spec.setProperty("foo", "bar"); 057 spec.setProperty("biff", "bazz"); 058 059 // From MetaPageSubclass 060 spec.setProperty("in-subclass", "true"); 061 062 replay(); 063 064 new MetaAnnotationWorker().performEnhancement(op, spec, MetaPageSubclass.class, l); 065 066 verify(); 067 068 } 069 070 public void testNoEqualsSign() 071 { 072 EnhancementOperation op = newOp(); 073 IComponentSpecification spec = newSpec(); 074 Location l = newLocation(); 075 076 replay(); 077 078 MetaAnnotationWorker worker = new MetaAnnotationWorker(); 079 080 try 081 { 082 worker.performEnhancement(op, spec, MissingEqualsMetaPage.class, l); 083 } 084 catch (ApplicationRuntimeException ex) 085 { 086 assertEquals( 087 "The meta value 'noequals' must include an equals sign to seperate the key and the value.", 088 ex.getMessage()); 089 assertSame(l, ex.getLocation()); 090 } 091 092 verify(); 093 094 } 095 }