/*
* Danet GmbH
* Beratung und Software-Entwicklung
* Gesch�ftstelle AN
*
* $Id: SegResBundle.java 2326 2007-03-27 21:59:44Z mlipp $
*
* $Log$
* Revision 1.1.1.1 2003/06/30 20:07:00 drmlipp
* Initial import
*
* Revision 1.11 2003/04/16 19:25:04 lipp
* Adapted to jdk 1.4
*
* Revision 1.10 2002/06/18 14:07:50 lipp
* Fixed bug in SegmentedMap that prevented the use of top level keys.
*
* Revision 1.9 2002/02/03 21:41:42 lipp
* Cleaned up unittests.
*
* Revision 1.8 2002/01/28 12:34:48 huaiyang
* Removed obsolete import for SegmentedResourceBundle.
*
* Revision 1.7 2001/12/05 16:32:26 feldgen
* Patched for use with Hashmaps
*
* Revision 1.6 2001/12/04 11:53:06 schlue
* Minor bug fixes
*
* Revision 1.5 2001/11/26 17:37:50 feldgen
* changed tests to SegmentedMap
*
* Revision 1.4 2001/11/15 09:56:06 schlue
* Import statement updated
*
* Revision 1.3 2001/10/10 09:51:56 schlue
* Call of deprecated method "assert" replaced by "assertTrue"
*
* Revision 1.2 2001/10/05 08:46:57 schlue
* Caching of keylists and values added
*
* Revision 1.1 2001/09/25 16:16:04 schlue
* SegmentedResourceBundle added and used for mapping entries
*
*
*/
package util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.Set;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import de.danet.an.util.ResourceBundleAsMap;
import de.danet.an.util.SegmentedMap;
/**
* Tests the SegmentedResourceBundle
*/
public class SegResBundle extends TestCase {
/**
* Konstruktor zum Erzeugen eines TestCase
*/
public SegResBundle(String name) {
super (name);
}
/**
* Assembling the test suite
*/
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new SegResBundle("getAllResources"));
suite.addTest(new SegResBundle("getKeysOfPathDanetOSS"));
suite.addTest(new SegResBundle("getKeysOfPathDanetOSSAN"));
suite.addTest(new SegResBundle("getKeysOfPathTelekom"));
suite.addTest(new SegResBundle("getKeysOfEmptyPath"));
suite.addTest(new SegResBundle("getValues"));
suite.addTest(new SegResBundle("testKeyListCache"));
suite.addTest(new SegResBundle("testValueCache"));
return suite;
}
/**
* Test locale and loading all resource entries
*/
public void getAllResources() throws Exception {
ResourceBundle bundle
= ResourceBundle.getBundle("util.I18nTest", Locale.GERMANY);
ResourceBundleAsMap rbm = new ResourceBundleAsMap(bundle);
SegmentedMap segmap = new SegmentedMap(rbm);
// Make sure that german property file is used
assertTrue(bundle.getLocale().toString().equals("de"));
int i = segmap.size();
// Verfiy that all entries have been found
assertTrue(i==21);
}
/**
* Test loading all resource entries in path "danet.oss"
*/
public void getKeysOfPathDanetOSS() throws Exception {
final String[] resultKeys = {
"danet.oss.danet",
"danet.oss.poolPKW",
"danet.oss.oss",
"danet.oss.sm",
"danet.oss.bss",
"danet.oss.an.poolPKW",
"danet.oss.z",
"danet.oss.danet-is",
"danet.oss.telekom",
"danet.oss.an",
"danet.oss.tt"
};
List resultList = new ArrayList();
resultList.addAll(Arrays.asList(resultKeys));
ResourceBundle bundle
= ResourceBundle.getBundle("util.I18nTest", Locale.GERMANY);
ResourceBundleAsMap rbm = new ResourceBundleAsMap(bundle);
SegmentedMap segmap = new SegmentedMap(rbm);
Set myKeySet = segmap.keySet("danet.oss");
int i = 0;
assertTrue(myKeySet.containsAll(resultList));
i = myKeySet.size();
// Verfiy that all entries have been found
assertTrue(i==resultKeys.length);
}
/**
* Test loading all resource entries in path "danet.oss.an"
*/
public void getKeysOfPathDanetOSSAN() throws Exception {
final String[] resultKeys = {
"danet.oss.an.danet",
"danet.oss.an.poolPKW",
"danet.oss.an.oss",
"danet.oss.an.sm",
"danet.oss.an.bss",
"danet.oss.an.z",
"danet.oss.an.danet-is",
"danet.oss.an.telekom",
"danet.oss.an.an",
"danet.oss.an.tt"
};
List resultList = new ArrayList();
resultList.addAll(Arrays.asList(resultKeys));
ResourceBundle bundle
= ResourceBundle.getBundle("util.I18nTest", Locale.GERMANY);
ResourceBundleAsMap rbm = new ResourceBundleAsMap(bundle);
SegmentedMap segmap = new SegmentedMap(rbm);
int i = 0;
Set myKeySet = segmap.keySet("danet.oss.an");
assertTrue(myKeySet.containsAll(resultList));
i = myKeySet.size();
// Verfiy that all entries have been found
assertTrue(i==resultKeys.length);
}
/**
* Test loading all resource entries in path "telekom"
*/
public void getKeysOfPathTelekom() throws Exception {
final String[] resultKeys = {
"telekom.danet",
"telekom.danet-is",
"telekom.telekom",
"telekom.t-systems",
"telekom.t-data",
"telekom.t-mobil"
};
List resultList = new ArrayList();
resultList.addAll(Arrays.asList(resultKeys));
ResourceBundle bundle
= ResourceBundle.getBundle("util.I18nTest", Locale.GERMANY);
ResourceBundleAsMap rbm = new ResourceBundleAsMap(bundle);
SegmentedMap segmap = new SegmentedMap(rbm);
int i = 0;
Set myKeySet = segmap.keySet("telekom");
assertTrue(myKeySet.containsAll(resultList));
i = myKeySet.size();
// Verfiy that all entries have been found
assertTrue(i==resultKeys.length);
}
/**
* Test loading all resource entries in empty path
*/
public void getKeysOfEmptyPath() throws Exception {
ResourceBundle bundle
= ResourceBundle.getBundle("util.I18nTest", Locale.GERMANY);
ResourceBundleAsMap rbm = new ResourceBundleAsMap(bundle);
SegmentedMap segmap = new SegmentedMap(rbm);
int i = 0;
Set myKeySet = segmap.keySet();
i = myKeySet.size();
// Verfiy that all entries have been found
assertTrue(i==21);
}
/**
* Test loading all resource entries in empty path
*/
public void getValues() throws Exception {
ResourceBundle bundle
= ResourceBundle.getBundle("util.I18nTest", Locale.GERMANY);
ResourceBundleAsMap rbm = new ResourceBundleAsMap(bundle);
SegmentedMap segmap = new SegmentedMap(rbm);
// oss.an has its own PKW resource
assertTrue(segmap.get("danet.oss.an.poolPKW").equals("DA-AN 964"));
// oss.sm uses the PKW resource of oss
assertTrue(segmap.get("danet.oss.sm.poolPKW").equals("DA-OS 137"));
// bss.bs uses the PKW resource of danet
assertTrue(segmap.get("danet.bss.bs.poolPKW").equals("DA-NET 123"));
// everybody uses danet
assertTrue(segmap.get("danet.oss.an.danet").equals("Danet GmbH"));
boolean notFound = false;
Object value = segmap.get("telekom.poolPKW");
if ( (value == null)
&& !segmap.containsKey("telekom.poolPKW") ) {
notFound = true;
}
assertTrue(notFound);
}
/**
* Test caching of key list to given path
*/
public void testKeyListCache() throws Exception {
ResourceBundle bundle
= ResourceBundle.getBundle("util.I18nTest", Locale.GERMANY);
ResourceBundleAsMap rbm = new ResourceBundleAsMap(bundle);
SegmentedMap segmap = new SegmentedMap(rbm);
Set keyList1 = segmap.keySet("telekom");
Set keyList2 = segmap.keySet("telekom");
Set keyList3 = segmap.keySet("danet");
Set keyList4 = segmap.keySet("telekom.t-data");
// Verfiy that keylist1 matches keylist2
assertTrue(keyList1.equals(keyList2));
// Verfiy that keylist1 doesn't match keylist3
assertTrue(!(keyList1.equals(keyList3)));
// Verfiy that keylist1 doesn't match keylist4
assertTrue(!(keyList1.equals(keyList4)));
}
/**
* Test caching of value to given key
*/
public void testValueCache() throws Exception {
ResourceBundle bundle
= ResourceBundle.getBundle("util.I18nTest", Locale.GERMANY);
ResourceBundleAsMap rbm = new ResourceBundleAsMap(bundle);
SegmentedMap segmap = new SegmentedMap(rbm);
String pkw1 = (String)segmap.get("danet.oss.sm.poolPKW");
String pkw2 = (String)segmap.get("danet.oss.poolPKW");
String pkw3 = (String)segmap.get("danet.oss.sm.poolPKW");
assertTrue(pkw1.equals(pkw2));
assertTrue(pkw1 == pkw3);
}
}