1 15 package org.apache.tapestry.components; 16 17 import org.apache.tapestry.IBinding; 18 import org.apache.tapestry.IMarkupWriter; 19 import org.apache.tapestry.IRender; 20 import org.apache.tapestry.IRequestCycle; 21 import org.apache.tapestry.spec.IComponentSpecification; 22 23 29 public class TestConditional extends BaseComponentTestCase 30 { 31 private IRender newRender(IMarkupWriter writer, IRequestCycle cycle) 32 { 33 IRender render = (IRender) newMock(IRender.class); 34 35 render.render(writer, cycle); 36 37 return render; 38 } 39 40 public void testFalseAndFalse() 41 { 42 Conditional conditional = (Conditional) newInstance(Conditional.class, new Object [] 43 { "condition", Boolean.FALSE, "invert", Boolean.FALSE }); 44 45 conditional.renderComponent(null, null); 46 } 47 48 public void testTrueAndTrue() 49 { 50 Conditional conditional = (Conditional) newInstance(Conditional.class, new Object [] 51 { "condition", Boolean.TRUE, "invert", Boolean.TRUE }); 52 53 conditional.renderComponent(null, null); 54 } 55 56 public void testRenderSimple() 57 { 58 IRequestCycle cycle = newCycle(false); 59 IMarkupWriter writer = newWriter(); 60 IRender body = newRender(writer, cycle); 61 62 replayControls(); 63 64 Conditional conditional = (Conditional) newInstance(Conditional.class, new Object [] 65 { "condition", Boolean.TRUE }); 66 conditional.addBody(body); 67 68 conditional.render(writer, cycle); 69 70 verifyControls(); 71 } 72 73 public void testIgnoreElementWhenRewinding() 74 { 75 IRequestCycle cycle = newCycle(true); 76 IMarkupWriter writer = newWriter(); 77 IRender body = newRender(writer, cycle); 78 79 replayControls(); 80 81 Conditional conditional = (Conditional) newInstance(Conditional.class, new Object [] 82 { "condition", Boolean.TRUE, "element", "div" }); 83 conditional.addBody(body); 84 85 conditional.render(writer, cycle); 86 87 verifyControls(); 88 } 89 90 public void testElement() 91 { 92 IBinding informal = newBinding("informal-value"); 93 IComponentSpecification spec = newSpec("informal", null); 94 95 IRequestCycle cycle = newCycle(false); 96 IMarkupWriter writer = newWriter(); 97 IRender body = newRender(writer, cycle); 98 99 writer.begin("div"); 100 writer.attribute("informal", "informal-value"); 101 102 108 writer.end("div"); 109 110 replayControls(); 111 112 Conditional conditional = (Conditional) newInstance(Conditional.class, new Object [] 113 { "condition", Boolean.TRUE, "element", "div", "specification", spec }); 114 conditional.addBody(body); 115 conditional.setBinding("informal", informal); 116 117 conditional.render(writer, cycle); 118 119 verifyControls(); 120 } 121 } | Popular Tags |