@Test public void testWarnings() throws Exception { ConnectionImpl conn = Mockito.mock(ConnectionImpl.class); DQP dqp = Mockito.mock(DQP.class); ResultsFuture<ResultsMessage> results = new ResultsFuture<ResultsMessage>(); Mockito.stub(dqp.executeRequest(Mockito.anyLong(), (RequestMessage) Mockito.anyObject())) .toReturn(results); ResultsMessage rm = new ResultsMessage(); rm.setResults(new List<?>[] {Arrays.asList(1)}); rm.setWarnings(Arrays.asList(new Throwable())); rm.setColumnNames(new String[] {"expr1"}); rm.setDataTypes(new String[] {"string"}); results.getResultsReceiver().receiveResults(rm); Mockito.stub(conn.getDQP()).toReturn(dqp); StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY) { @Override protected java.util.TimeZone getServerTimeZone() throws java.sql.SQLException { return null; } }; statement.execute("select 'a'"); assertNotNull(statement.getResultSet()); SQLWarning warning = statement.getWarnings(); assertNotNull(warning); assertNull(warning.getNextWarning()); }
@Test public void testBatchExecution() throws Exception { ConnectionImpl conn = Mockito.mock(ConnectionImpl.class); DQP dqp = Mockito.mock(DQP.class); ResultsFuture<ResultsMessage> results = new ResultsFuture<ResultsMessage>(); Mockito.stub(dqp.executeRequest(Mockito.anyLong(), (RequestMessage) Mockito.anyObject())) .toReturn(results); ResultsMessage rm = new ResultsMessage(); rm.setResults(new List<?>[] {Arrays.asList(1), Arrays.asList(2)}); rm.setUpdateResult(true); results.getResultsReceiver().receiveResults(rm); Mockito.stub(conn.getDQP()).toReturn(dqp); StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); statement.clearBatch(); // previously caused npe statement.addBatch("delete from table"); // $NON-NLS-1$ statement.addBatch("delete from table1"); // $NON-NLS-1$ assertTrue(Arrays.equals(new int[] {1, 2}, statement.executeBatch())); }