001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.pluto.internal.impl;
018:
019: import org.apache.pluto.util.PlutoTestCase;
020: import org.apache.pluto.descriptors.portlet.PortletDD;
021: import org.apache.pluto.descriptors.portlet.PortletInfoDD;
022:
023: import java.util.ListResourceBundle;
024: import java.util.Locale;
025: import java.util.ResourceBundle;
026:
027: import junit.framework.Assert;
028:
029: /**
030: * Unit test for the resource bundle factory.
031: * @since Jul 30, 2005
032: */
033: public class ResourceBundleFactoryTest extends PlutoTestCase {
034:
035: private PortletDD validDD;
036:
037: public void setUp() throws Exception {
038: super .setUp();
039:
040: validDD = new PortletDD();
041:
042: PortletInfoDD info = new PortletInfoDD();
043: info.setTitle("Info Title");
044: info.setShortTitle("Info Short Title");
045: info.setKeywords("Info Keywords");
046: validDD.setPortletInfo(info);
047:
048: validDD.setResourceBundle(TestResourceBundle.class.getName());
049: }
050:
051: public void tearDown() throws Exception {
052: super .setUp();
053: validDD = null;
054: }
055:
056: public void testGetBundleAllSpecified() {
057: ResourceBundleFactory factory = new ResourceBundleFactory(
058: validDD);
059: ResourceBundle bundle = factory.getResourceBundle(Locale
060: .getDefault());
061:
062: Assert.assertEquals("Bundle Title", bundle
063: .getString("javax.portlet.title"));
064: Assert.assertEquals("Bundle Short Title", bundle
065: .getString("javax.portlet.short-title"));
066: Assert.assertEquals("Bundle Keywords", bundle
067: .getString("javax.portlet.keywords"));
068: }
069:
070: public void testGetResourceBundleNoBundle() {
071: validDD.setResourceBundle(null);
072: ResourceBundleFactory factory = new ResourceBundleFactory(
073: validDD);
074: ResourceBundle bundle = factory.getResourceBundle(Locale
075: .getDefault());
076:
077: Assert.assertEquals("Info Title", bundle
078: .getString("javax.portlet.title"));
079: Assert.assertEquals("Info Short Title", bundle
080: .getString("javax.portlet.short-title"));
081: Assert.assertEquals("Info Keywords", bundle
082: .getString("javax.portlet.keywords"));
083: }
084:
085: public void testGetResourceBundleNoInfo() {
086: validDD.setPortletInfo(null);
087: ResourceBundleFactory factory = new ResourceBundleFactory(
088: validDD);
089: ResourceBundle bundle = factory.getResourceBundle(Locale
090: .getDefault());
091:
092: Assert.assertEquals("Bundle Title", bundle
093: .getString("javax.portlet.title"));
094: Assert.assertEquals("Bundle Short Title", bundle
095: .getString("javax.portlet.short-title"));
096: Assert.assertEquals("Bundle Keywords", bundle
097: .getString("javax.portlet.keywords"));
098: }
099:
100: public void testGetResourceBundleNoBundleNullValues() {
101: validDD.setResourceBundle(null);
102: validDD.getPortletInfo().setTitle(null);
103: validDD.getPortletInfo().setShortTitle(null);
104: validDD.getPortletInfo().setKeywords(null);
105: ResourceBundleFactory factory = new ResourceBundleFactory(
106: validDD);
107: ResourceBundle bundle = factory.getResourceBundle(Locale
108: .getDefault());
109:
110: try {
111: Assert.assertEquals(null, bundle
112: .getString("javax.portlet.title"));
113: fail("Exception should have been thrown.");
114: } catch (Throwable t) {
115:
116: }
117:
118: try {
119: Assert.assertEquals(null, bundle
120: .getString("javax.portlet.short-title"));
121: fail("Exception should have been throw.");
122: } catch (Throwable t) {
123:
124: }
125:
126: try {
127: Assert.assertEquals(null, bundle
128: .getString("javax.portlet.keywords"));
129: fail("Exception should have been thrown.");
130: } catch (Throwable t) {
131:
132: }
133: }
134:
135: public static class TestResourceBundle extends ListResourceBundle {
136:
137: private final Object[][] contents = {
138: { "javax.portlet.title", "Bundle Title" },
139: { "javax.portlet.short-title", "Bundle Short Title" },
140: { "javax.portlet.keywords", "Bundle Keywords" } };
141:
142: protected Object[][] getContents() {
143: return contents;
144: }
145: }
146:
147: }
|