Search in sources :

Example 1 with IdMapper

use of mbg.test.mb3.generated.dsql.mapper.mbgtest.IdMapper in project generator by mybatis.

the class DynamicSqlTest method testIdTable.

@Test
public void testIdTable() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        IdMapper mapper = sqlSession.getMapper(IdMapper.class);
        Id id = new Id();
        id.setId(1);
        id.setDescription("Spanish");
        mapper.insert(id);
        Id id1 = new Id();
        id1.setId(2);
        id1.setDescription("French");
        mapper.insert(id1);
        Optional<Id> returnedRecord = mapper.selectByPrimaryKey(2);
        assertThat(returnedRecord).hasValueSatisfying(rr -> {
            assertEquals(id1.getId(), rr.getId());
            assertEquals(id1.getDescription(), rr.getDescription());
        });
        id1.setDescription("Italian");
        mapper.updateByPrimaryKey(id1);
        returnedRecord = mapper.selectByPrimaryKey(2);
        assertThat(returnedRecord).hasValueSatisfying(rr -> {
            assertEquals(id1.getId(), rr.getId());
            assertEquals(id1.getDescription(), rr.getDescription());
        });
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) IdMapper(mbg.test.mb3.generated.dsql.mapper.mbgtest.IdMapper) Id(mbg.test.mb3.generated.dsql.model.mbgtest.Id) Test(org.junit.jupiter.api.Test)

Aggregations

IdMapper (mbg.test.mb3.generated.dsql.mapper.mbgtest.IdMapper)1 Id (mbg.test.mb3.generated.dsql.model.mbgtest.Id)1 SqlSession (org.apache.ibatis.session.SqlSession)1 Test (org.junit.jupiter.api.Test)1