1 15 package org.apache.hivemind.util; 16 17 import java.net.MalformedURLException ; 18 import java.net.URL ; 19 import java.util.Locale ; 20 21 import javax.servlet.ServletContext ; 22 23 import org.apache.hivemind.test.HiveMindTestCase; 24 import org.easymock.MockControl; 25 26 32 public class TestLocalizedContextResourceFinder extends HiveMindTestCase 33 { 34 public void testFound() throws Exception 35 { 36 MockControl control = newControl(ServletContext .class); 37 ServletContext sc = (ServletContext ) control.getMock(); 38 39 sc.getResource("/foo/bar/baz_en_US.html"); 40 control.setReturnValue(null); 41 42 sc.getResource("/foo/bar/baz_en.html"); 43 control.setReturnValue(new URL ("http://foo.com")); 44 45 replayControls(); 46 47 LocalizedContextResourceFinder f = new LocalizedContextResourceFinder(sc); 48 49 LocalizedResource lr = f.resolve("/foo/bar/baz.html", Locale.US); 50 51 assertEquals("/foo/bar/baz_en.html", lr.getResourcePath()); 52 assertEquals(Locale.ENGLISH, lr.getResourceLocale()); 53 54 verifyControls(); 55 56 } 57 58 public void testNotFound() throws Exception 59 { 60 MockControl control = newControl(ServletContext .class); 61 ServletContext sc = (ServletContext ) control.getMock(); 62 63 sc.getResource("/foo/bar/baz_en.html"); 64 control.setReturnValue(null); 65 66 sc.getResource("/foo/bar/baz.html"); 67 control.setReturnValue(null); 68 69 replayControls(); 70 71 LocalizedContextResourceFinder f = new LocalizedContextResourceFinder(sc); 72 73 assertNull(f.resolve("/foo/bar/baz.html", Locale.ENGLISH)); 74 75 verifyControls(); 76 } 77 78 public void testNotFoundException() throws Exception 79 { 80 MockControl control = newControl(ServletContext .class); 81 ServletContext sc = (ServletContext ) control.getMock(); 82 83 sc.getResource("/foo/bar/baz_en.html"); 84 control.setThrowable(new MalformedURLException ()); 85 86 sc.getResource("/foo/bar/baz.html"); 87 control.setThrowable(new MalformedURLException ()); 88 89 replayControls(); 90 91 LocalizedContextResourceFinder f = new LocalizedContextResourceFinder(sc); 92 93 assertNull(f.resolve("/foo/bar/baz.html", Locale.ENGLISH)); 94 95 verifyControls(); 96 } 97 98 public void testExtensionlessResource() throws Exception 99 { 100 MockControl control = newControl(ServletContext .class); 101 ServletContext sc = (ServletContext ) control.getMock(); 102 103 sc.getResource("/foo/bar/baz"); 104 control.setReturnValue(new URL ("http://foo.com")); 105 106 replayControls(); 107 108 LocalizedContextResourceFinder f = new LocalizedContextResourceFinder(sc); 109 110 LocalizedResource lr = f.resolve("/foo/bar/baz", null); 111 112 assertEquals("/foo/bar/baz", lr.getResourcePath()); 113 assertNull(lr.getResourceLocale()); 114 115 verifyControls(); 116 } 117 } | Popular Tags |