Java Reference
In-Depth Information
Another simplification, which lessens the need for the automated tests to verify
the SQL statements, is to visually inspect the mapping document and to execute
each SQL statement by copying and pasting the SQL statement into a command-
line tool such as Oracle SQL *Plus. The trouble with this manual approach is that
it will not catch errors caused by changes to the Java code or the database schema.
It also relies on the developer to manually retest the mapping documents after
making changes. One way to make this testing approach more robust is to use the
Gold Master approach described in JUnit Recipes . After manually testing the SQL
statements, you write tests that fail whenever the SQL statement is changed, which
will remind you to recheck the statement. You must still write tests that execute
the statements, but they do not need to test the SQL statements as thoroughly.
Tests such as the one for the findOrder mapped statement must verify that the
result map constructs the objects correctly. The most direct approach is to populate
the database with test data, execute the query, and verify that i BATIS returns the cor-
rect object. The trouble with this approach is that the tests can be difficult to write
and slow to execute. An alternative approach is to write tests that use the i BATIS
mapping metadata in a similar way to the tests that we wrote to verify the Hibernate
and JDO O/R mapping. As with the JDO and Hibernate tests, the i BATIS tests must
use internal API s. For example, let's look at an example of a test for the findOrder
mapped statement and its result map. The test gets the metadata describing the
mapped statement from the SqlMapClient and makes assertions about it:
public class IBatisMappingTests extends TestCase {
private SqlMapClient sqlMapClient;
public void setUp() throws Exception { … };
public void test () throws Exception {
mappedStatement = ((ExtendedSqlMapClient)sqlMapClient)
.getMappedStatement("findPendingOrder");
assertEquals(String.class,
mappedStatement
.getParameterClass());
Verifies
parameter type
ResultMap resultMap = mappedStatement
.getResultMap();
assertEquals(PendingOrderDTO.class,
resultMap
.getResultClass());
Verifies
result type
resultMappings = resultMap.getResultMappings();
 
Search WWH ::




Custom Search