1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package org.apache.harmony.sql.tests.javax.sql; 19 20import java.io.Serializable; 21import java.sql.SQLException; 22 23import javax.sql.PooledConnection; 24import javax.sql.StatementEvent; 25 26import junit.framework.TestCase; 27 28import org.apache.harmony.testframework.serialization.SerializationTest; 29import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert; 30 31/** 32 * Test class for javax.sql.StatementEvent. 33 * 34 * @since 1.6 35 */ 36public class StatementEventTest extends TestCase { 37 38 private static PooledConnection pc = new Impl_PooledConnection(); 39 40 private static StatementEvent st = new StatementEvent(pc, null); 41 42 /** 43 * @tests {@link javax.sql.StatementEvent#StatementEvent(PooledConnection, java.sql.PreparedStatement)} 44 */ 45 public void testStatementEventPooledConnectionPreparedStatementSQLException() { 46 SQLException e = new SQLException(); 47 StatementEvent st2 = new StatementEvent(pc, null, e); 48 assertNotNull(st2); 49 50 assertEquals(e, st2.getSQLException()); 51 } 52 53 /** 54 * @tests {@link javax.sql.StatementEvent#StatementEvent(PooledConnection, java.sql.PreparedStatement)} 55 */ 56 public void testStatementEventPooledConnectionPreparedStatement() { 57 assertNotNull(st); 58 59 try { 60 new StatementEvent(null, null); 61 fail("should throw IllegalArgumentException"); 62 } catch (IllegalArgumentException e) { 63 // expected 64 } 65 } 66 67 /** 68 * @tests {@link javax.sql.StatementEvent#getStatement()} 69 */ 70 public void testGetStatement() { 71 assertNull(st.getStatement()); 72 } 73 74 /** 75 * @tests {@link javax.sql.StatementEvent#getSQLException()} 76 */ 77 public void testGetSQLException() { 78 assertNull(st.getSQLException()); 79 } 80 81 /** 82 * @tests serialization/deserialization compatibility. 83 */ 84 public void testSerializationSelf() throws Exception { 85 SerializationTest.verifySelf(st, STATEMENTEVENT_COMPARATOR); 86 } 87 88 /** 89 * @tests serialization/deserialization compatibility with RI. 90 */ 91 public void testSerializationCompatibility() throws Exception { 92 StatementEvent st3 = new StatementEvent(pc, null, new SQLException( 93 "test message")); 94 SerializationTest.verifyGolden(this, st3, STATEMENTEVENT_COMPARATOR); 95 } 96 97 private static final SerializableAssert STATEMENTEVENT_COMPARATOR = new SerializableAssert() { 98 99 public void assertDeserialized(Serializable initial, 100 Serializable deserialized) { 101 StatementEvent iniSt = (StatementEvent) initial; 102 StatementEvent dserSt = (StatementEvent) deserialized; 103 if (null != iniSt.getSQLException()) { 104 assertEquals(iniSt.getSQLException().getMessage(), dserSt 105 .getSQLException().getMessage()); 106 } 107 assertEquals(iniSt.getStatement(), dserSt.getStatement()); 108 } 109 110 }; 111} 112