Search in sources :

Example 11 with AuthorMapper

use of org.apache.ibatis.domain.blog.mappers.AuthorMapper in project mybatis-3 by mybatis.

the class SqlSessionTest method shouldExecuteSelectAllAuthorsUsingMapperClassThatReturnsSet.

@Test
public void shouldExecuteSelectAllAuthorsUsingMapperClassThatReturnsSet() {
    SqlSession session = sqlMapper.openSession();
    try {
        AuthorMapper mapper = session.getMapper(AuthorMapper.class);
        Collection<Author> authors = mapper.selectAllAuthorsSet();
        assertEquals(2, authors.size());
    } finally {
        session.close();
    }
}
Also used : AuthorMapper(org.apache.ibatis.domain.blog.mappers.AuthorMapper) ImmutableAuthor(org.apache.ibatis.domain.blog.ImmutableAuthor) Author(org.apache.ibatis.domain.blog.Author) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 12 with AuthorMapper

use of org.apache.ibatis.domain.blog.mappers.AuthorMapper in project mybatis-3 by mybatis.

the class SqlSessionTest method shouldFailExecutingAnAnnotatedMapperClassWithResultHandler.

@Test(expected = BindingException.class)
public void shouldFailExecutingAnAnnotatedMapperClassWithResultHandler() {
    SqlSession session = sqlMapper.openSession();
    try {
        DefaultResultHandler handler = new DefaultResultHandler();
        AuthorMapper mapper = session.getMapper(AuthorMapper.class);
        mapper.selectAuthor2(101, handler);
        Author author = (Author) handler.getResultList().get(0);
        assertEquals(101, author.getId());
    } finally {
        session.close();
    }
}
Also used : AuthorMapper(org.apache.ibatis.domain.blog.mappers.AuthorMapper) ImmutableAuthor(org.apache.ibatis.domain.blog.ImmutableAuthor) Author(org.apache.ibatis.domain.blog.Author) DefaultResultHandler(org.apache.ibatis.executor.result.DefaultResultHandler) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 13 with AuthorMapper

use of org.apache.ibatis.domain.blog.mappers.AuthorMapper in project mybatis-3 by mybatis.

the class SqlSessionManagerTest method shouldRollbackInsertedAuthor.

@Test
public void shouldRollbackInsertedAuthor() throws Exception {
    try {
        manager.startManagedSession();
        AuthorMapper mapper = manager.getMapper(AuthorMapper.class);
        Author expected = new Author(501, "lmeadors", "******", "lmeadors@somewhere.com", "Something...", null);
        mapper.insertAuthor(expected);
        manager.rollback();
        Author actual = mapper.selectAuthor(501);
        assertNull(actual);
    } finally {
        manager.close();
    }
}
Also used : AuthorMapper(org.apache.ibatis.domain.blog.mappers.AuthorMapper) Author(org.apache.ibatis.domain.blog.Author) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 14 with AuthorMapper

use of org.apache.ibatis.domain.blog.mappers.AuthorMapper in project mybatis-3 by mybatis.

the class SqlSessionTest method shouldUpdateAuthorUsingMapperClass.

@Test
public void shouldUpdateAuthorUsingMapperClass() throws Exception {
    SqlSession session = sqlMapper.openSession();
    try {
        AuthorMapper mapper = session.getMapper(AuthorMapper.class);
        Author expected = mapper.selectAuthor(101);
        expected.setUsername("NewUsername");
        int count = mapper.updateAuthor(expected);
        assertEquals(1, count);
        Author actual = mapper.selectAuthor(101);
        assertEquals(expected.getUsername(), actual.getUsername());
    } finally {
        session.close();
    }
}
Also used : AuthorMapper(org.apache.ibatis.domain.blog.mappers.AuthorMapper) ImmutableAuthor(org.apache.ibatis.domain.blog.ImmutableAuthor) Author(org.apache.ibatis.domain.blog.Author) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 15 with AuthorMapper

use of org.apache.ibatis.domain.blog.mappers.AuthorMapper in project mybatis-3 by mybatis.

the class SqlSessionTest method shouldExecuteSelectOneAuthorUsingMapperClassThatReturnsALinedHashMap.

@Test
public void shouldExecuteSelectOneAuthorUsingMapperClassThatReturnsALinedHashMap() {
    SqlSession session = sqlMapper.openSession();
    try {
        AuthorMapper mapper = session.getMapper(AuthorMapper.class);
        LinkedHashMap<String, Object> author = mapper.selectAuthorLinkedHashMap(101);
        assertEquals(101, author.get("ID"));
    } finally {
        session.close();
    }
}
Also used : AuthorMapper(org.apache.ibatis.domain.blog.mappers.AuthorMapper) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Aggregations

BaseDataTest (org.apache.ibatis.BaseDataTest)16 AuthorMapper (org.apache.ibatis.domain.blog.mappers.AuthorMapper)16 Test (org.junit.Test)16 Author (org.apache.ibatis.domain.blog.Author)13 ImmutableAuthor (org.apache.ibatis.domain.blog.ImmutableAuthor)10 DefaultResultHandler (org.apache.ibatis.executor.result.DefaultResultHandler)3