1 8 package org.apache.avalon.excalibur.i18n.test; 9 10 import java.util.Map ; 11 import java.util.HashMap ; 12 import java.util.Locale ; 13 import java.net.URL ; 14 15 import org.apache.avalon.framework.configuration.Configuration; 16 import org.apache.avalon.framework.configuration.ConfigurationException; 17 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; 18 import org.apache.avalon.framework.configuration.Configurable; 19 import org.apache.avalon.framework.component.ComponentException; 20 import junit.framework.TestCase; 21 22 import org.apache.avalon.excalibur.i18n.BundleInfo; 23 import org.apache.avalon.excalibur.i18n.BundleMatcher; 24 import org.apache.avalon.excalibur.i18n.ConfigurableBundleInfo; 25 26 30 public class DefaultBundleMatcherTestCase extends TestCase { 31 32 private BundleMatcher[] matchers; 33 34 public DefaultBundleMatcherTestCase(String name) { 35 super(name); 36 } 37 38 public void configure(Configuration configuration) throws Exception { 39 Configuration[] confs = configuration.getChildren("matcher"); 40 this.matchers = new BundleMatcher[confs.length]; 41 for (int i = 0; i < confs.length; i++) { 42 this.matchers[i] = (BundleMatcher) Class.forName(confs[i].getAttribute("class")).newInstance(); 43 if (this.matchers[i] instanceof Configurable) ((Configurable) this.matchers[i]).configure(confs[i]); 44 } 45 } 46 47 public void setUp() throws Exception { 48 super.setUp(); 49 50 final String resourceName = this.getClass().getName().replace( '.', '/' ) + ".xtest"; 51 URL resource = this.getClass().getClassLoader().getResource( resourceName ); 52 final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); 53 final Configuration conf = builder.build( resource.openStream() ); 54 configure(conf); 55 } 56 57 public void tearDown() throws Exception { 58 super.tearDown(); 59 this.matchers = null; 60 } 61 62 public void testMatching() throws Exception { 63 assertEquals("test1", matchers[0].getType(new BundleInfo("test", new Locale ("test-lang", "test-country", "test-variant"), "test-ext"))); 64 assertTrue(null == matchers[0].getType(new BundleInfo("test", new Locale ("test-lang", "test-country", "test-variant"), "test"))); 65 assertEquals("test2", matchers[1].getType(new BundleInfo("test", new Locale ("test-lang", "test-country", "test-variant")))); 66 assertTrue(null == matchers[1].getType(new BundleInfo("testing", new Locale ("test-lang", "test-country", "test-variant")))); 67 assertEquals("test3", matchers[2].getType(new BundleInfo("test", new Locale ("test-lang", "test-country")))); 68 assertTrue(null == matchers[2].getType(new BundleInfo("testing", new Locale ("test-language", "test-country")))); 69 assertTrue(null == matchers[2].getType(new BundleInfo("testing", new Locale ("test-lang", "test-count")))); 70 } 71 72 } 73 | Popular Tags |