use of org.apache.ibatis.domain.blog.Author in project mybatis-3 by mybatis.
the class SqlSessionManagerTest method shouldImplicitlyRollbackInsertedAuthor.
@Test
public void shouldImplicitlyRollbackInsertedAuthor() throws Exception {
manager.startManagedSession();
AuthorMapper mapper = manager.getMapper(AuthorMapper.class);
Author expected = new Author(502, "emacarron", "******", "emacarron@somewhere.com", "Something...", null);
mapper.insertAuthor(expected);
manager.close();
Author actual = mapper.selectAuthor(502);
assertNull(actual);
}
use of org.apache.ibatis.domain.blog.Author in project mybatis-3 by mybatis.
the class SqlSessionTest method shouldSelectNestedBlogWithPostsAndAuthorUsingJoin.
@Test
public void shouldSelectNestedBlogWithPostsAndAuthorUsingJoin() throws Exception {
SqlSession session = sqlMapper.openSession();
try {
Blog blog = session.selectOne("org.apache.ibatis.domain.blog.mappers.NestedBlogMapper.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 shouldSelectAuthorsUsingMapperClass.
@Test
public void shouldSelectAuthorsUsingMapperClass() {
SqlSession session = sqlMapper.openSession();
try {
AuthorMapper mapper = session.getMapper(AuthorMapper.class);
List<Author> authors = mapper.selectAllAuthors();
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 shouldUpdateAuthorIfNecessary.
@Test
public void shouldUpdateAuthorIfNecessary() 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");
original.setBio(null);
int updates = session.update("org.apache.ibatis.domain.blog.mappers.AuthorMapper.updateAuthorIfNecessary", 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();
}
}
use of org.apache.ibatis.domain.blog.Author in project mybatis-3 by mybatis.
the class SqlSessionTest method shouldInsertAuthor.
@Test
public void shouldInsertAuthor() throws Exception {
SqlSession session = sqlMapper.openSession();
try {
Author expected = new Author(500, "cbegin", "******", "cbegin@somewhere.com", "Something...", null);
int updates = session.insert("org.apache.ibatis.domain.blog.mappers.AuthorMapper.insertAuthor", expected);
assertEquals(1, updates);
Author actual = session.selectOne("org.apache.ibatis.domain.blog.mappers.AuthorMapper.selectAuthor", new Author(500));
assertNotNull(actual);
assertEquals(expected.getId(), actual.getId());
assertEquals(expected.getUsername(), actual.getUsername());
assertEquals(expected.getPassword(), actual.getPassword());
assertEquals(expected.getEmail(), actual.getEmail());
assertEquals(expected.getBio(), actual.getBio());
} finally {
session.close();
}
}
Aggregations