You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ne...@apache.org on 2001/12/07 14:48:22 UTC
cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/test XmlBundleTestCase.java DefaultBundleMatcherTestCase.xtest DefaultBundleMatcherTestCase.java DefaultBundleLoaderTestCase.xtest
neeme 01/12/07 05:48:22
Modified: src/scratchpad/org/apache/avalon/excalibur/i18n/test
XmlBundleTestCase.java
DefaultBundleMatcherTestCase.xtest
DefaultBundleMatcherTestCase.java
DefaultBundleLoaderTestCase.xtest
Log:
bundle matching rewrite
Revision Changes Path
1.5 +10 -3 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/test/XmlBundleTestCase.java
Index: XmlBundleTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/test/XmlBundleTestCase.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XmlBundleTestCase.java 2001/11/02 19:37:48 1.4
+++ XmlBundleTestCase.java 2001/12/07 13:48:22 1.5
@@ -9,6 +9,7 @@
import java.util.Map;
import java.util.HashMap;
+import java.util.Locale;
import org.apache.avalon.excalibur.testcase.ExcaliburTestCase;
import org.apache.avalon.excalibur.i18n.BundleInfo;
@@ -16,7 +17,7 @@
/**
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
- * @version $Id: XmlBundleTestCase.java,v 1.4 2001/11/02 19:37:48 neeme Exp $
+ * @version $Id: XmlBundleTestCase.java,v 1.5 2001/12/07 13:48:22 neeme Exp $
*/
public class XmlBundleTestCase extends ExcaliburTestCase {
@@ -28,20 +29,26 @@
super(name);
}
+ private BundleInfo getBundleInfoInstance(String name, Locale loc) {
+ BundleInfo bi = new BundleInfo();
+ bi.configure(name, loc);
+ return bi;
+ }
+
public void setUp() throws Exception {
this.variables.put("value", "a cat");
final String bundleFileName = this.getClass().getPackage().getName().replace( '.', '/' ) + "/XmlBundle.xml";
getLogger().debug("Test-bundle file = " + bundleFileName);
- this.bundle.setBundleInfo(new BundleInfo("test", null));
+ this.bundle.setBundleInfo(getBundleInfoInstance("test", null));
this.bundle.enableLogging(getLogEnabledLogger());
this.bundle.compose(this.manager);
this.bundle.setLoadOnInit(true);
this.bundleWithRoot.setUseRootElement(false);
this.bundle.init(this.getClass().getClassLoader().getResource(bundleFileName).openStream());
- this.bundleWithRoot.setBundleInfo(new BundleInfo("test-with-root", null));
+ this.bundleWithRoot.setBundleInfo(getBundleInfoInstance("test-with-root", null));
this.bundleWithRoot.enableLogging(getLogEnabledLogger());
this.bundleWithRoot.compose(super.manager);
this.bundleWithRoot.setLoadOnInit(true);
1.2 +6 -16 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/test/DefaultBundleMatcherTestCase.xtest
Index: DefaultBundleMatcherTestCase.xtest
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/test/DefaultBundleMatcherTestCase.xtest,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultBundleMatcherTestCase.xtest 2001/11/02 19:37:03 1.1
+++ DefaultBundleMatcherTestCase.xtest 2001/12/07 13:48:22 1.2
@@ -1,26 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
-<testcase>
- <annotation><![CDATA[
- <title>DefaultBundleLoader tests</title>
- <para>
- Tests the DefaultBundleLoader implementation: loading bundles, mapping correctly, etc.
- </para>
- ]]></annotation>
- <context/>
- <logkit/>
- <configuration>
- <matcher class="org.apache.avalon.excalibur.i18n.DefaultMatcher" type="test1">
+<conf>
+ <matcher class="org.apache.avalon.excalibur.i18n.DefaultBundleMatcher" type="test1">
<bundle-info name="test" ext="test-ext">
<locale language="test-lang" country="test-country" variant="test-variant"/>
</bundle-info>
</matcher>
- <matcher class="org.apache.avalon.excalibur.i18n.DefaultMatcher" type="test2">
+ <matcher class="org.apache.avalon.excalibur.i18n.DefaultBundleMatcher" type="test2">
<bundle-info name="test"/>
</matcher>
- <matcher class="org.apache.avalon.excalibur.i18n.DefaultMatcher" type="test3">
- <bundle-info>
+ <matcher class="org.apache.avalon.excalibur.i18n.DefaultBundleMatcher" type="test3">
+ <bundle-info class="org.apache.avalon.excalibur.i18n.BundleInfo">
<locale language="test-lang" country="test-country"/>
</bundle-info>
</matcher>
- </configuration>
-</testcase>
+</conf>
1.2 +46 -21 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/test/DefaultBundleMatcherTestCase.java
Index: DefaultBundleMatcherTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/test/DefaultBundleMatcherTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultBundleMatcherTestCase.java 2001/11/02 19:37:03 1.1
+++ DefaultBundleMatcherTestCase.java 2001/12/07 13:48:22 1.2
@@ -10,58 +10,83 @@
import java.util.Map;
import java.util.HashMap;
import java.util.Locale;
+import java.net.URL;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.excalibur.testcase.ExcaliburTestCase;
+import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.avalon.framework.component.ComponentException;
+import junit.framework.TestCase;
import org.apache.avalon.excalibur.i18n.BundleInfo;
-import org.apache.avalon.excalibur.i18n.DefaultBundleMatcher;
+import org.apache.avalon.excalibur.i18n.BundleMatcher;
/**
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
- * @version $Id: DefaultBundleMatcherTestCase.java,v 1.1 2001/11/02 19:37:03 neeme Exp $
+ * @version $Id: DefaultBundleMatcherTestCase.java,v 1.2 2001/12/07 13:48:22 neeme Exp $
*/
-public class DefaultBundleMatcherTestCase extends ExcaliburTestCase {
+public class DefaultBundleMatcherTestCase extends TestCase {
- private DefaultBundleMatcher[] matchers;
+ private BundleMatcher[] matchers;
public DefaultBundleMatcherTestCase(String name) {
super(name);
}
- public void configure(Configuration configuration) throws ConfigurationException {
+ public void configure(Configuration configuration) throws Exception {
Configuration[] confs = configuration.getChildren("matcher");
- this.matchers = new DefaultBundleMatcher[confs.length];
+ this.matchers = new BundleMatcher[confs.length];
for (int i = 0; i < confs.length; i++) {
- this.matchers[i] = new DefaultBundleMatcher();
+ this.matchers[i] = (BundleMatcher) Class.forName(confs[i].getAttribute("class")).newInstance();
this.matchers[i].configure(confs[i]);
}
}
public void setUp() throws Exception {
super.setUp();
+
+ final String resourceName = this.getClass().getName().replace( '.', '/' ) + ".xtest";
+ URL resource = this.getClass().getClassLoader().getResource( resourceName );
+ final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
+ final Configuration conf = builder.build( resource.openStream() );
+ configure(conf);
}
public void tearDown() throws Exception {
super.tearDown();
+ this.matchers = null;
}
public void testMatching() throws Exception {
- assertEquals("test1", matchers[0].getType(new BundleInfo("test", new Locale("test-lang", "test-country", "test-variant"), "test-ext")));
- assertTrue(null == matchers[0].getType(new BundleInfo("test", new Locale("test-lang", "test-country", "test-variant"), "test")));
-
- assertEquals("test2", matchers[1].getType(new BundleInfo("test", new Locale("test-lang", "test-country", "test-variant"))));
- assertTrue(null == matchers[1].getType(new BundleInfo("testing", new Locale("test-lang", "test-country", "test-variant"))));
-
- assertEquals("test3", matchers[2].getType(new BundleInfo("test", new Locale("test-lang", "test-country"))));
- assertTrue(null == matchers[2].getType(new BundleInfo("testing", new Locale("test-language", "test-country"))));
- assertTrue(null == matchers[2].getType(new BundleInfo("testing", new Locale("test-lang", "test-count"))));
- }
+ BundleInfo bundleInfo = new BundleInfo();
- public static void main(String[] args) {
- ExcaliburTestCase test = new DefaultBundleMatcherTestCase("test");
- test.run();
+ bundleInfo.configure("test", new Locale("test-lang", "test-country", "test-variant"), "test-ext");
+ assertEquals("test1", matchers[0].getType(bundleInfo));
+ bundleInfo.recycle();
+
+ bundleInfo.configure("test", new Locale("test-lang", "test-country", "test-variant"), "test");
+ assertTrue(null == matchers[0].getType(bundleInfo));
+ bundleInfo.recycle();
+
+ bundleInfo.configure("test", new Locale("test-lang", "test-country", "test-variant"));
+ assertEquals("test2", matchers[1].getType(bundleInfo));
+ bundleInfo.recycle();
+
+ bundleInfo.configure("testing", new Locale("test-lang", "test-country", "test-variant"));
+ assertTrue(null == matchers[1].getType(bundleInfo));
+ bundleInfo.recycle();
+
+ bundleInfo.configure("test", new Locale("test-lang", "test-country"));
+ assertEquals("test3", matchers[2].getType(bundleInfo));
+ bundleInfo.recycle();
+
+ bundleInfo.configure("testing", new Locale("test-language", "test-country"));
+ assertTrue(null == matchers[2].getType(bundleInfo));
+ bundleInfo.recycle();
+
+ bundleInfo.configure("testing", new Locale("test-lang", "test-count"));
+ assertTrue(null == matchers[2].getType(bundleInfo));
+ bundleInfo.recycle();
}
}
1.4 +5 -3 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/test/DefaultBundleLoaderTestCase.xtest
Index: DefaultBundleLoaderTestCase.xtest
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/test/DefaultBundleLoaderTestCase.xtest,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DefaultBundleLoaderTestCase.xtest 2001/11/02 19:40:35 1.3
+++ DefaultBundleLoaderTestCase.xtest 2001/12/07 13:48:22 1.4
@@ -9,10 +9,12 @@
<roles>
<role name="org.apache.avalon.excalibur.xml.xpath.XPathProcessor" shorthand="xpath-processor" default-class="org.apache.avalon.excalibur.xml.xpath.XPathProcessorImpl"/>
<role name="org.apache.avalon.excalibur.i18n.BundleSelector" shorthand="bundle-selector" default-class="org.apache.avalon.excalibur.i18n.BundleSelector"/>
+ <role name="org.apache.avalon.excalibur.i18n.BundleInfo" shorthand="bundle-info" default-class="org.apache.avalon.excalibur.i18n.BundleInfo"/>
</roles>
<context/>
<logkit/>
<components>
+ <bundle-info/>
<bundle-selector>
<loaders>
<loader type-name="xml" bundle="org.apache.avalon.excalibur.i18n.XmlBundle" class="org.apache.avalon.excalibur.i18n.DefaultBundleLoader" mapper="org.apache.avalon.excalibur.i18n.DefaultMapper">
@@ -25,15 +27,15 @@
</loader>
</loaders>
<matchers default-type="xml">
- <matcher class="org.apache.avalon.excalibur.i18n.DefaultMatcher" type="test1">
+ <matcher class="org.apache.avalon.excalibur.i18n.DefaultBundleMatcher" type="test1">
<bundle-info name="test" ext="test-ext">
<locale language="test-lang" country="test-country" variant="test-variant"/>
</bundle-info>
</matcher>
- <matcher class="org.apache.avalon.excalibur.i18n.DefaultMatcher" type="test2">
+ <matcher class="org.apache.avalon.excalibur.i18n.DefaultBundleMatcher" type="test2">
<bundle-info name="test"/>
</matcher>
- <matcher class="org.apache.avalon.excalibur.i18n.DefaultMatcher" type="test3">
+ <matcher class="org.apache.avalon.excalibur.i18n.DefaultBundleMatcher" type="test3">
<bundle-info>
<locale language="test-lang" country="test-country"/>
</bundle-info>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>