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 static org.easymock.EasyMock.expect; 018 019 import java.util.Collections; 020 021 import org.apache.hivemind.ApplicationRuntimeException; 022 import org.apache.tapestry.enhance.EnhancementOperation; 023 import org.apache.tapestry.spec.BindingSpecification; 024 import org.apache.tapestry.spec.ComponentSpecification; 025 import org.apache.tapestry.spec.ContainedComponent; 026 import org.apache.tapestry.spec.IComponentSpecification; 027 import org.apache.tapestry.spec.IContainedComponent; 028 import org.testng.annotations.Test; 029 030 /** 031 * Tests for {@link org.apache.tapestry.annotations.ComponentHousekeepingWorker}. 032 * 033 * @author Andreas Andreou 034 * @since 4.1.1 035 */ 036 @Test 037 public class TestComponentHousekeepingWorker extends BaseAnnotationTestCase 038 { 039 public void test_No_Components() 040 { 041 EnhancementOperation op = newOp(); 042 IComponentSpecification spec = newSpec(); 043 expect(spec.getComponentIds()).andReturn(Collections.EMPTY_LIST); 044 045 replay(); 046 047 new ComponentHousekeepingWorker().performEnhancement(op, spec); 048 049 verify(); 050 } 051 052 public void test_Unable_To_Copy() 053 { 054 IComponentSpecification spec = new ComponentSpecification(); 055 056 IContainedComponent ccOne = new ContainedComponent(); 057 ccOne.setType("Insert"); 058 spec.addComponent("time", ccOne); 059 060 IContainedComponent ccTwo = new ContainedComponent(); 061 ccTwo.setCopyOf("date"); 062 spec.addComponent("invalid", ccTwo); 063 064 try 065 { 066 new ComponentHousekeepingWorker().performEnhancement(null, spec); 067 unreachable(); 068 } 069 catch (ApplicationRuntimeException ex) 070 { 071 assertExceptionSubstring(ex, "Unable to copy"); 072 } 073 } 074 075 public void test_CopyOf_Valid() 076 { 077 IComponentSpecification spec = new ComponentSpecification(); 078 079 IContainedComponent ccOne = new ContainedComponent(); 080 ccOne.setType("Insert"); 081 ccOne.setBinding("value", new BindingSpecification()); 082 spec.addComponent("time", ccOne); 083 084 085 IContainedComponent ccTwo = new ContainedComponent(); 086 ccTwo.setCopyOf("time"); 087 spec.addComponent("valid", ccTwo); 088 assertNull( ccTwo.getBinding("value") ); 089 090 new ComponentHousekeepingWorker().performEnhancement(null, spec); 091 092 IContainedComponent result = spec.getComponent("valid"); 093 assertEquals(result, ccTwo); 094 assertNotNull( result.getBinding("value") ); 095 } 096 097 }