use of org.apache.ibatis.domain.blog.Author in project mybatis-3 by mybatis.
the class SqlSessionTest method shouldSelectOneAuthor.
@Test
public void shouldSelectOneAuthor() throws Exception {
SqlSession session = sqlMapper.openSession();
try {
Author author = session.selectOne("org.apache.ibatis.domain.blog.mappers.AuthorMapper.selectAuthor", new Author(101));
assertEquals(101, author.getId());
assertEquals(Section.NEWS, author.getFavouriteSection());
} finally {
session.close();
}
}
use of org.apache.ibatis.domain.blog.Author in project mybatis-3 by mybatis.
the class SqlSessionTest method shouldExecuteSelectAllAuthorsUsingMapperClassThatReturnsVector.
@Test
public void shouldExecuteSelectAllAuthorsUsingMapperClassThatReturnsVector() {
SqlSession session = sqlMapper.openSession();
try {
AuthorMapper mapper = session.getMapper(AuthorMapper.class);
Collection<Author> authors = mapper.selectAllAuthorsVector();
assertEquals(2, authors.size());
} finally {
session.close();
}
}
use of org.apache.ibatis.domain.blog.Author in project mybatis-3 by mybatis.
the class SqlSessionTest method shouldSelectOneAuthorWithInlineParams.
@Test
public void shouldSelectOneAuthorWithInlineParams() throws Exception {
SqlSession session = sqlMapper.openSession();
try {
Author author = session.selectOne("org.apache.ibatis.domain.blog.mappers.AuthorMapper.selectAuthorWithInlineParams", new Author(101));
assertEquals(101, author.getId());
} finally {
session.close();
}
}
use of org.apache.ibatis.domain.blog.Author in project mybatis-3 by mybatis.
the class SqlSessionTest method shouldSelectBlogWithPostsAndAuthorUsingJoin.
@Test
public void shouldSelectBlogWithPostsAndAuthorUsingJoin() throws Exception {
SqlSession session = sqlMapper.openSession();
try {
Blog blog = session.selectOne("org.apache.ibatis.domain.blog.mappers.BlogMapper.selectBlogJoinedWithPostsAndAuthor", 1);
assertEquals("Jim Business", blog.getTitle());
final Author author = blog.getAuthor();
assertEquals(101, author.getId());
assertEquals("jim", author.getUsername());
final List<Post> posts = blog.getPosts();
assertEquals(2, posts.size());
final Post post = blog.getPosts().get(0);
assertEquals(1, post.getId());
assertEquals("Corn nuts", post.getSubject());
final List<Comment> comments = post.getComments();
assertEquals(2, comments.size());
final List<Tag> tags = post.getTags();
assertEquals(3, tags.size());
final Comment comment = comments.get(0);
assertEquals(1, comment.getId());
assertEquals(DraftPost.class, blog.getPosts().get(0).getClass());
assertEquals(Post.class, blog.getPosts().get(1).getClass());
} finally {
session.close();
}
}
use of org.apache.ibatis.domain.blog.Author in project mybatis-3 by mybatis.
the class SqlSessionTest method shouldUpdateAuthorCommit.
@Test
public void shouldUpdateAuthorCommit() throws Exception {
SqlSession session = sqlMapper.openSession();
Author original;
Author updated;
try {
original = session.selectOne("org.apache.ibatis.domain.blog.mappers.AuthorMapper.selectAuthor", 101);
original.setEmail("new@email.com");
int updates = session.update("org.apache.ibatis.domain.blog.mappers.AuthorMapper.updateAuthor", original);
assertEquals(1, updates);
updated = session.selectOne("org.apache.ibatis.domain.blog.mappers.AuthorMapper.selectAuthor", 101);
assertEquals(original.getEmail(), updated.getEmail());
session.commit();
} finally {
session.close();
}
try {
session = sqlMapper.openSession();
updated = session.selectOne("org.apache.ibatis.domain.blog.mappers.AuthorMapper.selectAuthor", 101);
assertEquals(original.getEmail(), updated.getEmail());
} finally {
session.close();
}
}
Aggregations