Skip to content

Commit b295bac

Browse files
committed
Added managed session tests commit/rollback/implicit etc.
1 parent fdab870 commit b295bac

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/test/java/org/apache/ibatis/session/SqlSessionManagerTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,47 @@ public void shouldInsertAuthorUsingMapperClass() throws Exception {
317317
assertEquals(expected.getBio(), actual.getBio());
318318
}
319319

320+
@Test
321+
public void shouldCommitInsertedAuthor() throws Exception {
322+
try {
323+
manager.startManagedSession();
324+
AuthorMapper mapper = manager.getMapper(AuthorMapper.class);
325+
Author expected = new Author(500, "cbegin", "******", "[email protected]", "Something...", null);
326+
mapper.insertAuthor(expected);
327+
manager.commit();
328+
Author actual = mapper.selectAuthor(500);
329+
assertNotNull(actual);
330+
} finally {
331+
manager.close();
332+
}
333+
}
334+
335+
@Test
336+
public void shouldRollbackInsertedAuthor() throws Exception {
337+
try {
338+
manager.startManagedSession();
339+
AuthorMapper mapper = manager.getMapper(AuthorMapper.class);
340+
Author expected = new Author(500, "cbegin", "******", "[email protected]", "Something...", null);
341+
mapper.insertAuthor(expected);
342+
manager.rollback();
343+
Author actual = mapper.selectAuthor(500);
344+
assertNull(actual);
345+
} finally {
346+
manager.close();
347+
}
348+
}
349+
350+
@Test
351+
public void shouldImplicitlyRollbackInsertedAuthor() throws Exception {
352+
manager.startManagedSession();
353+
AuthorMapper mapper = manager.getMapper(AuthorMapper.class);
354+
Author expected = new Author(500, "cbegin", "******", "[email protected]", "Something...", null);
355+
mapper.insertAuthor(expected);
356+
manager.close();
357+
Author actual = mapper.selectAuthor(500);
358+
assertNull(actual);
359+
}
360+
320361
@Test
321362
public void shouldDeleteAuthorUsingMapperClass() throws Exception {
322363
AuthorMapper mapper = manager.getMapper(AuthorMapper.class);

0 commit comments

Comments
 (0)