SHARE
TWEET

Untitled

a guest Mar 17th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import groovy.grape.Grape
  2. import groovy.sql.Sql
  3. import groovy.xml.StreamingMarkupBuilder
  4. import org.dbunit.*
  5. import org.dbunit.dataset.xml.*
  6. import org.dbunit.database.*
  7.  
  8. @Grab('org.dbunit:dbunit:2.4.7')
  9. @Grab('org.slf4j:slf4j-nop:1.5.10')
  10. class DbUnitSampleTest extends GroovyTestCase {
  11.  
  12.     static {
  13.         Grape.grab(group:'org.hsqldb', module:'hsqldb', version:'1.8.0.10', classLoader:DbUnitSampleTest.classLoader.rootLoader)
  14.         Sql.newInstance('jdbc:hsqldb:db/sample', 'sa', '', 'org.hsqldb.jdbcDriver').execute """
  15.             CREATE TABLE emp (
  16.                 empno INTEGER PRIMARY KEY,
  17.                 ename VARCHAR(10),
  18.                 job VARCHAR(9)
  19.             );"""
  20.     }
  21.  
  22.     def tester
  23.  
  24.     void setUp() {
  25.         tester = new JdbcDatabaseTester('org.hsqldb.jdbcDriver', 'jdbc:hsqldb:db/sample', 'sa', '')
  26.     }
  27.  
  28.     void testDelete() {
  29.         tester.dataSet = dataSet {
  30.             emp empno:7369, ename:'SMITH', job:'CLERK'
  31.             emp empno:7499, ename:'ALLEN', job:'SALESMAN'
  32.             emp empno:7521, ename:'WARD', job:'SALESMAN'
  33.         }
  34.         tester.onSetup()
  35.  
  36.         assert 1 == Sql.newInstance('jdbc:hsqldb:db/sample', 'sa', '', 'org.hsqldb.jdbcDriver')
  37.             .executeUpdate('delete from emp where empno = 7499')
  38.  
  39.         Assertion.assertEquals dataSet {
  40.             emp empno:7369, ename:'SMITH', job:'CLERK'
  41.             emp empno:7521, ename:'WARD', job:'SALESMAN'
  42.         }, tester.connection.createDataSet()
  43.     }
  44.  
  45.     def dataSet(c) {
  46.         new FlatXmlDataSet(new StringReader(new StreamingMarkupBuilder().bind{dataset c}.toString()))
  47.     }
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top