01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.openjpa.persistence.kernel;
20:
21: import java.util.Iterator;
22: import java.util.List;
23: import java.util.Locale;
24: import javax.persistence.EntityManager;
25:
26: import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
27: import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
28:
29: public class TestEJBLocales extends AbstractTestCase {
30:
31: public TestEJBLocales(String name) {
32: super (name, "kernelcactusapp");
33: }
34:
35: public void setUp() {
36: deleteAll(RuntimeTest1.class);
37: }
38:
39: public void testLocales() {
40: EntityManager pm = currentEntityManager();
41: startTx(pm);
42: RuntimeTest1 t1 = new RuntimeTest1(1);
43: t1.setLocaleField(new Locale(Locale.FRANCE.getCountry(),
44: Locale.FRENCH.getLanguage()));
45: pm.persist(t1);
46: pm.persist(new RuntimeTest1(2));
47: endTx(pm);
48: endEm(pm);
49:
50: pm = currentEntityManager();
51: List c = findAll(RuntimeTest1.class, pm);
52: assertEquals(2, c.size());
53:
54: boolean foundNull = false;
55: boolean foundFrance = false;
56: Locale locale;
57:
58: for (Iterator iter = c.iterator(); iter.hasNext();) {
59: t1 = (RuntimeTest1) iter.next();
60: locale = t1.getLocaleField();
61: if (locale == null)
62: foundNull = true;
63: else if ((locale.getCountry().equals(Locale.FRANCE
64: .getCountry()))
65: && (locale.getLanguage().equals(Locale.FRANCE
66: .getLanguage())))
67: foundFrance = true;
68: }
69:
70: assertTrue(foundNull);
71: assertTrue(foundFrance);
72: endEm(pm);
73: }
74:
75: public List findAll(Class c, EntityManager em) {
76: List l = em.createQuery("Select object(o) from RuntimeTest1 o")
77: .getResultList();
78: return l;
79: }
80: }
|