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.conf;
20:
21: import java.util.*;
22:
23: import javax.persistence.*;
24: import javax.persistence.PersistenceException;
25:
26: import junit.framework.*;
27:
28: import org.apache.openjpa.lib.util.ParseException;
29: import org.apache.openjpa.persistence.*;
30:
31: public class TestBadAutoDetachProperty extends TestCase {
32: public void testEmptyValue() {
33: HashMap props = new HashMap(System.getProperties());
34: props.put("openjpa.AutoDetach", "");
35: EntityManagerFactory emf = (OpenJPAEntityManagerFactory) Persistence
36: .createEntityManagerFactory("test", props);
37: EntityManager em = emf.createEntityManager();
38: em.close();
39: emf.close();
40: }
41:
42: public void testCommaOnlyValue() {
43: try {
44: HashMap props = new HashMap(System.getProperties());
45: props.put("openjpa.AutoDetach", ",");
46: EntityManagerFactory emf = (OpenJPAEntityManagerFactory) Persistence
47: .createEntityManagerFactory("test", props);
48: EntityManager em = emf.createEntityManager();
49: em.close();
50: emf.close();
51: } catch (PersistenceException e) {
52: Throwable cause = e.getCause();
53: while (cause instanceof PersistenceException)
54: cause = ((PersistenceException) cause).getCause();
55: if (!(cause instanceof ParseException)) {
56: fail("Should have caught PersistenceException whose cause was "
57: + "a ParseException. "
58: + "Instead the cause was: " + cause);
59: }
60: } catch (RuntimeException e) {
61: fail("Should have caught a PersistenceException, instead caught: "
62: + e);
63: }
64: }
65:
66: public void testEmptyItemValue() {
67: try {
68: HashMap props = new HashMap(System.getProperties());
69: props.put("openjpa.AutoDetach", "close,,commit");
70: EntityManagerFactory emf = (OpenJPAEntityManagerFactory) Persistence
71: .createEntityManagerFactory("test", props);
72: EntityManager em = emf.createEntityManager();
73: em.close();
74: emf.close();
75: } catch (PersistenceException e) {
76: Throwable cause = e.getCause();
77: while (cause instanceof PersistenceException)
78: cause = ((PersistenceException) cause).getCause();
79: if (!(cause instanceof ParseException)) {
80: fail("Should have caught PersistenceException whose cause was "
81: + "a ParseException. "
82: + "Instead the cause was: " + cause);
83: }
84: } catch (RuntimeException e) {
85: fail("Should have caught a PersistenceException, instead caught: "
86: + e);
87: }
88: }
89: }
|