Search in sources :

Example 1 with MockPreparedStatement

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

the class LocalDateTypeTest method testSetJdbcObject.

public void testSetJdbcObject() throws Exception {
    PreparedStatement statement = new MockPreparedStatement(new MockConnection(), "update t set c = ?");
    LocalDate savedObject = new LocalDate(0);
    type.setJdbcObject(statement, savedObject, 1, Types.DATE, 0);
    Object object = ((MockPreparedStatement) statement).getParameter(1);
    assertEquals(Date.class, object.getClass());
    assertEquals(savedObject.toDate().getTime(), ((Date) object).getTime());
    type.setJdbcObject(statement, savedObject, 1, Types.TIMESTAMP, 0);
    object = ((MockPreparedStatement) statement).getParameter(1);
    assertEquals(Timestamp.class, object.getClass());
    assertEquals(savedObject.toDate().getTime(), ((Timestamp) object).getTime());
    type.setJdbcObject(statement, null, 1, Types.TIMESTAMP, 0);
    object = ((MockPreparedStatement) statement).getParameter(1);
    assertNull(object);
}
Also used : PreparedStatement(java.sql.PreparedStatement) MockPreparedStatement(com.mockrunner.mock.jdbc.MockPreparedStatement) MockPreparedStatement(com.mockrunner.mock.jdbc.MockPreparedStatement) MockConnection(com.mockrunner.mock.jdbc.MockConnection) LocalDate(org.joda.time.LocalDate)

Example 2 with MockPreparedStatement

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

the class LocalTimeTypeTest method testSetJdbcObject.

public void testSetJdbcObject() throws Exception {
    PreparedStatement statement = new MockPreparedStatement(new MockConnection(), "update t set c = ?");
    LocalTime date = new LocalTime(0);
    type.setJdbcObject(statement, date, 1, Types.TIME, 0);
    Object object = ((MockPreparedStatement) statement).getParameter(1);
    assertEquals(Time.class, object.getClass());
    assertEquals(new LocalDate(0, DateTimeZone.UTC).toDateTime(date).getMillis(), ((Time) object).getTime());
    type.setJdbcObject(statement, date, 1, Types.TIMESTAMP, 0);
    object = ((MockPreparedStatement) statement).getParameter(1);
    assertEquals(Timestamp.class, object.getClass());
    assertEquals(new LocalDate(0, DateTimeZone.UTC).toDateTime(date).getMillis(), ((Timestamp) object).getTime());
    type.setJdbcObject(statement, null, 1, Types.TIMESTAMP, 0);
    object = ((MockPreparedStatement) statement).getParameter(1);
    assertNull(object);
}
Also used : LocalTime(org.joda.time.LocalTime) PreparedStatement(java.sql.PreparedStatement) MockPreparedStatement(com.mockrunner.mock.jdbc.MockPreparedStatement) MockPreparedStatement(com.mockrunner.mock.jdbc.MockPreparedStatement) MockConnection(com.mockrunner.mock.jdbc.MockConnection) LocalDate(org.joda.time.LocalDate)

Example 3 with MockPreparedStatement

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

the class DateTimeTypeTest method testSetJdbcObject.

public void testSetJdbcObject() throws Exception {
    PreparedStatement statement = new MockPreparedStatement(new MockConnection(), "update t set c = ?");
    DateTime date = new DateTime(0);
    type.setJdbcObject(statement, date, 1, Types.TIMESTAMP, 0);
    Object object = ((MockPreparedStatement) statement).getParameter(1);
    assertEquals(Timestamp.class, object.getClass());
    assertEquals(date.getMillis(), ((Timestamp) object).getTime());
    type.setJdbcObject(statement, null, 1, Types.TIMESTAMP, 0);
    object = ((MockPreparedStatement) statement).getParameter(1);
    assertNull(object);
}
Also used : PreparedStatement(java.sql.PreparedStatement) MockPreparedStatement(com.mockrunner.mock.jdbc.MockPreparedStatement) MockPreparedStatement(com.mockrunner.mock.jdbc.MockPreparedStatement) MockConnection(com.mockrunner.mock.jdbc.MockConnection) DateTime(org.joda.time.DateTime)

Example 4 with MockPreparedStatement

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

the class LocalDateTimeTypeTest method testSetJdbcObject.

public void testSetJdbcObject() throws Exception {
    PreparedStatement statement = new MockPreparedStatement(new MockConnection(), "update t set c = ?");
    LocalDateTime date = new LocalDateTime(0);
    type.setJdbcObject(statement, date, 1, Types.TIMESTAMP, 0);
    Object object = ((MockPreparedStatement) statement).getParameter(1);
    assertEquals(Timestamp.class, object.getClass());
    assertEquals(date.toDate().getTime(), ((Timestamp) object).getTime());
    type.setJdbcObject(statement, null, 1, Types.TIMESTAMP, 0);
    object = ((MockPreparedStatement) statement).getParameter(1);
    assertNull(object);
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) PreparedStatement(java.sql.PreparedStatement) MockPreparedStatement(com.mockrunner.mock.jdbc.MockPreparedStatement) MockPreparedStatement(com.mockrunner.mock.jdbc.MockPreparedStatement) MockConnection(com.mockrunner.mock.jdbc.MockConnection)

Aggregations

MockConnection (com.mockrunner.mock.jdbc.MockConnection)4 MockPreparedStatement (com.mockrunner.mock.jdbc.MockPreparedStatement)4 PreparedStatement (java.sql.PreparedStatement)4 LocalDate (org.joda.time.LocalDate)2 DateTime (org.joda.time.DateTime)1 LocalDateTime (org.joda.time.LocalDateTime)1 LocalTime (org.joda.time.LocalTime)1