Search in sources :

Example 1 with TranslationMapper

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

the class DynamicSqlTest method testTranslationTable.

@Test
public void testTranslationTable() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        TranslationMapper mapper = sqlSession.getMapper(TranslationMapper.class);
        Translation t = new Translation();
        t.setId(1);
        t.setTranslation("Spanish");
        mapper.insert(t);
        Translation t1 = new Translation();
        t1.setId(2);
        t1.setTranslation("French");
        mapper.insert(t1);
        Optional<Translation> returnedRecord = mapper.selectByPrimaryKey(2);
        assertThat(returnedRecord).hasValueSatisfying(rr -> {
            assertEquals(t1.getId(), rr.getId());
            assertEquals(t1.getTranslation(), rr.getTranslation());
        });
        t1.setTranslation("Italian");
        mapper.updateByPrimaryKey(t1);
        returnedRecord = mapper.selectByPrimaryKey(2);
        assertThat(returnedRecord).hasValueSatisfying(rr -> {
            assertEquals(t1.getId(), rr.getId());
            assertEquals(t1.getTranslation(), rr.getTranslation());
        });
    }
}
Also used : TranslationMapper(mbg.test.mb3.generated.dsql.mapper.mbgtest.sub.TranslationMapper) Translation(mbg.test.mb3.generated.dsql.model.mbgtest.sub.Translation) SqlSession(org.apache.ibatis.session.SqlSession) Test(org.junit.jupiter.api.Test)

Aggregations

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