Search in sources :

Example 6 with Post

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

the class SqlSessionTest method shouldSelectNestedBlogWithPostsAndAuthorUsingJoin.

@Test
void shouldSelectNestedBlogWithPostsAndAuthorUsingJoin() {
    try (SqlSession session = sqlMapper.openSession()) {
        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());
    }
}
Also used : Comment(org.apache.ibatis.domain.blog.Comment) DraftPost(org.apache.ibatis.domain.blog.DraftPost) Post(org.apache.ibatis.domain.blog.Post) ImmutableAuthor(org.apache.ibatis.domain.blog.ImmutableAuthor) Author(org.apache.ibatis.domain.blog.Author) Tag(org.apache.ibatis.domain.blog.Tag) Blog(org.apache.ibatis.domain.blog.Blog) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.jupiter.api.Test)

Example 7 with Post

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

the class BindingTest method shouldFindPostsInArray.

@Test
void shouldFindPostsInArray() {
    try (SqlSession session = sqlSessionFactory.openSession()) {
        BoundAuthorMapper mapper = session.getMapper(BoundAuthorMapper.class);
        Integer[] params = new Integer[] { 1, 3, 5 };
        List<Post> posts = mapper.findPostsInArray(params);
        assertEquals(3, posts.size());
        session.rollback();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) DraftPost(org.apache.ibatis.domain.blog.DraftPost) Post(org.apache.ibatis.domain.blog.Post) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.jupiter.api.Test)

Example 8 with Post

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

the class BindingTest method shouldExecuteBoundSelectOneBlogStatementWithConstructor.

@Test
void shouldExecuteBoundSelectOneBlogStatementWithConstructor() {
    try (SqlSession session = sqlSessionFactory.openSession()) {
        BoundBlogMapper mapper = session.getMapper(BoundBlogMapper.class);
        Blog blog = mapper.selectBlogUsingConstructor(1);
        assertEquals(1, blog.getId());
        assertEquals("Jim Business", blog.getTitle());
        assertNotNull(blog.getAuthor(), "author should not be null");
        List<Post> posts = blog.getPosts();
        assertTrue(posts != null && !posts.isEmpty(), "posts should not be empty");
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) DraftPost(org.apache.ibatis.domain.blog.DraftPost) Post(org.apache.ibatis.domain.blog.Post) Blog(org.apache.ibatis.domain.blog.Blog) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.jupiter.api.Test)

Example 9 with Post

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

the class BindingTest method shouldExecuteBoundSelectBlogUsingConstructorWithResultMapCollection.

@Disabled
// issue #480 and #101
@Test
void shouldExecuteBoundSelectBlogUsingConstructorWithResultMapCollection() {
    try (SqlSession session = sqlSessionFactory.openSession()) {
        BoundBlogMapper mapper = session.getMapper(BoundBlogMapper.class);
        Blog blog = mapper.selectBlogUsingConstructorWithResultMapCollection(1);
        assertEquals(1, blog.getId());
        assertEquals("Jim Business", blog.getTitle());
        assertNotNull(blog.getAuthor(), "author should not be null");
        List<Post> posts = blog.getPosts();
        assertTrue(posts != null && !posts.isEmpty(), "posts should not be empty");
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) DraftPost(org.apache.ibatis.domain.blog.DraftPost) Post(org.apache.ibatis.domain.blog.Post) Blog(org.apache.ibatis.domain.blog.Blog) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 10 with Post

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

the class BindingTest method shouldFindThreeSpecificPosts.

@Test
void shouldFindThreeSpecificPosts() {
    try (SqlSession session = sqlSessionFactory.openSession()) {
        BoundAuthorMapper mapper = session.getMapper(BoundAuthorMapper.class);
        List<Post> posts = mapper.findThreeSpecificPosts(1, new RowBounds(1, 1), 3, 5);
        assertEquals(1, posts.size());
        assertEquals(3, posts.get(0).getId());
        session.rollback();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) DraftPost(org.apache.ibatis.domain.blog.DraftPost) Post(org.apache.ibatis.domain.blog.Post) RowBounds(org.apache.ibatis.session.RowBounds) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.jupiter.api.Test)

Aggregations

Post (org.apache.ibatis.domain.blog.Post)21 BaseDataTest (org.apache.ibatis.BaseDataTest)18 Test (org.junit.jupiter.api.Test)17 DraftPost (org.apache.ibatis.domain.blog.DraftPost)15 SqlSession (org.apache.ibatis.session.SqlSession)13 Blog (org.apache.ibatis.domain.blog.Blog)9 Author (org.apache.ibatis.domain.blog.Author)6 MappedStatement (org.apache.ibatis.mapping.MappedStatement)6 Comment (org.apache.ibatis.domain.blog.Comment)5 Tag (org.apache.ibatis.domain.blog.Tag)5 RowBounds (org.apache.ibatis.session.RowBounds)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 StaticSqlSource (org.apache.ibatis.builder.StaticSqlSource)3 Section (org.apache.ibatis.domain.blog.Section)3 ParameterMap (org.apache.ibatis.mapping.ParameterMap)3 ResultFlag (org.apache.ibatis.mapping.ResultFlag)3 ResultMap (org.apache.ibatis.mapping.ResultMap)3 ResultMapping (org.apache.ibatis.mapping.ResultMapping)3 SqlSource (org.apache.ibatis.mapping.SqlSource)3