Search in sources :

Example 1 with SingleInsertTask

use of com.ctrip.platform.dal.dao.task.SingleInsertTask in project dal by ctripcorp.

the class SingleInsertTaskTestStub method testExecute.

@Test
public void testExecute() {
    SingleInsertTask<ClientTestModel> test = new SingleInsertTask<>();
    test.initialize(getParser());
    DalHints hints = new DalHints();
    try {
        int result = test.execute(hints, getAllMap().get(0), null);
        //			assertEquals(1, result);
        assertEquals(3 + 1, getCount());
    } catch (SQLException e) {
        e.printStackTrace();
        fail();
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) SingleInsertTask(com.ctrip.platform.dal.dao.task.SingleInsertTask) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 2 with SingleInsertTask

use of com.ctrip.platform.dal.dao.task.SingleInsertTask in project dal by ctripcorp.

the class SingleInsertTaskTestStub method testExecuteWithUpdatableEntity.

@Test
public void testExecuteWithUpdatableEntity() throws SQLException {
    SingleInsertTask<UpdatableClientTestModel> test = new SingleInsertTask<>();
    test.initialize(getParser(UpdatableClientTestModel.class));
    DalHints hints = new DalHints();
    try {
        UpdatableClientTestModel model = getAll(UpdatableClientTestModel.class).get(0);
        model.setAddress("abc");
        int result = test.execute(hints, getFields(model), model);
        //			assertEquals(0, result);
        assertEquals(4, getCount());
        UpdatableClientTestModel model2 = getAll(UpdatableClientTestModel.class).get(3);
        assertEquals("abc", model2.getAddress());
        assertEquals(model.getTableIndex(), model2.getTableIndex());
        assertEquals(model.getDbIndex(), model2.getDbIndex());
        assertEquals(model.getQuantity(), model2.getQuantity());
        assertEquals(model.getType(), model2.getType());
    } catch (SQLException e) {
        e.printStackTrace();
        fail();
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) SingleInsertTask(com.ctrip.platform.dal.dao.task.SingleInsertTask) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 3 with SingleInsertTask

use of com.ctrip.platform.dal.dao.task.SingleInsertTask in project dal by ctripcorp.

the class SingleInsertTaskTestStub method testExecuteWithNonInsertable.

@Test
public void testExecuteWithNonInsertable() throws SQLException {
    SingleInsertTask<NonInsertableVersionModel> test = new SingleInsertTask<>();
    DalParser<NonInsertableVersionModel> parser = new DalDefaultJpaParser<>(NonInsertableVersionModel.class, getDbName());
    test.initialize(parser);
    DalHints hints = new DalHints();
    int result = test.execute(hints, getAllMap().get(0), null);
    assertEquals(3 + 1, getCount());
    Map<Integer, Map<String, ?>> pojos = getAllMap();
    for (Map<String, ?> pojo : pojos.values()) {
        assertNotNull(pojo.get("last_changed"));
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) SingleInsertTask(com.ctrip.platform.dal.dao.task.SingleInsertTask) DalDefaultJpaParser(com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser) Map(java.util.Map) Test(org.junit.Test)

Example 4 with SingleInsertTask

use of com.ctrip.platform.dal.dao.task.SingleInsertTask in project dal by ctripcorp.

the class SingleInsertTaskTestStub method testExecuteWithId.

@Test
public void testExecuteWithId() {
    SingleInsertTask<ClientTestModel> test = new SingleInsertTask<>();
    test.initialize(getParser());
    DalHints hints = new DalHints().enableIdentityInsert();
    try {
        if (this instanceof SingleInsertTaskSqlSvrTest)
            SqlServerTestInitializer.turnOnIdentityInsert();
        Map<String, ?> pojo = getAllMap().get(0);
        ((Map) pojo).put("id", new Integer(210));
        int result = test.execute(hints, pojo, null);
        assertEquals(3 + 1, getCount());
        Map<Integer, Map<String, ?>> pojos = getAllMap();
        Set<Integer> ids = new HashSet<>();
        for (Map<String, ?> pojoi : pojos.values()) {
            ids.add((Integer) pojoi.get("id"));
        }
        assertTrue(ids.contains(210));
        if (this instanceof SingleInsertTaskSqlSvrTest)
            SqlServerTestInitializer.turnOffIdentityInsert();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) SingleInsertTask(com.ctrip.platform.dal.dao.task.SingleInsertTask) SQLException(java.sql.SQLException) Map(java.util.Map) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

DalHints (com.ctrip.platform.dal.dao.DalHints)4 SingleInsertTask (com.ctrip.platform.dal.dao.task.SingleInsertTask)4 Test (org.junit.Test)4 SQLException (java.sql.SQLException)3 Map (java.util.Map)2 DalDefaultJpaParser (com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser)1 HashSet (java.util.HashSet)1