1 15 package org.apache.tapestry.components; 16 17 import org.apache.hivemind.ApplicationRuntimeException; 18 import org.apache.hivemind.Location; 19 import org.apache.tapestry.IBinding; 20 import org.apache.tapestry.IMarkupWriter; 21 import org.apache.tapestry.IRender; 22 import org.apache.tapestry.IRequestCycle; 23 import org.apache.tapestry.spec.ComponentSpecification; 24 25 31 public class TestAny extends BaseComponentTestCase 32 { 33 public void testElementNull() 34 { 35 IMarkupWriter writer = newWriter(); 36 IRequestCycle cycle = newCycle(); 37 Location l = newLocation(); 38 39 replayControls(); 40 41 Any any = (Any) newInstance(Any.class, new Object [] 42 { "location", l }); 43 44 try 45 { 46 any.render(writer, cycle); 47 unreachable(); 48 } 49 catch (ApplicationRuntimeException ex) 50 { 51 assertEquals(ComponentMessages.anyElementNotDefined(), ex.getMessage()); 52 assertSame(l, ex.getLocation()); 53 } 54 55 verifyControls(); 56 } 57 58 public void testRender() 59 { 60 IMarkupWriter writer = newWriter(); 61 IRequestCycle cycle = newCycle(false); 62 IRender body = newRender(); 63 64 writer.begin("span"); 65 66 body.render(writer, cycle); 67 68 writer.end("span"); 69 70 replayControls(); 71 72 Any any = (Any) newInstance(Any.class, new Object [] 73 { "element", "span" }); 74 75 any.addBody(body); 76 77 any.render(writer, cycle); 78 79 verifyControls(); 80 } 81 82 public void testRenderWithInformalParameters() 83 { 84 IMarkupWriter writer = newWriter(); 85 IRequestCycle cycle = newCycle(false); 86 IRender body = newRender(); 87 IBinding binding = newBinding("fred"); 88 89 writer.begin("span"); 90 writer.attribute("class", "fred"); 91 92 body.render(writer, cycle); 93 94 writer.end("span"); 95 96 replayControls(); 97 98 Any any = (Any) newInstance(Any.class, new Object [] 99 { "element", "span", "specification", new ComponentSpecification() }); 100 101 any.addBody(body); 102 any.setBinding("class", binding); 103 104 any.render(writer, cycle); 105 106 verifyControls(); 107 } 108 109 public void testRewind() 110 { 111 IMarkupWriter writer = newWriter(); 112 IRequestCycle cycle = newCycle(true); 113 IRender body = newRender(); 114 115 body.render(writer, cycle); 116 117 replayControls(); 118 119 Any any = (Any) newInstance(Any.class, new Object [] 120 { "element", "span" }); 121 122 any.addBody(body); 123 124 any.render(writer, cycle); 125 126 verifyControls(); 127 } 128 } 129 | Popular Tags |