1 15 package org.apache.tapestry.web; 16 17 import java.net.URL ; 18 import java.util.Locale ; 19 20 import org.apache.hivemind.Resource; 21 import org.apache.hivemind.test.HiveMindTestCase; 22 import org.apache.tapestry.web.WebContextResource; 23 import org.apache.tapestry.web.WebContext; 24 import org.easymock.MockControl; 25 26 32 public class TestWebContextResource extends HiveMindTestCase 33 { 34 private WebContext newContext() 35 { 36 return (WebContext) newMock(WebContext.class); 37 } 38 39 public void testConstructor() 40 { 41 WebContext context = newContext(); 42 43 replayControls(); 44 45 Resource r = new WebContextResource(context, "/foo/bar/baz_en.html", Locale.ENGLISH); 46 47 assertEquals("context:/foo/bar/baz_en.html", r.toString()); 48 49 assertEquals("/foo/bar/baz_en.html", r.getPath()); 50 51 assertEquals("baz_en.html", r.getName()); 52 53 assertEquals(Locale.ENGLISH, r.getLocale()); 54 55 verifyControls(); 56 } 57 58 public void testLocalizationExists() throws Exception 59 { 60 MockControl control = newControl(WebContext.class); 61 WebContext context = (WebContext) control.getMock(); 62 63 context.getResource("/foo/bar/baz_en.html"); 64 control.setReturnValue(new URL ("http://foo.com")); 65 66 replayControls(); 67 68 Resource r1 = new WebContextResource(context, "/foo/bar/baz.html"); 69 70 Resource r2 = r1.getLocalization(Locale.ENGLISH); 71 72 assertEquals("/foo/bar/baz_en.html", r2.getPath()); 73 assertEquals(Locale.ENGLISH, r2.getLocale()); 74 75 verifyControls(); 76 } 77 78 public void testLocalizationSame() throws Exception 79 { 80 MockControl control = newControl(WebContext.class); 81 WebContext context = (WebContext) control.getMock(); 82 83 context.getResource("/foo/bar/baz_en.html"); 84 control.setReturnValue(null); 85 86 context.getResource("/foo/bar/baz.html"); 87 control.setReturnValue(new URL ("http://foo.com")); 88 89 replayControls(); 90 91 Resource r1 = new WebContextResource(context, "/foo/bar/baz.html"); 92 93 Resource r2 = r1.getLocalization(Locale.ENGLISH); 94 95 assertSame(r2, r1); 96 97 verifyControls(); 98 } 99 100 public void testLocalizationMissing() throws Exception 101 { 102 MockControl control = newControl(WebContext.class); 103 WebContext context = (WebContext) control.getMock(); 104 105 context.getResource("/foo/bar/baz_en.html"); 106 control.setReturnValue(null); 107 108 context.getResource("/foo/bar/baz.html"); 109 control.setReturnValue(null); 110 111 replayControls(); 112 113 Resource r1 = new WebContextResource(context, "/foo/bar/baz.html"); 114 115 assertNull(r1.getLocalization(Locale.ENGLISH)); 116 117 verifyControls(); 118 } 119 120 public void testGetRelativeResource() 121 { 122 WebContext context = newContext(); 123 124 replayControls(); 125 126 Resource r1 = new WebContextResource(context, "/foo/bar/baz.html"); 127 Resource r2 = r1.getRelativeResource("baz.gif"); 128 129 assertEquals("/foo/bar/baz.gif", r2.getPath()); 130 131 verifyControls(); 132 } 133 } | Popular Tags |