Skip to content

Commit

Permalink
Polishing SqlxmlTypeHandlerTest
Browse files Browse the repository at this point in the history
See #1221
  • Loading branch information
kazuki43zoo committed May 3, 2018
1 parent 81aafdf commit a9325c9
Showing 1 changed file with 16 additions and 33 deletions.
49 changes: 16 additions & 33 deletions src/test/java/org/apache/ibatis/type/SqlxmlTypeHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public static void setUp() throws Exception {
Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource(
"org.postgresql.Driver", url, null));
configuration.setEnvironment(environment);
configuration.setUseGeneratedKeys(true);
configuration.addMapper(Mapper.class);
sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);

Expand Down Expand Up @@ -154,58 +153,42 @@ public void shouldGetResultNullFromCallableStatement() throws Exception {
}

@Test
public void shouldReturnXmlAsString() throws Exception {
SqlSession session = sqlSessionFactory.openSession();
try {
public void shouldReturnXmlAsString() {
try (SqlSession session = sqlSessionFactory.openSession()) {
Mapper mapper = session.getMapper(Mapper.class);
XmlBean bean = mapper.select(1);
assertEquals("<title>XML data</title>",
bean.getContent());
} finally {
session.close();
}
}

@Test
public void shouldReturnNull() throws Exception {
SqlSession session = sqlSessionFactory.openSession();
try {
public void shouldReturnNull() {
try (SqlSession session = sqlSessionFactory.openSession()) {
Mapper mapper = session.getMapper(Mapper.class);
XmlBean bean = mapper.select(2);
assertNull(bean.getContent());
} finally {
session.close();
}
}

@Test
public void shouldInsertXmlString() throws Exception {
public void shouldInsertXmlString() {
final Integer id = 100;
final String content = "<books><book><title>Save XML</title></book><book><title>Get XML</title></book></books>";
// Insert
{
SqlSession session = sqlSessionFactory.openSession();
try {
Mapper mapper = session.getMapper(Mapper.class);
XmlBean bean = new XmlBean();
bean.setId(id);
bean.setContent(content);
mapper.insert(bean);
session.commit();
} finally {
session.close();
}
try (SqlSession session = sqlSessionFactory.openSession()) {
Mapper mapper = session.getMapper(Mapper.class);
XmlBean bean = new XmlBean();
bean.setId(id);
bean.setContent(content);
mapper.insert(bean);
session.commit();
}
// Select to verify
{
SqlSession session = sqlSessionFactory.openSession();
try {
Mapper mapper = session.getMapper(Mapper.class);
XmlBean bean = mapper.select(id);
assertEquals(content, bean.getContent());
} finally {
session.close();
}
try (SqlSession session = sqlSessionFactory.openSession()) {
Mapper mapper = session.getMapper(Mapper.class);
XmlBean bean = mapper.select(id);
assertEquals(content, bean.getContent());
}
}

Expand Down

0 comments on commit a9325c9

Please sign in to comment.