KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > i18n > test > DefaultBundleMatcherTestCase


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE.txt file.
7  */

8 package org.apache.avalon.excalibur.i18n.test;
9
10 import java.util.Map JavaDoc;
11 import java.util.HashMap JavaDoc;
12 import java.util.Locale JavaDoc;
13 import java.net.URL JavaDoc;
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 /**
27  * @author <a HREF="mailto:neeme@apache.org">Neeme Praks</a>
28  * @version $Id: DefaultBundleMatcherTestCase.java,v 1.4 2002/01/02 19:04:56 neeme Exp $
29  */

30 public class DefaultBundleMatcherTestCase extends TestCase {
31
32     private BundleMatcher[] matchers;
33
34     public DefaultBundleMatcherTestCase(String JavaDoc name) {
35         super(name);
36     }
37
38     public void configure(Configuration configuration) throws Exception JavaDoc {
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 JavaDoc {
48         super.setUp();
49
50         final String JavaDoc resourceName = this.getClass().getName().replace( '.', '/' ) + ".xtest";
51         URL JavaDoc 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 JavaDoc {
58         super.tearDown();
59         this.matchers = null;
60     }
61
62     public void testMatching() throws Exception JavaDoc {
63         assertEquals("test1", matchers[0].getType(new BundleInfo("test", new Locale JavaDoc("test-lang", "test-country", "test-variant"), "test-ext")));
64         assertTrue(null == matchers[0].getType(new BundleInfo("test", new Locale JavaDoc("test-lang", "test-country", "test-variant"), "test")));
65         assertEquals("test2", matchers[1].getType(new BundleInfo("test", new Locale JavaDoc("test-lang", "test-country", "test-variant"))));
66         assertTrue(null == matchers[1].getType(new BundleInfo("testing", new Locale JavaDoc("test-lang", "test-country", "test-variant"))));
67         assertEquals("test3", matchers[2].getType(new BundleInfo("test", new Locale JavaDoc("test-lang", "test-country"))));
68         assertTrue(null == matchers[2].getType(new BundleInfo("testing", new Locale JavaDoc("test-language", "test-country"))));
69         assertTrue(null == matchers[2].getType(new BundleInfo("testing", new Locale JavaDoc("test-lang", "test-count"))));
70     }
71
72 }
73
Popular Tags