001: /**
002: *
003: * Copyright 2004 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * 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: */package org.apache.ws.scout.registry.infomodel;
017:
018: import java.util.ArrayList;
019: import java.util.Collection;
020: import java.util.Locale;
021:
022: import javax.xml.registry.JAXRException;
023: import javax.xml.registry.infomodel.InternationalString;
024: import javax.xml.registry.infomodel.LocalizedString;
025:
026: import junit.framework.TestCase;
027:
028: /**
029: * @version $Revision$ $Date$
030: */
031: public class InternationalStringTest extends TestCase {
032: private Locale defaultLocale;
033: private LocalizedString defaultString;
034: private LocalizedString usString;
035: private LocalizedString ukString;
036: private LocalizedString caString;
037:
038: public void testAddLocalizedString() throws JAXRException {
039: InternationalString is = new InternationalStringImpl(Locale.US,
040: "USA", LocalizedString.DEFAULT_CHARSET_NAME);
041: Collection localizedStrings = is.getLocalizedStrings();
042: assertEquals(1, localizedStrings.size());
043: assertTrue(localizedStrings.contains(usString));
044: is.addLocalizedString(ukString);
045: localizedStrings = is.getLocalizedStrings();
046: assertEquals(2, localizedStrings.size());
047: assertTrue(localizedStrings.contains(usString));
048: assertTrue(localizedStrings.contains(ukString));
049:
050: // add again and see that we overwrite
051: is.addLocalizedString(ukString);
052: localizedStrings = is.getLocalizedStrings();
053: assertEquals(2, localizedStrings.size());
054: assertTrue(localizedStrings.contains(usString));
055: assertTrue(localizedStrings.contains(ukString));
056: }
057:
058: public void testAddLocalizedStrings() throws JAXRException {
059: InternationalString is = new InternationalStringImpl(Locale.US,
060: "USA", LocalizedString.DEFAULT_CHARSET_NAME);
061: Collection localizedStrings = is.getLocalizedStrings();
062: assertEquals(1, localizedStrings.size());
063: assertTrue(localizedStrings.contains(usString));
064: ArrayList<LocalizedString> strings = new ArrayList<LocalizedString>(
065: 2);
066: strings.add(ukString);
067: strings.add(caString);
068: is.addLocalizedStrings(strings);
069: localizedStrings = is.getLocalizedStrings();
070: assertEquals(3, localizedStrings.size());
071: assertTrue(localizedStrings.contains(usString));
072: assertTrue(localizedStrings.contains(caString));
073: assertTrue(localizedStrings.contains(ukString));
074: }
075:
076: public void testGetValue() throws JAXRException {
077: InternationalString is = new InternationalStringImpl();
078: is.addLocalizedString(usString);
079: is.addLocalizedString(defaultString);
080: is.addLocalizedString(ukString);
081: assertEquals("default", is.getValue());
082: }
083:
084: public void testSetValue() throws JAXRException {
085: InternationalString is = new InternationalStringImpl();
086: is.addLocalizedString(defaultString);
087: is.setValue("foo");
088: assertEquals("foo", is.getValue());
089: }
090:
091: public void testGetValueWithLocale() throws JAXRException {
092: InternationalString is = new InternationalStringImpl();
093: is.addLocalizedString(usString);
094: is.addLocalizedString(ukString);
095: assertEquals("USA", is.getValue(Locale.US));
096: }
097:
098: public void testGetValueWithUndefinedLocale() throws JAXRException {
099: InternationalString is = new InternationalStringImpl();
100: is.addLocalizedString(usString);
101: assertNull(is.getValue(Locale.UK));
102: }
103:
104: public void testSetValueWithLocale() throws JAXRException {
105: InternationalString is = new InternationalStringImpl();
106: is.addLocalizedString(usString);
107: is.addLocalizedString(ukString);
108: is.setValue(Locale.US, "foo");
109: assertEquals("foo", is.getValue(Locale.US));
110: assertEquals("England", is.getValue(Locale.UK));
111: assertEquals(2, is.getLocalizedStrings().size());
112: }
113:
114: public void testRemoveLocalizedString() throws JAXRException {
115: InternationalString is = new InternationalStringImpl();
116: is.addLocalizedString(usString);
117: is.addLocalizedString(ukString);
118: is.addLocalizedString(caString);
119: assertEquals(3, is.getLocalizedStrings().size());
120: is.removeLocalizedString(ukString);
121: Collection localizedStrings = is.getLocalizedStrings();
122: assertEquals(2, localizedStrings.size());
123: assertTrue(localizedStrings.contains(usString));
124: assertFalse(localizedStrings.contains(ukString));
125: assertTrue(localizedStrings.contains(caString));
126: }
127:
128: public void testRemoveLocalizedStrings() throws JAXRException {
129: InternationalString is = new InternationalStringImpl();
130: is.addLocalizedString(usString);
131: is.addLocalizedString(ukString);
132: is.addLocalizedString(caString);
133: assertEquals(3, is.getLocalizedStrings().size());
134: Collection<LocalizedString> localizedStrings = new ArrayList<LocalizedString>();
135: localizedStrings.add(usString);
136: localizedStrings.add(caString);
137: is.removeLocalizedStrings(localizedStrings);
138: localizedStrings = is.getLocalizedStrings();
139: assertEquals(1, localizedStrings.size());
140: assertFalse(localizedStrings.contains(usString));
141: assertTrue(localizedStrings.contains(ukString));
142: assertFalse(localizedStrings.contains(caString));
143: }
144:
145: public void testGetLocalizedString() throws JAXRException {
146: InternationalString is = new InternationalStringImpl();
147: is.addLocalizedString(usString);
148: assertEquals(usString, is.getLocalizedString(Locale.US,
149: LocalizedString.DEFAULT_CHARSET_NAME));
150: assertNull(is.getLocalizedString(Locale.US, "US-ASCII"));
151: }
152:
153: protected void setUp() throws Exception {
154: super .setUp();
155: defaultLocale = Locale.getDefault();
156: defaultString = new LocalizedStringImpl(defaultLocale,
157: "default", LocalizedString.DEFAULT_CHARSET_NAME);
158: usString = new LocalizedStringImpl(Locale.US, "USA",
159: LocalizedString.DEFAULT_CHARSET_NAME);
160: ukString = new LocalizedStringImpl(Locale.UK, "England",
161: LocalizedString.DEFAULT_CHARSET_NAME);
162: caString = new LocalizedStringImpl(Locale.CANADA, "Canada",
163: LocalizedString.DEFAULT_CHARSET_NAME);
164: }
165: }
|