001: /*
002: * Copyright 2006 Dan Shellman
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.iscreen.impl;
017:
018: import java.util.HashSet;
019: import java.util.Locale;
020:
021: import junit.framework.TestCase;
022:
023: /**
024: *
025: * @author Shellman, Dan
026: */
027: public class ConfiguredResourceTest extends TestCase {
028: public ConfiguredResourceTest(String name) {
029: super (name);
030: } //end ConfiguredResourceTest()
031:
032: /**
033: * Tests the loading of multiple resource files.
034: */
035: public void testResourceFiles() {
036: ConfiguredResource resource;
037:
038: resource = new ConfiguredResource();
039: resource.addResourceFile("org.iscreen.impl.test");
040: resource.addResourceFile("org.iscreen.impl.resources");
041:
042: assertEquals("Unable to find resource key.", "Test Value 1",
043: resource.getValue("test1", Locale.getDefault()));
044: assertEquals("Unable to find resource key.", "Resource 1",
045: resource.getValue("resource1", Locale.getDefault()));
046: } //end testResourceFiles()
047:
048: /**
049: * Tests the loading of multiple resources files at once.
050: */
051: public void testResourceFileSet() {
052: ConfiguredResource resource;
053: HashSet set = new HashSet();
054:
055: resource = new ConfiguredResource();
056: set.add("org.iscreen.impl.test");
057: set.add("org.iscreen.impl.resources");
058: resource.addResourceFiles(set);
059:
060: assertEquals("Unable to find resource key.", "Test Value 1",
061: resource.getValue("test1", Locale.getDefault()));
062: assertEquals("Unable to find resource key.", "Resource 1",
063: resource.getValue("resource1", Locale.getDefault()));
064: } //end testResourceFileSet()
065:
066: public void testParentResource() {
067: ConfiguredResource resource;
068: ConfiguredResource parentResource;
069:
070: resource = new ConfiguredResource();
071: resource.addResourceFile("org.iscreen.impl.test");
072: parentResource = new ConfiguredResource();
073: parentResource.addResourceFile("org.iscreen.impl.resources");
074: resource.setRef(parentResource);
075:
076: assertEquals("Parent's override value not found.",
077: "Resource 1", resource.getValue("resource1", Locale
078: .getDefault()));
079: } //end testParentResource()
080:
081: /**
082: * Tests the "override" of the child's resource value.
083: */
084: public void testParentOverride() {
085: ConfiguredResource resource;
086: ConfiguredResource parentResource;
087:
088: resource = new ConfiguredResource();
089: resource.addResourceFile("org.iscreen.impl.test");
090: parentResource = new ConfiguredResource();
091: parentResource.addResourceFile("org.iscreen.impl.resources");
092: resource.setRef(parentResource);
093:
094: assertEquals("Child's override value not found.",
095: "Combined Value overridden", resource.getValue(
096: "combined1", Locale.getDefault()));
097: } //end testParentOverride()
098:
099: /**
100: * Tests to ensure that the proper resource value is found when using
101: * a different locale.
102: */
103: public void testInternationalResource() {
104: ConfiguredResource resource;
105:
106: resource = new ConfiguredResource();
107: resource.addResourceFile("org.iscreen.impl.test");
108:
109: assertEquals(
110: "Unable to find resource key in the French resource.",
111: "French Test Value 1", resource.getValue("test1",
112: Locale.FRENCH));
113: } //end testInterationalResource()
114: } //end ConfiguredResourceTest
|