Search in sources :

Example 1 with ClientTestModel

use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.

the class DalQueryDaoTestStub method testQueryFirstSuccess.

/**
 * Test query for first success
 * @throws SQLException
 */
@Test
public void testQueryFirstSuccess() throws SQLException {
    String sql = "SELECT * FROM " + TABLE_NAME + " WHERE id = 1";
    StatementParameters param = new StatementParameters();
    DalHints hints = new DalHints();
    ClientTestModel model = client.queryFirst(sql, param, hints, mapper);
    Assert.assertEquals(1, model.getId().intValue());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Example 2 with ClientTestModel

use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.

the class DalQueryDaoTestStub method testQueryWithMapper.

/**
 * Test the basic query function with mapper
 * @throws SQLException
 */
@Test
public void testQueryWithMapper() throws SQLException {
    String sql = "SELECT * FROM " + TABLE_NAME;
    StatementParameters param = new StatementParameters();
    DalHints hints = new DalHints();
    List<ClientTestModel> models = client.query(sql, param, hints, mapper);
    Assert.assertEquals(ROW_COUNT, models.size());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Example 3 with ClientTestModel

use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.

the class DalQueryDaoTestStub method testQueryTopSuccess.

/**
 * Test query for Top success
 * @throws SQLException
 */
@Test
public void testQueryTopSuccess() throws SQLException {
    String sql = "SELECT * FROM " + TABLE_NAME + " WHERE quantity = 10";
    StatementParameters param = new StatementParameters();
    DalHints hints = new DalHints();
    List<ClientTestModel> models = client.queryTop(sql, param, hints, mapper, 10);
    Assert.assertEquals(10, models.size());
    Assert.assertEquals(10, models.get(0).getQuantity().intValue());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Example 4 with ClientTestModel

use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.

the class DalQueryDaoTestStub method testQueryFromFailed.

/**
 * Test query for From Failed
 * @throws SQLException
 */
@Test
public void testQueryFromFailed() throws SQLException {
    String sql = "SELECT * FROM " + TABLE_NAME + " LIMIT x 5";
    StatementParameters param = new StatementParameters();
    DalHints hints = new DalHints();
    List<ClientTestModel> models;
    try {
        models = client.queryFrom(sql, param, hints, mapper, 0, 10);
        Assert.fail();
    } catch (Exception e) {
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 5 with ClientTestModel

use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.

the class DalTableDaoTestStub method testInsertMultipleAsList.

/**
 * Test Insert multiple entities one by one
 * @throws SQLException
 */
@Test
public void testInsertMultipleAsList() throws SQLException {
    List<ClientTestModel> entities = new ArrayList<ClientTestModel>();
    for (int i = 0; i < 3; i++) {
        ClientTestModel model = new ClientTestModel();
        model.setQuantity(10 + 1 % 3);
        model.setType(((Number) (1 % 3)).shortValue());
        model.setAddress("CTRIP");
        entities.add(model);
    }
    int[] res = dao.insert(new DalHints(), entities);
    assertEquals(new int[] { 1, 1, 1 }, res, 3, "address='CTRIP'");
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

DalHints (com.ctrip.platform.dal.dao.DalHints)61 ClientTestModel (test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel)61 Test (org.junit.Test)59 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)40 ArrayList (java.util.ArrayList)13 SQLException (java.sql.SQLException)9 DalClient (com.ctrip.platform.dal.dao.DalClient)3 DalCommand (com.ctrip.platform.dal.dao.DalCommand)3 SelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder)3 ClientTestDalRowMapper (test.com.ctrip.platform.dal.dao.unitbase.ClientTestDalRowMapper)3 KeyHolder (com.ctrip.platform.dal.dao.KeyHolder)2 DalRowMapperExtractor (com.ctrip.platform.dal.dao.helper.DalRowMapperExtractor)2 DalRowCallback (com.ctrip.platform.dal.dao.DalRowCallback)1 DalCustomRowMapper (com.ctrip.platform.dal.dao.helper.DalCustomRowMapper)1 FreeSelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder)1 ResultSet (java.sql.ResultSet)1 Timestamp (java.sql.Timestamp)1 List (java.util.List)1 Map (java.util.Map)1