Search in sources :

Example 1 with AuthorMapper

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

the class SqlSessionManagerTest method shouldCommitInsertedAuthor.

@Test
public void shouldCommitInsertedAuthor() throws Exception {
    try {
        manager.startManagedSession();
        AuthorMapper mapper = manager.getMapper(AuthorMapper.class);
        Author expected = new Author(500, "cbegin", "******", "cbegin@somewhere.com", "Something...", null);
        mapper.insertAuthor(expected);
        manager.commit();
        Author actual = mapper.selectAuthor(500);
        assertNotNull(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 2 with AuthorMapper

use of org.apache.ibatis.domain.blog.mappers.AuthorMapper 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);
}
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 3 with AuthorMapper

use of org.apache.ibatis.domain.blog.mappers.AuthorMapper 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();
    }
}
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 4 with AuthorMapper

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

the class SqlSessionTest method shouldInsertAuthorUsingMapperClass.

@Test
public void shouldInsertAuthorUsingMapperClass() throws Exception {
    SqlSession session = sqlMapper.openSession();
    try {
        AuthorMapper mapper = session.getMapper(AuthorMapper.class);
        Author expected = new Author(500, "cbegin", "******", "cbegin@somewhere.com", "Something...", null);
        mapper.insertAuthor(expected);
        Author actual = mapper.selectAuthor(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();
    }
}
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 5 with AuthorMapper

use of org.apache.ibatis.domain.blog.mappers.AuthorMapper 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();
    }
}
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)

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