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.html; 016 017 import static org.easymock.EasyMock.expect; 018 019 import org.apache.tapestry.BaseComponentTestCase; 020 import org.apache.tapestry.IMarkupWriter; 021 import org.apache.tapestry.IRequestCycle; 022 import org.testng.annotations.Test; 023 024 /** 025 * Tests for {@link org.apache.tapestry.html.InsertText}. 026 * 027 * @author Howard M. Lewis Ship 028 * @since 4.0 029 */ 030 @Test 031 public class TestInsertText extends BaseComponentTestCase 032 { 033 public void testRewinding() 034 { 035 IMarkupWriter writer = newWriter(); 036 IRequestCycle cycle = newCycle(true); 037 038 InsertText component = (InsertText) newInstance(InsertText.class); 039 040 expect(cycle.renderStackPush(component)).andReturn(component); 041 042 expect(cycle.renderStackPop()).andReturn(component); 043 044 replay(); 045 046 component.render(writer, cycle); 047 048 verify(); 049 } 050 051 public void testRenderNull() 052 { 053 IMarkupWriter writer = newWriter(); 054 IRequestCycle cycle = newCycle(false); 055 056 InsertText component = (InsertText) newInstance(InsertText.class); 057 058 expect(cycle.renderStackPush(component)).andReturn(component); 059 060 expect(cycle.renderStackPop()).andReturn(component); 061 062 replay(); 063 064 component.render(writer, cycle); 065 066 verify(); 067 } 068 069 public void testRenderBreaks() 070 { 071 IMarkupWriter writer = newWriter(); 072 IRequestCycle cycle = newCycle(false); 073 074 InsertText component = (InsertText) newInstance( 075 InsertText.class, 076 "value", 077 "Now is the time\nfor all good men\nto come to the aid of their Tapestry."); 078 079 expect(cycle.renderStackPush(component)).andReturn(component); 080 081 writer.print("Now is the time", false); 082 writer.beginEmpty("br"); 083 writer.print("for all good men", false); 084 writer.beginEmpty("br"); 085 writer.print("to come to the aid of their Tapestry.", false); 086 087 expect(cycle.renderStackPop()).andReturn(component); 088 089 replay(); 090 091 component.finishLoad(cycle, null, null); 092 component.render(writer, cycle); 093 094 verify(); 095 } 096 097 public void testRenderParas() 098 { 099 IMarkupWriter writer = newWriter(); 100 IRequestCycle cycle = newCycle(false); 101 102 InsertText component = newInstance(InsertText.class, 103 new Object[] { "mode", InsertTextMode.PARAGRAPH, "value", 104 "Now is the time\nfor all good men\nto come to the aid of their Tapestry." }); 105 106 expect(cycle.renderStackPush(component)).andReturn(component); 107 108 writer.begin("p"); 109 writer.print("Now is the time", false); 110 writer.end(); 111 112 writer.begin("p"); 113 writer.print("for all good men", false); 114 writer.end(); 115 116 writer.begin("p"); 117 writer.print("to come to the aid of their Tapestry.", false); 118 writer.end(); 119 120 expect(cycle.renderStackPop()).andReturn(component); 121 122 replay(); 123 124 component.render(writer, cycle); 125 126 verify(); 127 } 128 129 public void testRenderRaw() 130 { 131 IMarkupWriter writer = newWriter(); 132 IRequestCycle cycle = newCycle(false); 133 134 InsertText component = newInstance(InsertText.class, 135 new Object[] { "value", "output\n<b>raw</b>", "raw", Boolean.TRUE }); 136 137 expect(cycle.renderStackPush(component)).andReturn(component); 138 139 writer.print("output", true); 140 writer.beginEmpty("br"); 141 writer.print("<b>raw</b>", true); 142 143 expect(cycle.renderStackPop()).andReturn(component); 144 145 replay(); 146 147 component.finishLoad(cycle, null, null); 148 component.render(writer, cycle); 149 150 verify(); 151 } 152 153 public void test_Render_Nested_Raw() 154 { 155 IMarkupWriter writer = newBufferWriter(); 156 IRequestCycle cycle = newCycle(false); 157 158 InsertText component = newInstance(InsertText.class, 159 new Object[] { "value", "output\n<b>raw</b>", "raw", Boolean.TRUE }); 160 161 expect(cycle.renderStackPush(component)).andReturn(component); 162 163 IMarkupWriter nested = writer.getNestedWriter(); 164 165 expect(cycle.renderStackPop()).andReturn(component); 166 167 replay(); 168 169 component.finishLoad(cycle, null, null); 170 component.render(nested, cycle); 171 172 verify(); 173 174 nested.close(); 175 176 assertBuffer("output<br /><b>raw</b>"); 177 } 178 }