Search in sources :

Example 1 with MockStatement

use of com.mockrunner.mock.jdbc.MockStatement in project cayenne by apache.

the class JDBCResultIteratorTest method testNextDataRow.

@Test
public void testNextDataRow() throws Exception {
    Connection c = new MockConnection();
    Statement s = new MockStatement(c);
    MockResultSet rs = new MockResultSet("rs");
    rs.addColumn("a", new Object[] { "1", "2", "3" });
    RowDescriptor descriptor = new RowDescriptorBuilder().setResultSet(rs).getDescriptor(new ExtendedTypeMap());
    RowReader<?> rowReader = new DefaultRowReaderFactory().rowReader(descriptor, new MockQueryMetadata(), mock(DbAdapter.class), Collections.<ObjAttribute, ColumnDescriptor>emptyMap());
    JDBCResultIterator it = new JDBCResultIterator(s, rs, rowReader);
    DataRow row = (DataRow) it.nextRow();
    assertNotNull(row);
    assertEquals(1, row.size());
    assertEquals("1", row.get("a"));
}
Also used : MockStatement(com.mockrunner.mock.jdbc.MockStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) MockConnection(com.mockrunner.mock.jdbc.MockConnection) MockResultSet(com.mockrunner.mock.jdbc.MockResultSet) MockConnection(com.mockrunner.mock.jdbc.MockConnection) DataRow(org.apache.cayenne.DataRow) ExtendedTypeMap(org.apache.cayenne.access.types.ExtendedTypeMap) DefaultRowReaderFactory(org.apache.cayenne.access.jdbc.reader.DefaultRowReaderFactory) MockQueryMetadata(org.apache.cayenne.query.MockQueryMetadata) DbAdapter(org.apache.cayenne.dba.DbAdapter) MockStatement(com.mockrunner.mock.jdbc.MockStatement) Test(org.junit.Test)

Example 2 with MockStatement

use of com.mockrunner.mock.jdbc.MockStatement in project cayenne by apache.

the class JDBCResultIteratorTest method testClose.

@Test
public void testClose() throws Exception {
    Connection c = new MockConnection();
    MockStatement s = new MockStatement(c);
    MockResultSet rs = new MockResultSet("rs");
    rs.addColumn("a", new Object[] { "1", "2", "3" });
    RowReader<?> rowReader = mock(RowReader.class);
    try (JDBCResultIterator it = new JDBCResultIterator(s, rs, rowReader)) {
        assertFalse(rs.isClosed());
        assertFalse(s.isClosed());
        assertFalse(c.isClosed());
    }
    assertTrue(rs.isClosed());
    assertTrue(s.isClosed());
}
Also used : Connection(java.sql.Connection) MockConnection(com.mockrunner.mock.jdbc.MockConnection) MockStatement(com.mockrunner.mock.jdbc.MockStatement) MockResultSet(com.mockrunner.mock.jdbc.MockResultSet) MockConnection(com.mockrunner.mock.jdbc.MockConnection) Test(org.junit.Test)

Aggregations

MockConnection (com.mockrunner.mock.jdbc.MockConnection)2 MockResultSet (com.mockrunner.mock.jdbc.MockResultSet)2 MockStatement (com.mockrunner.mock.jdbc.MockStatement)2 Connection (java.sql.Connection)2 Test (org.junit.Test)2 Statement (java.sql.Statement)1 DataRow (org.apache.cayenne.DataRow)1 DefaultRowReaderFactory (org.apache.cayenne.access.jdbc.reader.DefaultRowReaderFactory)1 ExtendedTypeMap (org.apache.cayenne.access.types.ExtendedTypeMap)1 DbAdapter (org.apache.cayenne.dba.DbAdapter)1 MockQueryMetadata (org.apache.cayenne.query.MockQueryMetadata)1