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: */package org.superbiz;
017:
018: import junit.framework.TestCase;
019:
020: import javax.naming.InitialContext;
021: import javax.naming.Context;
022: import java.util.Locale;
023: import java.util.Properties;
024:
025: /**
026: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
027: *
028: * @version $Rev: 601953 $ $Date: 2007-12-06 17:09:47 -0800 $
029: */
030: public class FriendlyPersonTest extends TestCase {
031: private InitialContext initialContext;
032:
033: protected void setUp() throws Exception {
034: Properties properties = new Properties();
035: properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
036: "org.apache.openejb.client.LocalInitialContextFactory");
037: initialContext = new InitialContext(properties);
038: }
039:
040: /**
041: * Here we lookup and test the FriendlyPerson bean via its EJB 2.1 EJBHome and EJBObject interfaces
042: *
043: * @throws Exception
044: */
045: public void testEjbHomeAndEjbObject() throws Exception {
046: Object object = initialContext
047: .lookup("FriendlyPersonRemoteHome");
048: FriendlyPersonEjbHome home = (FriendlyPersonEjbHome) object;
049: FriendlyPersonEjbObject friendlyPerson = home.create();
050:
051: friendlyPerson.setDefaultLanguage("en");
052:
053: assertEquals("Hello David!", friendlyPerson.greet("David"));
054: assertEquals("Hello Amelia!", friendlyPerson.greet("Amelia"));
055:
056: friendlyPerson.setLanguagePreferences("Amelia", "es");
057:
058: assertEquals("Hello David!", friendlyPerson.greet("David"));
059: assertEquals("Hola Amelia!", friendlyPerson.greet("Amelia"));
060:
061: // Amelia took some French, let's see if she remembers
062: assertEquals("Bonjour Amelia!", friendlyPerson.greet("fr",
063: "Amelia"));
064:
065: // Dave should take some Polish and if he had, he could say Hi in Polish
066: assertEquals("Witaj Dave!", friendlyPerson.greet("pl", "Dave"));
067:
068: // Let's see if I speak Portuguese
069: assertEquals("Sorry, I don't speak "
070: + new Locale("pt").getDisplayLanguage() + ".",
071: friendlyPerson.greet("pt", "David"));
072:
073: // Ok, well I've been meaning to learn, so...
074: friendlyPerson.addGreeting("pt", "Ola {0}!");
075:
076: assertEquals("Ola David!", friendlyPerson.greet("pt", "David"));
077: }
078:
079: /**
080: * Here we lookup and test the FriendlyPerson bean via its EJB 2.1 EJBLocalHome and EJBLocalObject interfaces
081: *
082: * @throws Exception
083: */
084: public void testEjbLocalHomeAndEjbLocalObject() throws Exception {
085: Object object = initialContext
086: .lookup("FriendlyPersonLocalHome");
087: FriendlyPersonEjbLocalHome home = (FriendlyPersonEjbLocalHome) object;
088: FriendlyPersonEjbLocalObject friendlyPerson = home.create();
089:
090: friendlyPerson.setDefaultLanguage("en");
091:
092: assertEquals("Hello David!", friendlyPerson.greet("David"));
093: assertEquals("Hello Amelia!", friendlyPerson.greet("Amelia"));
094:
095: friendlyPerson.setLanguagePreferences("Amelia", "es");
096:
097: assertEquals("Hello David!", friendlyPerson.greet("David"));
098: assertEquals("Hola Amelia!", friendlyPerson.greet("Amelia"));
099:
100: // Amelia took some French, let's see if she remembers
101: assertEquals("Bonjour Amelia!", friendlyPerson.greet("fr",
102: "Amelia"));
103:
104: // Dave should take some Polish and if he had, he could say Hi in Polish
105: assertEquals("Witaj Dave!", friendlyPerson.greet("pl", "Dave"));
106:
107: // Let's see if I speak Portuguese
108: assertEquals("Sorry, I don't speak "
109: + new Locale("pt").getDisplayLanguage() + ".",
110: friendlyPerson.greet("pt", "David"));
111:
112: // Ok, well I've been meaning to learn, so...
113: friendlyPerson.addGreeting("pt", "Ola {0}!");
114:
115: assertEquals("Ola David!", friendlyPerson.greet("pt", "David"));
116: }
117:
118: /**
119: * Here we lookup and test the FriendlyPerson bean via its EJB 3.0 business remote interface
120: *
121: * @throws Exception
122: */
123: public void testBusinessRemote() throws Exception {
124: Object object = initialContext.lookup("FriendlyPersonRemote");
125:
126: FriendlyPersonRemote friendlyPerson = (FriendlyPersonRemote) object;
127:
128: friendlyPerson.setDefaultLanguage("en");
129:
130: assertEquals("Hello David!", friendlyPerson.greet("David"));
131: assertEquals("Hello Amelia!", friendlyPerson.greet("Amelia"));
132:
133: friendlyPerson.setLanguagePreferences("Amelia", "es");
134:
135: assertEquals("Hello David!", friendlyPerson.greet("David"));
136: assertEquals("Hola Amelia!", friendlyPerson.greet("Amelia"));
137:
138: // Amelia took some French, let's see if she remembers
139: assertEquals("Bonjour Amelia!", friendlyPerson.greet("fr",
140: "Amelia"));
141:
142: // Dave should take some Polish and if he had, he could say Hi in Polish
143: assertEquals("Witaj Dave!", friendlyPerson.greet("pl", "Dave"));
144:
145: // Let's see if I speak Portuguese
146: assertEquals("Sorry, I don't speak "
147: + new Locale("pt").getDisplayLanguage() + ".",
148: friendlyPerson.greet("pt", "David"));
149:
150: // Ok, well I've been meaning to learn, so...
151: friendlyPerson.addGreeting("pt", "Ola {0}!");
152:
153: assertEquals("Ola David!", friendlyPerson.greet("pt", "David"));
154: }
155:
156: /**
157: * Here we lookup and test the FriendlyPerson bean via its EJB 3.0 business local interface
158: *
159: * @throws Exception
160: */
161: public void testBusinessLocal() throws Exception {
162: Object object = initialContext.lookup("FriendlyPersonLocal");
163:
164: FriendlyPersonLocal friendlyPerson = (FriendlyPersonLocal) object;
165:
166: friendlyPerson.setDefaultLanguage("en");
167:
168: assertEquals("Hello David!", friendlyPerson.greet("David"));
169: assertEquals("Hello Amelia!", friendlyPerson.greet("Amelia"));
170:
171: friendlyPerson.setLanguagePreferences("Amelia", "es");
172:
173: assertEquals("Hello David!", friendlyPerson.greet("David"));
174: assertEquals("Hola Amelia!", friendlyPerson.greet("Amelia"));
175:
176: // Amelia took some French, let's see if she remembers
177: assertEquals("Bonjour Amelia!", friendlyPerson.greet("fr",
178: "Amelia"));
179:
180: // Dave should take some Polish and if he had, he could say Hi in Polish
181: assertEquals("Witaj Dave!", friendlyPerson.greet("pl", "Dave"));
182:
183: // Let's see if I speak Portuguese
184: assertEquals("Sorry, I don't speak "
185: + new Locale("pt").getDisplayLanguage() + ".",
186: friendlyPerson.greet("pt", "David"));
187:
188: // Ok, well I've been meaning to learn, so...
189: friendlyPerson.addGreeting("pt", "Ola {0}!");
190:
191: assertEquals("Ola David!", friendlyPerson.greet("pt", "David"));
192: }
193:
194: }
|