KickJava   Java API By Example, From Geeks To Geeks.

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


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
14 import org.apache.avalon.excalibur.testcase.ExcaliburTestCase;
15 import org.apache.avalon.excalibur.i18n.BundleInfo;
16 import org.apache.avalon.excalibur.i18n.XmlBundle;
17 import org.apache.avalon.excalibur.i18n.BundleInfoMapper;
18 import org.apache.avalon.framework.configuration.Configuration;
19 import org.apache.avalon.framework.configuration.DefaultConfiguration;
20 import org.xml.sax.InputSource JavaDoc;
21
22 /**
23  * @author <a HREF="mailto:neeme@apache.org">Neeme Praks</a>
24  * @version $Id: XmlBundleTestCase.java,v 1.8 2002/01/02 19:48:51 neeme Exp $
25  */

26 public class XmlBundleTestCase extends ExcaliburTestCase {
27
28     private Map JavaDoc variables = new HashMap JavaDoc(5);
29     private XmlBundle bundle = new XmlBundle();
30     private XmlBundle bundleWithRoot = new XmlBundle();
31
32     public XmlBundleTestCase( String JavaDoc name ) {
33         super(name);
34     }
35
36     public void setUp() throws Exception JavaDoc {
37         this.variables.put("value", "a cat");
38
39         final String JavaDoc bundleFileName = this.getClass().getPackage().getName().replace( '.', '/' ) + "/XmlBundle.xml";
40         getLogger().debug("Test-bundle file = " + bundleFileName);
41
42         this.bundle.setBundleInfo(new BundleInfo("test", null));
43         this.bundle.setMapper((BundleInfoMapper) this.manager.lookup(BundleInfoMapper.ROLE));
44         this.bundle.enableLogging(getLogEnabledLogger());
45         this.bundle.compose(this.manager);
46         DefaultConfiguration conf = new DefaultConfiguration("bundle-conf", "conf");
47         conf.setAttribute(XmlBundle.ConfigurationKeys.LOAD_ON_INIT, "true");
48         conf.setAttribute(XmlBundle.ConfigurationKeys.USE_ROOT, "false");
49         this.bundle.configure(conf);
50         this.bundle.initialize(new InputSource JavaDoc(this.getClass().getClassLoader().getResource(bundleFileName).openStream()));
51
52         this.bundleWithRoot.setBundleInfo(new BundleInfo("test-with-root", null));
53         this.bundleWithRoot.setMapper((BundleInfoMapper) this.manager.lookup(BundleInfoMapper.ROLE));
54         this.bundleWithRoot.enableLogging(getLogEnabledLogger());
55         this.bundleWithRoot.compose(super.manager);
56         conf = new DefaultConfiguration("bundle-conf", "conf");
57         conf.setAttribute(XmlBundle.ConfigurationKeys.LOAD_ON_INIT, "true");
58         conf.setAttribute(XmlBundle.ConfigurationKeys.USE_ROOT, "true");
59         this.bundleWithRoot.configure(conf);
60         this.bundleWithRoot.initialize(new InputSource JavaDoc(this.getClass().getClassLoader().getResource(bundleFileName).openStream()));
61     }
62
63     public void testGetString() {
64         assertEquals("Text on level3", this.bundle.getString("level1.level2.level3"));
65         assertEquals("Flat level 2", this.bundle.getString("levels/level[@number='2']"));
66
67         assertEquals("Text on level3", this.bundleWithRoot.getString("resources.level1.level2.level3"));
68         assertEquals("Flat level 2", this.bundleWithRoot.getString("resources.levels/level[@number='2']"));
69     }
70
71     public void testGetStringWithVariable() {
72         assertEquals("Here is an example of a cat.", this.bundle.getString("key-with-variable", this.variables));
73         assertEquals("Here is an example of a cat.", this.bundleWithRoot.getString("resources.key-with-variable", this.variables));
74     }
75
76 }
77
Popular Tags