1 15 package org.apache.tapestry.describe; 16 17 import java.net.URL ; 18 19 import org.apache.hivemind.Location; 20 import org.apache.hivemind.Resource; 21 import org.apache.hivemind.impl.LocationImpl; 22 import org.apache.hivemind.util.URLResource; 23 import org.apache.tapestry.IMarkupWriter; 24 import org.apache.tapestry.IRequestCycle; 25 import org.easymock.MockControl; 26 27 33 public class TestLocationRenderStrategy extends BaseDescribeTestCase 34 { 35 private Resource newResource(URL url) 36 { 37 MockControl control = newControl(Resource.class); 38 Resource resource = (Resource) control.getMock(); 39 40 resource.getResourceURL(); 41 control.setReturnValue(url); 42 43 return resource; 44 } 45 46 private Location newLocation(String file, int lineNumber) 47 { 48 URL url = getClass().getResource(file); 49 50 Resource resource = new URLResource(url); 51 52 return new LocationImpl(resource, lineNumber); 53 } 54 55 private void train(IMarkupWriter writer, int startLine, int lineNumber, String [] lines) 56 { 57 writer.beginEmpty("br"); 58 writer.begin("table"); 59 writer.attribute("class", "location-content"); 60 61 for (int i = 0; i < lines.length; i++) 62 { 63 int currentLine = startLine + i; 64 65 writer.begin("tr"); 66 67 if (currentLine == lineNumber) 68 writer.attribute("class", "target-line"); 69 70 writer.begin("td"); 71 writer.attribute("class", "line-number"); 72 writer.print(currentLine); 73 writer.end(); 74 75 writer.begin("td"); 76 writer.print(lines[i]); 77 writer.end("tr"); 78 writer.println(); 79 } 80 81 writer.end("table"); 82 } 83 84 public void testNoLineNumber() 85 { 86 IMarkupWriter writer = newWriter(); 87 IRequestCycle cycle = newCycle(); 88 MockControl lc = newControl(Location.class); 89 Location l = (Location) lc.getMock(); 90 91 l.getLineNumber(); 92 lc.setReturnValue(0); 93 94 writer.print(l.toString()); 95 96 replayControls(); 97 98 new LocationRenderStrategy().renderObject(l, writer, cycle); 99 100 verifyControls(); 101 } 102 103 public void testNoURL() 104 { 105 IMarkupWriter writer = newWriter(); 106 IRequestCycle cycle = newCycle(); 107 Resource resource = newResource(null); 108 MockControl lc = newControl(Location.class); 109 Location l = (Location) lc.getMock(); 110 111 l.getLineNumber(); 112 lc.setReturnValue(99); 113 114 l.getResource(); 115 lc.setReturnValue(resource); 116 117 writer.print(l.toString()); 118 119 replayControls(); 120 121 new LocationRenderStrategy().renderObject(l, writer, cycle); 122 123 verifyControls(); 124 } 125 126 129 public void testShortContent() 130 { 131 IMarkupWriter writer = newWriter(); 132 IRequestCycle cycle = newCycle(); 133 Location l = newLocation("Short.txt", 7); 134 135 writer.print(l.toString()); 136 137 train(writer, 2, 7, new String [] 138 { "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" }); 139 140 replayControls(); 141 142 new LocationRenderStrategy().renderObject(l, writer, cycle); 143 144 verifyControls(); 145 } 146 147 150 public void testLongContent() 151 { 152 IMarkupWriter writer = newWriter(); 153 IRequestCycle cycle = newCycle(); 154 Location l = newLocation("Long.txt", 3); 155 156 writer.print(l.toString()); 157 158 train(writer, 1, 3, new String [] 159 { "Line One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight" }); 160 161 replayControls(); 162 163 new LocationRenderStrategy().renderObject(l, writer, cycle); 164 165 verifyControls(); 166 } 167 } | Popular Tags |