Search in sources :

Example 1 with MockResultSet

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

the class JodaTestCase method resultSet.

ResultSet resultSet(Object value) throws SQLException {
    MockResultSet rs = new MockResultSet("Test");
    rs.addColumn("Col");
    rs.addRow(new Object[] { value });
    rs.next();
    return rs;
}
Also used : MockResultSet(com.mockrunner.mock.jdbc.MockResultSet)

Example 2 with MockResultSet

use of com.mockrunner.mock.jdbc.MockResultSet 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 3 with MockResultSet

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

the class EnumTypeTest method testMaterializeStringObjectInnerEnum.

@Test
public void testMaterializeStringObjectInnerEnum() throws Exception {
    EnumType type = new EnumType(InnerEnumHolder.InnerEnum.class);
    MockResultSet rs = new MockResultSet("Test");
    rs.addColumn("Enum");
    rs.addRow(new Object[] { "b" });
    rs.next();
    Object o = type.materializeObject(rs, 1, Types.VARCHAR);
    assertSame(InnerEnumHolder.InnerEnum.b, o);
}
Also used : MockResultSet(com.mockrunner.mock.jdbc.MockResultSet) Test(org.junit.Test)

Example 4 with MockResultSet

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

the class BooleanTypeTest method testMaterializeObjectFromResultSet.

@Test
public void testMaterializeObjectFromResultSet() throws Exception {
    MockResultSet rs = new MockResultSet("") {

        @Override
        public boolean getBoolean(int i) throws SQLException {
            return (i + 2) % 2 == 0;
        }
    };
    BooleanType type = new BooleanType();
    // assert identity as well as equality (see CAY-320)
    assertSame(Boolean.FALSE, type.materializeObject(rs, 1, Types.BIT));
    assertSame(Boolean.TRUE, type.materializeObject(rs, 2, Types.BIT));
}
Also used : MockResultSet(com.mockrunner.mock.jdbc.MockResultSet) Test(org.junit.Test)

Example 5 with MockResultSet

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

the class EnumTypeTest method testMaterializeNumericObject.

@Test
public void testMaterializeNumericObject() throws Exception {
    EnumType type = new EnumType(MockEnum.class);
    MockResultSet rs = new MockResultSet("Test");
    rs.addColumn("Enum");
    rs.addRow(new Object[] { new Integer(2) });
    rs.next();
    Object o = type.materializeObject(rs, 1, Types.NUMERIC);
    assertSame(MockEnum.c, o);
}
Also used : MockResultSet(com.mockrunner.mock.jdbc.MockResultSet) Test(org.junit.Test)

Aggregations

MockResultSet (com.mockrunner.mock.jdbc.MockResultSet)8 Test (org.junit.Test)7 MockConnection (com.mockrunner.mock.jdbc.MockConnection)2 MockStatement (com.mockrunner.mock.jdbc.MockStatement)2 Connection (java.sql.Connection)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