MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DomainTypeHandlerFactoryTest.java
1 /*
2  Copyright 2010 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 package testsuite.clusterj;
20 
21 import testsuite.clusterj.model.CrazyDelegate;
22 import testsuite.clusterj.model.ThrowNullPointerException;
23 
52 
53  @Override
54  public void localSetUp() {
55  createSessionFactory();
56  session = sessionFactory.getSession();
57  }
58 
59  public void testThrowNullPointerException() {
60  try {
62  // This should cause CrazyDomainTypeHandlerFactoryImpl to throw
63  // a NullPointerException which should be ignored. But the standard
64  // implementation doesn't like ThrowNullPointerException either,
65  // so it should throw an exception. But the error message should
66  // contain the original NullPointerException that was thrown by
67  // CrazyDomainTypeHandlerFactoryImpl.
68  session.makePersistent(instance);
69  error("Failed to catch RuntimeException");
70  } catch (RuntimeException e) {
71  if (!e.getMessage().contains("java.lang.NullPointerException")) {
72  error("Failed to catch correct exception, but caught: " + e.toString());
73  }
74  // good catch
75  }
76  failOnError();
77  }
78 
79  public void testCrazyDelegate() {
80  try {
81  CrazyDelegate instance = new CrazyDelegate();
82  // This should fail at CrazyDomainTypeHandlerFactoryImpl.getProxyClass()
83  // It's a bit of a cheat since it relies on the internal implementation
84  // of SessionFactoryImpl.getDomainTypeHandler
85  session.makePersistent(instance);
86  error("Failed to catch UnsupportedOperationException");
87  } catch (UnsupportedOperationException ex) {
88  String message = ex.getMessage();
89  Throwable cause = ex.getCause();
90  String causeMessage = cause==null?"null":cause.getMessage();
91  if (!message.contains("Nice Job!")) {
92  error("Failed to catch correct exception, but caught: " + message + "; cause: " + causeMessage);
93  }
94  }
95  failOnError();
96  }
97 }