jdk/test/javax/sql/testng/test/rowset/RowSetWarningTests.java
author lancea
Tue, 21 Oct 2014 13:41:22 -0400
changeset 27183 5260f53ce305
permissions -rw-r--r--
8059411: RowSetWarning does not chain warnings Reviewed-by: darcy, smarks, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27183
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
     1
/*
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
     4
 *
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
     8
 *
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    13
 * accompanied this code).
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    14
 *
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    18
 *
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    21
 * questions.
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    22
 */
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    23
package test.rowset;
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    24
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    25
import java.sql.SQLException;
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    26
import javax.sql.rowset.RowSetWarning;
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    27
import static org.testng.Assert.*;
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    28
import org.testng.annotations.Test;
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    29
import util.BaseTest;
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    30
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    31
public class RowSetWarningTests extends BaseTest {
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    32
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    33
    private final String[] warnings = {"Warning 1", "cause 1", "Warning 2",
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    34
        "Warning 3", "cause 2"};
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    35
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    36
    /*
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    37
     * Create RowSetWarning and setting all objects to null
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    38
     */
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    39
    @Test
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    40
    public void test() {
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    41
        RowSetWarning e = new RowSetWarning(null, null, errorCode);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    42
        assertTrue(e.getMessage() == null && e.getSQLState() == null
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    43
                && e.getCause() == null && e.getErrorCode() == errorCode);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    44
    }
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    45
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    46
    /*
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    47
     * Create RowSetWarning with no-arg constructor
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    48
     */
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    49
    @Test
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    50
    public void test01() {
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    51
        RowSetWarning ex = new RowSetWarning();
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    52
        assertTrue(ex.getMessage() == null
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    53
                && ex.getSQLState() == null
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    54
                && ex.getCause() == null
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    55
                && ex.getErrorCode() == 0);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    56
    }
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    57
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    58
    /*
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    59
     * Create RowSetWarning with message
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    60
     */
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    61
    @Test
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    62
    public void test02() {
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    63
        RowSetWarning ex = new RowSetWarning(reason);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    64
        assertTrue(ex.getMessage().equals(reason)
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    65
                && ex.getSQLState() == null
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    66
                && ex.getCause() == null
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    67
                && ex.getErrorCode() == 0);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    68
    }
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    69
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    70
    /*
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    71
     * Create RowSetWarning with message, and SQLState
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    72
     */
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    73
    @Test
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    74
    public void test03() {
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    75
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    76
        RowSetWarning ex = new RowSetWarning(reason, state);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    77
        assertTrue(ex.getMessage().equals(reason)
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    78
                && ex.getSQLState().equals(state)
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    79
                && ex.getCause() == null
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    80
                && ex.getErrorCode() == 0);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    81
    }
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    82
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    83
    /*
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    84
     * Create RowSetWarning with message, SQLState, and error code
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    85
     */
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    86
    @Test
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    87
    public void test04() {
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    88
        RowSetWarning ex = new RowSetWarning(reason, state, errorCode);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    89
        assertTrue(ex.getMessage().equals(reason)
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    90
                && ex.getSQLState().equals(state)
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    91
                && ex.getCause() == null
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    92
                && ex.getErrorCode() == errorCode);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    93
    }
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    94
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    95
    /*
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    96
     * Serialize a RowSetWarning and make sure you can read it back properly
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    97
     */
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    98
    @Test
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
    99
    public void test05() throws Exception {
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   100
        RowSetWarning e = new RowSetWarning(reason, state, errorCode);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   101
        e.initCause(t);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   102
        RowSetWarning ex1 = createSerializedException(e);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   103
        assertTrue(reason.equals(ex1.getMessage())
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   104
                && ex1.getSQLState().equals(state)
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   105
                && cause.equals(ex1.getCause().toString())
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   106
                && ex1.getErrorCode() == errorCode);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   107
    }
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   108
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   109
    /*
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   110
     * Validate that the ordering of the returned Exceptions is correct using
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   111
     * for-each loop
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   112
     */
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   113
    @Test
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   114
    public void test06() {
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   115
        RowSetWarning ex = new RowSetWarning("Exception 1");
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   116
        ex.initCause(t1);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   117
        RowSetWarning ex1 = new RowSetWarning("Exception 2");
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   118
        RowSetWarning ex2 = new RowSetWarning("Exception 3");
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   119
        ex2.initCause(t2);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   120
        ex.setNextException(ex1);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   121
        ex.setNextException(ex2);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   122
        int num = 0;
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   123
        for (Throwable e : ex) {
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   124
            assertTrue(msgs[num++].equals(e.getMessage()));
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   125
        }
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   126
    }
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   127
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   128
    /*
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   129
     * Validate that the ordering of the returned Exceptions is correct using
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   130
     * traditional while loop
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   131
     */
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   132
    @Test
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   133
    public void test07() {
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   134
        RowSetWarning ex = new RowSetWarning("Exception 1");
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   135
        ex.initCause(t1);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   136
        RowSetWarning ex1 = new RowSetWarning("Exception 2");
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   137
        RowSetWarning ex2 = new RowSetWarning("Exception 3");
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   138
        ex2.initCause(t2);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   139
        ex.setNextException(ex1);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   140
        ex.setNextException(ex2);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   141
        int num = 0;
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   142
        SQLException sqe = ex;
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   143
        while (sqe != null) {
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   144
            assertTrue(msgs[num++].equals(sqe.getMessage()));
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   145
            Throwable c = sqe.getCause();
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   146
            while (c != null) {
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   147
                assertTrue(msgs[num++].equals(c.getMessage()));
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   148
                c = c.getCause();
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   149
            }
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   150
            sqe = sqe.getNextException();
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   151
        }
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   152
    }
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   153
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   154
    /*
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   155
     * Validate that the ordering of the returned RowSetWarning is correct using
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   156
     * for-each loop
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   157
     */
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   158
    @Test
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   159
    public void test08() {
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   160
        RowSetWarning ex = new RowSetWarning("Warning 1");
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   161
        ex.initCause(t1);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   162
        RowSetWarning ex1 = new RowSetWarning("Warning 2");
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   163
        RowSetWarning ex2 = new RowSetWarning("Warning 3");
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   164
        ex2.initCause(t2);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   165
        ex.setNextWarning(ex1);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   166
        ex.setNextWarning(ex2);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   167
        int num = 0;
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   168
        for (Throwable e : ex) {
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   169
            assertTrue(warnings[num++].equals(e.getMessage()));
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   170
        }
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   171
    }
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   172
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   173
    /**
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   174
     * Validate that the ordering of the returned RowSetWarning is correct using
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   175
     * traditional while loop
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   176
     */
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   177
    @Test
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   178
    public void test09() {
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   179
        RowSetWarning ex = new RowSetWarning("Warning 1");
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   180
        ex.initCause(t1);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   181
        RowSetWarning ex1 = new RowSetWarning("Warning 2");
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   182
        RowSetWarning ex2 = new RowSetWarning("Warning 3");
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   183
        ex2.initCause(t2);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   184
        ex.setNextWarning(ex1);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   185
        ex.setNextWarning(ex2);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   186
        int num = 0;
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   187
        RowSetWarning sqe = ex;
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   188
        while (sqe != null) {
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   189
            assertTrue(warnings[num++].equals(sqe.getMessage()));
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   190
            Throwable c = sqe.getCause();
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   191
            while (c != null) {
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   192
                assertTrue(msgs[num++].equals(c.getMessage()));
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   193
                c = c.getCause();
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   194
            }
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   195
            sqe = sqe.getNextWarning();
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   196
        }
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   197
    }
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   198
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   199
    /*
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   200
     * Serialize a RowSetWarning and make sure you can read it back properly
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   201
     */
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   202
    @Test
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   203
    public void test10() throws Exception {
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   204
        RowSetWarning e = new RowSetWarning(reason, state, errorCode);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   205
        RowSetWarning ex1 = createSerializedException(e);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   206
        assertTrue(reason.equals(ex1.getMessage())
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   207
                && ex1.getSQLState().equals(state)
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   208
                && ex1.getCause() == null
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   209
                && ex1.getErrorCode() == errorCode);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   210
    }
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   211
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   212
    /*
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   213
     *  Serialize a RowSetWarning and make sure you can read it back properly.
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   214
     * Validate that the ordering of the returned RowSetWarning is correct using
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   215
     * traditional while loop
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   216
     */
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   217
    @Test
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   218
    public void test11() throws Exception {
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   219
        RowSetWarning ex = new RowSetWarning("Warning 1");
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   220
        ex.initCause(t1);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   221
        RowSetWarning ex1 = new RowSetWarning("Warning 2");
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   222
        RowSetWarning ex2 = new RowSetWarning("Warning 3");
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   223
        ex2.initCause(t2);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   224
        ex.setNextWarning(ex1);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   225
        ex.setNextWarning(ex2);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   226
        int num = 0;
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   227
        RowSetWarning sqe = createSerializedException(ex);
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   228
        while (sqe != null) {
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   229
            assertTrue(warnings[num++].equals(sqe.getMessage()));
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   230
            Throwable c = sqe.getCause();
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   231
            while (c != null) {
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   232
                assertTrue(msgs[num++].equals(c.getMessage()));
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   233
                c = c.getCause();
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   234
            }
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   235
            sqe = sqe.getNextWarning();
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   236
        }
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   237
    }
5260f53ce305 8059411: RowSetWarning does not chain warnings
lancea
parents:
diff changeset
   238
}