コード例 #1
0
ファイル: SqlSessionTest.java プロジェクト: cuiiug/mybatis-3
 @Test
 public void shouldExecuteSelectAllAuthorsUsingMapperClassThatReturnsAnArray() {
   SqlSession session = sqlMapper.openSession();
   try {
     AuthorMapper mapper = session.getMapper(AuthorMapper.class);
     Author[] authors = mapper.selectAllAuthorsArray();
     assertEquals(2, authors.length);
   } finally {
     session.close();
   }
 }
コード例 #2
0
ファイル: SqlSessionTest.java プロジェクト: cuiiug/mybatis-3
 @Test
 public void shouldExecuteSelectAllAuthorsUsingMapperClassThatReturnsLinkedList() {
   SqlSession session = sqlMapper.openSession();
   try {
     AuthorMapper mapper = session.getMapper(AuthorMapper.class);
     Collection<Author> authors = mapper.selectAllAuthorsLinkedList();
     assertEquals(2, authors.size());
   } finally {
     session.close();
   }
 }
コード例 #3
0
ファイル: SqlSessionTest.java プロジェクト: cuiiug/mybatis-3
 @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();
   }
 }
コード例 #4
0
ファイル: SqlSessionTest.java プロジェクト: cuiiug/mybatis-3
 @Test
 public void shouldExecuteSelectOneAuthorUsingMapperClass() {
   SqlSession session = sqlMapper.openSession();
   try {
     AuthorMapper mapper = session.getMapper(AuthorMapper.class);
     Author author = mapper.selectAuthor(101);
     assertEquals(101, author.getId());
   } finally {
     session.close();
   }
 }
コード例 #5
0
ファイル: SqlSessionTest.java プロジェクト: cuiiug/mybatis-3
 @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();
   }
 }
コード例 #6
0
ファイル: SqlSessionTest.java プロジェクト: cuiiug/mybatis-3
 @Test
 public void shouldDeleteAuthorUsingMapperClass() throws Exception {
   SqlSession session = sqlMapper.openSession();
   try {
     AuthorMapper mapper = session.getMapper(AuthorMapper.class);
     int count = mapper.deleteAuthor(101);
     assertEquals(1, count);
     assertNull(mapper.selectAuthor(101));
   } finally {
     session.close();
   }
 }
コード例 #7
0
ファイル: SqlSessionTest.java プロジェクト: cuiiug/mybatis-3
 @Test
 public void shouldSelectAuthorsUsingMapperClassWithResultHandler() {
   SqlSession session = sqlMapper.openSession();
   try {
     DefaultResultHandler handler = new DefaultResultHandler();
     AuthorMapper mapper = session.getMapper(AuthorMapper.class);
     mapper.selectAllAuthors(handler);
     assertEquals(2, handler.getResultList().size());
   } finally {
     session.close();
   }
 }
コード例 #8
0
ファイル: SqlSessionTest.java プロジェクト: cuiiug/mybatis-3
 @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();
   }
 }
コード例 #9
0
ファイル: SqlSessionTest.java プロジェクト: cuiiug/mybatis-3
 @Test
 public void shouldExecuteSelectOneAuthorUsingMapperClassWithResultHandler() {
   SqlSession session = sqlMapper.openSession();
   try {
     DefaultResultHandler handler = new DefaultResultHandler();
     AuthorMapper mapper = session.getMapper(AuthorMapper.class);
     mapper.selectAuthor(101, handler);
     Author author = (Author) handler.getResultList().get(0);
     assertEquals(101, author.getId());
   } finally {
     session.close();
   }
 }
コード例 #10
0
ファイル: SqlSessionTest.java プロジェクト: cuiiug/mybatis-3
 @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();
   }
 }
コード例 #11
0
ファイル: SqlSessionTest.java プロジェクト: cuiiug/mybatis-3
 @Test
 public void shouldInsertAuthorUsingMapperClass() throws Exception {
   SqlSession session = sqlMapper.openSession();
   try {
     AuthorMapper mapper = session.getMapper(AuthorMapper.class);
     Author expected =
         new Author(500, "cbegin", "******", "*****@*****.**", "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();
   }
 }