Changeset 3145


Ignore:
Timestamp:
07/17/13 09:26:37 (11 years ago)
Author:
olhsha
Message:

refactored Dao-tests for notebooks and annotations. The common part (connection to the test DB) is moved in a separate class.

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java

    r3144 r3145  
    4848@ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-config/annotationDao.xml"})
    4949
    50 public class JdbcAnnotationDaoTest {
    51    
    52     @Autowired
    53     private JdbcTemplate jdbcTemplate;
     50public class JdbcAnnotationDaoTest extends JdbcResourceDaoTestBasic{
    5451   
    5552    @Autowired
    5653    JdbcAnnotationDao jdbcAnnotationDao;   
    5754   
    58    
    59     private String getNormalisedSql() throws FileNotFoundException, URISyntaxException {
    60         // remove the unsupported sql for the test
    61         final URL sqlUrl = JdbcAnnotationDaoTest.class.getResource("/sql/DashishAnnotatorCreate.sql");
    62         String sqlString = new Scanner(new File(sqlUrl.toURI()), "UTF8").useDelimiter("\\Z").next();
    63         for (String unknownToken : new String[]{
    64             "SET client_encoding",
    65             "CREATE DATABASE",
    66             "\\\\connect",
    67             "SET default_with_oids",
    68             "ALTER SEQUENCE",
    69             "ALTER TABLE ONLY",
    70             "ADD CONSTRAINT",
    71             "CREATE INDEX", // "ALTER TABLE ONLY [a-z]* ALTER COLUMN",
    72         // "ALTER TABLE ONLY [^A]* ADD CONSTRAINT"
    73         }) {
    74             sqlString = sqlString.replaceAll(unknownToken, "-- " + unknownToken);
    75         }
    76         sqlString = sqlString.replaceAll("body_xml xml", "body_xml text");
    77         sqlString = sqlString.replaceAll("CACHE 1;", "; -- CACHE 1;");
    78         sqlString = sqlString.replaceAll("UUID", "text");
    79         sqlString = sqlString.replaceAll("SERIAL NOT NULL", "INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY");
    80         return sqlString;
    81     }
    82 
    83     private String getTestDataInsertSql() throws FileNotFoundException, URISyntaxException {
    84         final URL sqlUrl = JdbcAnnotationDaoTest.class.getResource("/test-data/InsertTestData.sql");
    85         String sqlString = new Scanner(new File(sqlUrl.toURI()), "UTF8").useDelimiter("\\Z").next();
    86         return sqlString;
    87     }
    88    
    89    
    90     @Before
    91     public void setUp() throws DataAccessException, FileNotFoundException, URISyntaxException{
    92         jdbcTemplate.execute("DROP SCHEMA PUBLIC CASCADE");
    93         // consume the DashishAnnotatorCreate sql script to create the database
    94         jdbcTemplate.execute(getNormalisedSql());
    95         jdbcTemplate.execute(getTestDataInsertSql());
    96    
    97     }
    98    
    99     @After
    100     public void tearDown() {
    101     }
    10255   
    10356   
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDaoTest.java

    r3137 r3145  
    2525import eu.dasish.annotation.schema.Notebook;
    2626import eu.dasish.annotation.schema.NotebookInfo;
    27 import java.io.File;
    28 import java.io.FileNotFoundException;
    2927import java.net.URISyntaxException;
    30 import java.net.URL;
    3128import java.util.Calendar;
    3229import java.util.List;
    33 import java.util.Scanner;
    3430import java.util.UUID;
    3531import org.jmock.Expectations;
    3632import static org.jmock.Expectations.returnValue;
    3733import org.jmock.Mockery;
    38 import org.junit.After;
    39 import org.junit.Before;
    4034import org.junit.Test;
    4135import org.junit.runner.RunWith;
    4236import org.springframework.beans.factory.annotation.Autowired;
    43 import org.springframework.dao.DataAccessException;
    44 import org.springframework.jdbc.core.JdbcTemplate;
    4537import org.springframework.test.context.ContextConfiguration;
    4638import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
     
    5446@RunWith(SpringJUnit4ClassRunner.class)
    5547@ContextConfiguration({"/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/dataSource.xml", "/spring-config/notebookDao.xml"})
    56 public class JdbcNotebookDaoTest {
     48public class JdbcNotebookDaoTest extends JdbcResourceDaoTestBasic{
    5749
    58     @Autowired
    59     private JdbcTemplate jdbcTemplate;
    6050    @Autowired
    6151    JdbcNotebookDao jdbcNotebookDao;
     
    6555    private Mockery mockery;
    6656
    67     private String getNormalisedSql() throws FileNotFoundException, URISyntaxException {
    68         // remove the unsupported sql for the test
    69         final URL sqlUrl = JdbcNotebookDaoTest.class.getResource("/sql/DashishAnnotatorCreate.sql");
    70         String sqlString = new Scanner(new File(sqlUrl.toURI()), "UTF8").useDelimiter("\\Z").next();
    71         for (String unknownToken : new String[]{
    72             "SET client_encoding",
    73             "CREATE DATABASE",
    74             "\\\\connect",
    75             "SET default_with_oids",
    76             "ALTER SEQUENCE",
    77             "ALTER TABLE ONLY",
    78             "ADD CONSTRAINT",
    79             "CREATE INDEX", // "ALTER TABLE ONLY [a-z]* ALTER COLUMN",
    80         // "ALTER TABLE ONLY [^A]* ADD CONSTRAINT"
    81         }) {
    82             sqlString = sqlString.replaceAll(unknownToken, "-- " + unknownToken);
    83         }
    84         sqlString = sqlString.replaceAll("body_xml xml", "body_xml text");
    85         sqlString = sqlString.replaceAll("CACHE 1;", "; -- CACHE 1;");
    86         sqlString = sqlString.replaceAll("UUID", "text");
    87         sqlString = sqlString.replaceAll("SERIAL NOT NULL", "INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY");
    88         return sqlString;
    89     }
    90 
    91     private String getTestDataInsertSql() throws FileNotFoundException, URISyntaxException {
    92         final URL sqlUrl = JdbcNotebookDaoTest.class.getResource("/test-data/InsertTestData.sql");
    93         String sqlString = new Scanner(new File(sqlUrl.toURI()), "UTF8").useDelimiter("\\Z").next();
    94         return sqlString;
    95     }
    96 
    97     @Before
    98     public void setUp() throws DataAccessException, FileNotFoundException, URISyntaxException {
    99         jdbcTemplate.execute("DROP SCHEMA PUBLIC CASCADE");
    100         // consume the DashishAnnotatorCreate sql script to create the database
    101         jdbcTemplate.execute(getNormalisedSql());
    102         jdbcTemplate.execute(getTestDataInsertSql());
    103     }
    104 
    105     @After
    106     public void tearDown() {
    107     }
    108 
     57   
    10958    /**
    11059     * Test of getNotebookInfos method, of class JdbcNotebookDao.
Note: See TracChangeset for help on using the changeset viewer.