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.components; 016 017 import org.apache.tapestry.*; 018 import org.apache.tapestry.spec.ComponentSpecification; 019 import static org.easymock.EasyMock.expect; 020 import org.testng.annotations.Test; 021 022 /** 023 * Tests for the {@link org.apache.tapestry.components.Any} component. 024 * 025 */ 026 @Test 027 public class TestAny extends BaseComponentTestCase 028 { 029 030 public void testRender() 031 { 032 IMarkupWriter writer = newWriter(); 033 IRequestCycle cycle = newCycle(false, writer); 034 035 Any any = newInstance(Any.class, new Object[] { "templateTagName", "span" }); 036 037 expect(cycle.renderStackPush(any)).andReturn(any); 038 039 writer.begin("span"); 040 041 IRender body = newRender(); 042 body.render(writer, cycle); 043 044 writer.end(); 045 046 expect(cycle.renderStackPop()).andReturn(any); 047 048 replay(); 049 050 any.addBody(body); 051 052 any.render(writer, cycle); 053 054 verify(); 055 } 056 057 public void testRenderWithInformalParameters() 058 { 059 IMarkupWriter writer = newWriter(); 060 IRequestCycle cycle = newCycle(false, writer); 061 IRender body = newRender(); 062 IBinding binding = newBinding("fred"); 063 064 Any any = newInstance(Any.class, "templateTagName", "span", "specification", new ComponentSpecification()); 065 066 expect(cycle.renderStackPush(any)).andReturn(any); 067 068 writer.begin("span"); 069 writer.attribute("class", "fred"); 070 071 body.render(writer, cycle); 072 073 writer.end(); 074 075 expect(cycle.renderStackPop()).andReturn(any); 076 077 replay(); 078 079 any.addBody(body); 080 any.setBinding("class", binding); 081 082 any.render(writer, cycle); 083 084 verify(); 085 } 086 087 public void testRewind() 088 { 089 IMarkupWriter writer = newWriter(); 090 IRequestCycle cycle = newCycle(true, writer); 091 IRender body = newRender(); 092 093 Any any = newInstance(Any.class, new Object[] { "templateTagName", "span" }); 094 095 expect(cycle.renderStackPush(any)).andReturn(any); 096 097 body.render(writer, cycle); 098 099 expect(cycle.renderStackPop()).andReturn(any); 100 101 replay(); 102 103 any.addBody(body); 104 105 any.render(writer, cycle); 106 107 verify(); 108 } 109 }