test/java/sql/test/sql/DataTruncationTests.java
Print this page
*** 20,91 ****
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package test.sql;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.sql.SQLException;
import java.sql.DataTruncation;
import static org.testng.Assert.*;
- import org.testng.annotations.AfterClass;
- import org.testng.annotations.AfterMethod;
- import org.testng.annotations.BeforeClass;
- import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
! public class DataTruncationTests {
private final String READ_TRUNCATION = "01004";
private final String WRITE_TRUNCATION = "22001";
! private final String reason = "Data truncation";
! private final String cause = "java.lang.Throwable: cause";
! private final Throwable t = new Throwable("cause");
! private final Throwable t1 = new Throwable("cause 1");
! private final Throwable t2 = new Throwable("cause 2");
! private final int errorCode = 0;
! private final String[] msgs = {reason, "cause 1", reason,
! reason, "cause 2"};
private boolean onRead = false;
private final boolean parameter = false;
private final int index = 21;
private final int dataSize = 25;
private final int transferSize = 10;
- public DataTruncationTests() {
- }
-
- @BeforeClass
- public static void setUpClass() throws Exception {
- }
-
- @AfterClass
- public static void tearDownClass() throws Exception {
- }
-
- @BeforeMethod
- public void setUpMethod() throws Exception {
- }
-
- @AfterMethod
- public void tearDownMethod() throws Exception {
- }
-
/**
* Create DataTruncation object indicating a truncation on read
*/
@Test
public void test() {
onRead = true;
DataTruncation e = new DataTruncation(index, parameter, onRead,
dataSize, transferSize);
! assertTrue(e.getMessage().equals(reason)
&& e.getSQLState().equals(READ_TRUNCATION)
&& e.getCause() == null
! && e.getErrorCode() == errorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == index);
--- 20,61 ----
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package test.sql;
import java.sql.DataTruncation;
+ import java.sql.SQLException;
import static org.testng.Assert.*;
import org.testng.annotations.Test;
+ import util.BaseTest;
! public class DataTruncationTests extends BaseTest {
private final String READ_TRUNCATION = "01004";
private final String WRITE_TRUNCATION = "22001";
! private final String dtReason = "Data truncation";
! private final int dterrorCode = 0;
! private final String[] dtmsgs = {dtReason, "cause 1", dtReason,
! dtReason, "cause 2"};
private boolean onRead = false;
private final boolean parameter = false;
private final int index = 21;
private final int dataSize = 25;
private final int transferSize = 10;
/**
* Create DataTruncation object indicating a truncation on read
*/
@Test
public void test() {
onRead = true;
DataTruncation e = new DataTruncation(index, parameter, onRead,
dataSize, transferSize);
! assertTrue(e.getMessage().equals(dtReason)
&& e.getSQLState().equals(READ_TRUNCATION)
&& e.getCause() == null
! && e.getErrorCode() == dterrorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == index);
*** 97,110 ****
@Test
public void test1() {
onRead = false;
DataTruncation e = new DataTruncation(index, parameter, onRead,
dataSize, transferSize);
! assertTrue(e.getMessage().equals(reason)
&& e.getSQLState().equals(WRITE_TRUNCATION)
&& e.getCause() == null
! && e.getErrorCode() == errorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == index);
--- 67,80 ----
@Test
public void test1() {
onRead = false;
DataTruncation e = new DataTruncation(index, parameter, onRead,
dataSize, transferSize);
! assertTrue(e.getMessage().equals(dtReason)
&& e.getSQLState().equals(WRITE_TRUNCATION)
&& e.getCause() == null
! && e.getErrorCode() == dterrorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == index);
*** 117,130 ****
@Test
public void test2() {
onRead = true;
DataTruncation e = new DataTruncation(index, parameter, onRead,
dataSize, transferSize, t);
! assertTrue(e.getMessage().equals(reason)
&& e.getSQLState().equals(READ_TRUNCATION)
&& cause.equals(e.getCause().toString())
! && e.getErrorCode() == errorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == index);
--- 87,100 ----
@Test
public void test2() {
onRead = true;
DataTruncation e = new DataTruncation(index, parameter, onRead,
dataSize, transferSize, t);
! assertTrue(e.getMessage().equals(dtReason)
&& e.getSQLState().equals(READ_TRUNCATION)
&& cause.equals(e.getCause().toString())
! && e.getErrorCode() == dterrorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == index);
*** 137,150 ****
@Test
public void test3() {
onRead = true;;
DataTruncation e = new DataTruncation(index, parameter, onRead,
dataSize, transferSize, null);
! assertTrue(e.getMessage().equals(reason)
&& e.getSQLState().equals(READ_TRUNCATION)
&& e.getCause() == null
! && e.getErrorCode() == errorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == index);
--- 107,120 ----
@Test
public void test3() {
onRead = true;;
DataTruncation e = new DataTruncation(index, parameter, onRead,
dataSize, transferSize, null);
! assertTrue(e.getMessage().equals(dtReason)
&& e.getSQLState().equals(READ_TRUNCATION)
&& e.getCause() == null
! && e.getErrorCode() == dterrorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == index);
*** 158,171 ****
public void test4() {
onRead = true;
int negIndex = -1;
DataTruncation e = new DataTruncation(negIndex, parameter, onRead,
dataSize, transferSize);
! assertTrue(e.getMessage().equals(reason)
&& e.getSQLState().equals(READ_TRUNCATION)
&& e.getCause() == null
! && e.getErrorCode() == errorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == negIndex);
--- 128,141 ----
public void test4() {
onRead = true;
int negIndex = -1;
DataTruncation e = new DataTruncation(negIndex, parameter, onRead,
dataSize, transferSize);
! assertTrue(e.getMessage().equals(dtReason)
&& e.getSQLState().equals(READ_TRUNCATION)
&& e.getCause() == null
! && e.getErrorCode() == dterrorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == negIndex);
*** 176,196 ****
*/
@Test
public void test5() throws Exception {
DataTruncation e = new DataTruncation(index, parameter, onRead,
dataSize, transferSize);
! ObjectOutputStream out
! = new ObjectOutputStream(
! new FileOutputStream("DataTruncation.ser"));
! out.writeObject(e);
! ObjectInputStream is = new ObjectInputStream(
! new FileInputStream("DataTruncation.ser"));
! DataTruncation ex1 = (DataTruncation) is.readObject();
! assertTrue(e.getMessage().equals(reason)
&& e.getSQLState().equals(READ_TRUNCATION)
&& e.getCause() == null
! && e.getErrorCode() == errorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == index);
--- 146,160 ----
*/
@Test
public void test5() throws Exception {
DataTruncation e = new DataTruncation(index, parameter, onRead,
dataSize, transferSize);
! DataTruncation ex1 = createSerializedException(e, "DataTruncation.ser");
! assertTrue(e.getMessage().equals(dtReason)
&& e.getSQLState().equals(READ_TRUNCATION)
&& e.getCause() == null
! && e.getErrorCode() == dterrorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == index);
*** 210,220 ****
dataSize, transferSize, t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
for (Throwable e : ex) {
! assertTrue(msgs[num++].equals(e.getMessage()));
}
}
/**
* Validate that the ordering of the returned Exceptions is correct using
--- 174,184 ----
dataSize, transferSize, t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
for (Throwable e : ex) {
! assertTrue(dtmsgs[num++].equals(e.getMessage()));
}
}
/**
* Validate that the ordering of the returned Exceptions is correct using
*** 231,244 ****
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
SQLException sqe = ex;
while (sqe != null) {
! assertTrue(msgs[num++].equals(sqe.getMessage()));
Throwable c = sqe.getCause();
while (c != null) {
! assertTrue(msgs[num++].equals(c.getMessage()));
c = c.getCause();
}
sqe = sqe.getNextException();
}
}
--- 195,208 ----
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
SQLException sqe = ex;
while (sqe != null) {
! assertTrue(dtmsgs[num++].equals(sqe.getMessage()));
Throwable c = sqe.getCause();
while (c != null) {
! assertTrue(dtmsgs[num++].equals(c.getMessage()));
c = c.getCause();
}
sqe = sqe.getNextException();
}
}