Changeset 3598


Ignore:
Timestamp:
09/20/13 13:51:10 (11 years ago)
Author:
olhsha
Message:

Unreported in a ticket problem is fixed: there was no translation uri<--> externalID in in the DBIntegrityService, in adding methods for cachedRepresentationInfo, Version and Source, while their corresponding arguments where checked if they are already in the DB.

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/nb-configuration.xml

    r3452 r3598  
    2323            <config-file>src/main/resources/spring-config/cachedRepresentationDao.xml</config-file>
    2424            <config-file>src/test/resources/spring-test-config/mockVersionDao.xml</config-file>
    25             <config-file>src/test/resources/spring-test-config/mockDaoDispatcher.xml</config-file>
    26             <config-file>src/main/resources/spring-config/daoDispatcher.xml</config-file>
     25            <config-file>src/main/resources/spring-config/resourceDao.xml</config-file>
    2726        </config-files>
    2827        <config-file-groups/>
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/ResourceDao.java

    r3593 r3598  
    3636    public Number getInternalID(UUID externalId);
    3737   
     38   
     39     /**
     40     *
     41     * @param uri
     42     * @return internal identifier of the resource with uri, or null if there is no resource with this uri
     43     */
     44    public Number getInternalIDFromURI(String uri);
     45   
    3846    /**
    3947     *
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java

    r3596 r3598  
    133133    public Number[] addCachedForVersion(Number versionID, CachedRepresentationInfo cachedInfo, Blob cachedBlob) {
    134134        Number[] result = new Number[2];
    135         String cachedExternalIDstring = cachedInfo.getRef();
    136         UUID cachedUUID = (cachedExternalIDstring != null) ? UUID.fromString(cachedExternalIDstring) : null;
    137         result[1] = cachedRepresentationDao.getInternalID(cachedUUID);
     135        result[1] = cachedRepresentationDao.getInternalIDFromURI(cachedInfo.getRef());
    138136        if (result[1] == null) {
    139137            result[1] = cachedRepresentationDao.addCachedRepresentation(cachedInfo, cachedBlob);
     
    144142    }
    145143
     144   
    146145    @Override
    147146    public Number[] addSiblingVersionForSource(Number sourceID, Version version) throws SQLException {
    148147        Number[] result = new Number[2];
    149         String versionURI = version.getURI();
    150         UUID versionUUID = (versionURI != null) ? UUID.fromString(versionDao.stringURItoExternalID(versionURI)) : null;
    151         result[1] = versionDao.getInternalID(versionUUID);
     148        result[1] = versionDao.getInternalIDFromURI(version.getURI());
    152149        if (result[1] == null) {
    153150            result[1] = versionDao.addVersion(version);
     
    157154    }
    158155
     156    // TODo: mapping uri to external ID
    159157    @Override
    160158    public Map<String, String> addSourcesForAnnotation(Number annotationID, List<SourceInfo> sources) throws SQLException {
    161159        Map<String, String> result = new HashMap<String, String>();
    162         for (SourceInfo sourceInfo : sources) {
    163             if (sourceExists(sourceInfo)) {
    164                 int affectedRows = annotationDao.addAnnotationSource(annotationID, sourceDao.getInternalID(UUID.fromString(sourceInfo.getRef())));
     160        Number sourceIDRunner;
     161        for (SourceInfo sourceInfo : sources) { 
     162            sourceIDRunner = sourceDao.getInternalIDFromURI(sourceInfo.getRef());
     163            if (sourceIDRunner != null) {
     164                int affectedRows = annotationDao.addAnnotationSource(annotationID, sourceIDRunner);
    165165            } else {
    166166                Source newSource = createFreshSource(sourceInfo);
     
    168168                Number sourceID = sourceDao.addSource(newSource);
    169169                Number[] intermediateResult = addSiblingVersionForSource(sourceID, newVersion);
    170                 result.put(sourceInfo.getRef(), sourceDao.getExternalID(sourceID).toString());
     170                String sourceTemporaryID = sourceDao.stringURItoExternalID(sourceInfo.getRef());
     171                result.put(sourceTemporaryID, sourceDao.getExternalID(sourceID).toString());
    171172                int affectedRows = annotationDao.addAnnotationSource(annotationID, sourceID);
    172173            }
     
    175176    }
    176177
    177     // TODO add more criteria of being an existing sources
    178     private boolean sourceExists(SourceInfo sourceInfo) {
    179         boolean result = (sourceDao.getInternalID(UUID.fromString(sourceInfo.getRef())) != null);
    180         return result;
    181     }
    182178
    183179    @Override
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java

    r3596 r3598  
    2424import java.util.List;
    2525import java.util.UUID;
     26import javax.sql.DataSource;
    2627import javax.xml.datatype.DatatypeConfigurationException;
    2728import javax.xml.datatype.XMLGregorianCalendar;
     
    8990    protected String _serviceURI;
    9091   
    91    
     92 
    9293   
    9394    /////////////////// Class field SETTERS /////////////
     
    112113    }
    113114
     115    /////////////////////////////////////////////
    114116    @Override
    115117    public UUID getExternalID(Number internalId) {
     
    120122    }
    121123
     124    //////////////////////////////////////////////
     125    @Override
     126    public Number getInternalIDFromURI(String uri) {
     127        String externalID = stringURItoExternalID(uri);
     128        return getInternalID(UUID.fromString(externalID));
     129    }
     130   
    122131    /////////////////////////////////////////////////////
    123132    protected XMLGregorianCalendar retrieveTimeStamp(Number internalID) {
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/resources/spring-config/dbIntegrityService.xml

    r3477 r3598  
    2525">
    2626    <bean class="eu.dasish.annotation.backend.dao.impl.DBIntegrityServiceImlp">
    27         <!-- <constructor-arg ref="dataSource"/> -->
    2827    </bean>
    2928</beans>
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceTest.java

    r3596 r3598  
    7979    @Autowired
    8080    private AnnotationDao annotationDao;
    81     @Autowired
    82     private NotebookDao notebookDao;
     81   
     82   
    8383    TestInstances testInstances = new TestInstances();
    8484
     
    288288        String type = "text";
    289289        String tool = "latex";
     290        String externalID = UUID.randomUUID().toString();
    290291        final CachedRepresentationInfo newCachedInfo = new CachedRepresentationInfo();
    291292        newCachedInfo.setMimeType(mime);
    292293        newCachedInfo.setType(type);
    293294        newCachedInfo.setTool(tool);
     295        newCachedInfo.setRef(TestBackendConstants._TEST_SERVLET_URI + externalID);
    294296       
    295297        String  blobString = "aaa";
     
    300302        mockery.checking(new Expectations() {
    301303            {
    302                 oneOf(cachedRepresentationDao).getInternalID(null);
     304               
     305                oneOf(cachedRepresentationDao).getInternalIDFromURI(newCachedInfo.getRef());
    303306                will(returnValue(null));
    304307
     
    322325     * Test of addSiblingVersionForSource method, of class DBIntegrityServiceImlp.
    323326     */
     327    // TODO: teset with non-null esrive URI
    324328    @Test
    325329    public void testAddSiblingVersionForSource() throws Exception {
     
    328332        // test adding completely new version
    329333        final Version mockVersion = new Version(); // should be # 8
    330         final UUID mockUUID = UUID.randomUUID();
    331         mockVersion.setURI(mockUUID.toString()); // _serviceURI is assumed to be null for this test, therefore URI coincides with the externalID of the version
     334        String externalID = UUID.randomUUID().toString();
     335        mockVersion.setURI(TestBackendConstants._TEST_SERVLET_URI + externalID);
    332336        mockVersion.setVersion("version 8");
    333337
    334338        mockery.checking(new Expectations() {
    335339            {
    336                 oneOf(versionDao).stringURItoExternalID(mockUUID.toString());
    337                 will(returnValue(mockUUID.toString()));
    338                        
    339                 oneOf(versionDao).getInternalID(mockUUID);
     340                oneOf(versionDao).getInternalIDFromURI(mockVersion.getURI());
    340341                will(returnValue(null));
    341342
     
    358359
    359360        final Version mockVersionTwo = new Version(); // should be # 3
    360         final UUID mockUUIDTwo = UUID.fromString(TestBackendConstants._TEST_VERSION_3_EXT_ID);
    361         mockVersionTwo.setURI(mockUUIDTwo.toString()); // _serviceURI is assumed to be null for this test,therefore URI coincides with the externalID of the version
     361        mockVersionTwo.setURI(TestBackendConstants._TEST_SERVLET_URI + TestBackendConstants._TEST_VERSION_3_EXT_ID);
    362362        mockVersionTwo.setVersion("version 3");
    363363
    364364        mockery.checking(new Expectations() {
    365365            {
    366                 oneOf(versionDao).stringURItoExternalID(mockUUIDTwo.toString());
    367                 will(returnValue(mockUUIDTwo.toString()));
    368                
    369                 oneOf(versionDao).getInternalID(mockUUIDTwo);
     366                oneOf(versionDao).getInternalIDFromURI(mockVersionTwo.getURI());
    370367                will(returnValue(3));
    371368
     
    390387        SourceInfo testSourceOne = new SourceInfo();
    391388        testSourceOne.setLink(TestBackendConstants._TEST_SOURCE_1_LINK);
    392         testSourceOne.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID);
     389        testSourceOne.setRef(TestBackendConstants._TEST_SERVLET_URI + TestBackendConstants._TEST_SOURCE_1_EXT_ID);
    393390        testSourceOne.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);
    394         List<SourceInfo> mockSourceListOne = new ArrayList<SourceInfo>();
     391        final List<SourceInfo> mockSourceListOne = new ArrayList<SourceInfo>();
    395392        mockSourceListOne.add(testSourceOne);
    396393
    397394        mockery.checking(new Expectations() {
    398395            {   
    399                 // in sourceExists
    400                 oneOf(sourceDao).getInternalID(with(aNonNull(UUID.class)));
     396                oneOf(sourceDao).getInternalIDFromURI(mockSourceListOne.get(0).getRef());
    401397                will(returnValue(1));
    402398               
    403                 // in addSourceForAnnotationItself
    404                 oneOf(sourceDao).getInternalID(with(aNonNull(UUID.class)));
    405                 will(returnValue(1));
    406 
    407399                oneOf(annotationDao).addAnnotationSource(1, 1);
    408400                will(returnValue(1));
     
    415407        // test 2: adding a new source
    416408        SourceInfo testSourceTwo = new SourceInfo();
    417         testSourceTwo.setRef(UUID.randomUUID().toString());
     409        final String tempSourceID =  UUID.randomUUID().toString();
     410        testSourceTwo.setRef(TestBackendConstants._TEST_SERVLET_URI + tempSourceID);
    418411        testSourceTwo.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);
    419412        testSourceTwo.setVersion("version 1.0");
    420         List<SourceInfo> mockSourceListTwo = new ArrayList<SourceInfo>();
     413        final List<SourceInfo> mockSourceListTwo = new ArrayList<SourceInfo>();
    421414        mockSourceListTwo.add(testSourceTwo);
    422415
     
    425418        mockery.checking(new Expectations() {
    426419            {
    427                 // in sourceExists
    428                 oneOf(sourceDao).getInternalID(with(aNonNull(UUID.class)));
     420                oneOf(sourceDao).getInternalIDFromURI(mockSourceListTwo.get(0).getRef());
    429421                will(returnValue(null));
     422               
    430423                               
    431424                oneOf(sourceDao).addSource(with(aNonNull(Source.class)));
     
    433426
    434427                ////////////  mockery in the call addSiblingVersionForSource //////////////
     428                oneOf(versionDao).getInternalIDFromURI(null);
     429                will(returnValue(null));
    435430               
    436                 oneOf(versionDao).getInternalID(null);
    437                 will(returnValue(null));
    438 
    439431                oneOf(versionDao).addVersion(with(aNonNull(Version.class)));
    440432                will(returnValue(8)); // next free number
     
    445437                //////////////////////////////////////
    446438               
     439                oneOf(sourceDao).stringURItoExternalID(mockSourceListTwo.get(0).getRef());
     440                will(returnValue(tempSourceID));
     441                       
    447442                oneOf(sourceDao).getExternalID(6);
    448443                will(returnValue(mockNewSourceUUID));
     
    456451        Map<String, String> resultTwo = dbIntegrityService.addSourcesForAnnotation(1, mockSourceListTwo);
    457452        assertEquals(1, resultTwo.size());
    458         assertEquals(resultTwo.get(testSourceTwo.getRef()), mockNewSourceUUID.toString());
     453        assertEquals(mockNewSourceUUID.toString(), resultTwo.get(tempSourceID));
    459454
    460455    }
     
    476471
    477472                //  expectations for addSourcesForannotation
    478                 // first check if the source exists
    479                 oneOf(sourceDao).getInternalID(with(aNonNull(UUID.class)));
     473                oneOf(sourceDao).getInternalIDFromURI(with(aNonNull(String.class)));
    480474                will(returnValue(1));
    481475               
    482                 oneOf(sourceDao).getInternalID(with(aNonNull(UUID.class)));
    483                 will(returnValue(1));
    484 
    485476                oneOf(annotationDao).addAnnotationSource(6, 1);
    486477                will(returnValue(1));
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java

    r3594 r3598  
    182182        assertEquals(null, annotaionIdNull);
    183183    }
     184   
     185      /**
     186     * Test of getInternalIDFromURI method,
     187     * public Number getInternalIDFromURI(UUID externalID);
     188     */
     189    @Test
     190    public void testGetInternalIDFRomURI() {
     191        System.out.println("test getInternalIDFromURI");
     192        jdbcAnnotationDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI);
     193        String uri = TestBackendConstants._TEST_SERVLET_URI + TestBackendConstants._TEST_ANNOT_2_EXT;
     194        Number result = jdbcAnnotationDao.getInternalIDFromURI(uri);
     195        assertEquals(2, result.intValue());
     196    }
    184197
    185198    /**
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDaoTest.java

    r3596 r3598  
    2020import eu.dasish.annotation.backend.TestBackendConstants;
    2121import eu.dasish.annotation.schema.CachedRepresentationInfo;
    22 import java.io.InputStream;
    2322import java.io.UnsupportedEncodingException;
    2423import java.sql.Blob;
     
    2726import javax.sql.rowset.serial.SerialBlob;
    2827import javax.sql.rowset.serial.SerialException;
    29 import org.hsqldb.jdbc.JDBCBlobClient;
    3028import org.junit.Test;
    3129import static org.junit.Assert.*;
     
    3937 * @author olhsha
    4038 */
    41 
    4239@RunWith(SpringJUnit4ClassRunner.class)
    4340@ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-config/cachedRepresentationDao.xml"})
    44 public class JdbcCachedRepresentationDaoTest extends JdbcResourceDaoTest{
    45    
     41public class JdbcCachedRepresentationDaoTest extends JdbcResourceDaoTest {
     42
    4643    @Autowired
    47     JdbcCachedRepresentationDao jdbcCachedRepresentationDao;
    48    
    49    
     44    JdbcCachedRepresentationDao jdbcCachedRepresentationDao;
     45
    5046    public JdbcCachedRepresentationDaoTest() {
    5147    }
    52    
    53    
    5448
    5549    /**
    5650     * Test of getExternalId method, of class JdbcCachedRepresentationDao.
    5751     * public UUID getExternalId(Number internalID);
    58    
     52     *
    5953     */
    60     @Test 
     54    @Test
    6155    public void testGetExternalId() {
    6256        System.out.println("getExternalId");
     
    6660        assertEquals(expResult, result);
    6761    }
    68    
    6962
    7063    /**
    7164     * Test of getInternalId method, of class JdbcCachedRepresentationDao.
    72      * public  Number getInternalId(UUID externalID);
     65     * public Number getInternalId(UUID externalID);
    7366     */
    7467    @Test
    7568    public void testGetInternalId() {
    76         System.out.println("getInternalId");
     69        System.out.println("test getInternalID");
    7770        UUID externalID = UUID.fromString(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_);
    7871        Number result = jdbcCachedRepresentationDao.getInternalID(externalID);
    7972        assertEquals(1, result.intValue());
    8073    }
    81 
     74   
     75   
    8276    /**
    83      * Test of getCachedRepresentationInfo method, of class JdbcCachedRepresentationDao.
    84      *  public CachedRepresentationInfo getCachedRepresentationInfo(Number internalID);
     77     * Test of getInternalIDFromURI method,
     78     * public Number getInternalIDFromURI(UUID externalID);
    8579     */
    86     @Test 
     80    @Test
     81    public void testGetInternalIDFRomURI() {
     82        System.out.println("test getInternalIDFromURI");
     83        jdbcCachedRepresentationDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI);
     84        String uri = TestBackendConstants._TEST_SERVLET_URI + TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_;
     85        Number result = jdbcCachedRepresentationDao.getInternalIDFromURI(uri);
     86        assertEquals(1, result.intValue());
     87    }
     88   
     89    /**
     90     * Test of getCachedRepresentationInfo method, of class
     91     * JdbcCachedRepresentationDao. public CachedRepresentationInfo
     92     * getCachedRepresentationInfo(Number internalID);
     93     */
     94    @Test
    8795    public void testGetCachedRepresentationInfo() {
    8896        System.out.println("getCachedRepresentationInfo");
    89        
     97
    9098        jdbcCachedRepresentationDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI);
    91         CachedRepresentationInfo result = jdbcCachedRepresentationDao.getCachedRepresentationInfo(1);       
    92         assertEquals(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_, result.getRef());
     99        CachedRepresentationInfo result = jdbcCachedRepresentationDao.getCachedRepresentationInfo(1);
     100        assertEquals(TestBackendConstants._TEST_SERVLET_URI + TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_, result.getRef());
    93101        assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_MIME_TYPE_, result.getMimeType());
    94102        assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_TOOL_, result.getTool());
    95103        assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_TYPE_, result.getType());
    96         assertEquals(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_, result.getRef());
     104        assertEquals(TestBackendConstants._TEST_SERVLET_URI + TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_, result.getRef());
    97105    }
    98106
    99107    /**
    100      * Test of getCachedRepresentationBlob method, of class JdbcCachedRepresentationDao.
    101      *  public CachedRepresentationInfo getCachedRepresentationInfo(Number internalID);
     108     * Test of getCachedRepresentationBlob method, of class
     109     * JdbcCachedRepresentationDao. public CachedRepresentationInfo
     110     * getCachedRepresentationInfo(Number internalID);
    102111     */
    103     @Test 
    104     public void testGetCachedRepresentationBlob() throws SQLException, UnsupportedEncodingException{
     112    @Test
     113    public void testGetCachedRepresentationBlob() throws SQLException, UnsupportedEncodingException {
    105114        System.out.println("getCachedRepresentationBlob ");
    106115        Blob result = jdbcCachedRepresentationDao.getCachedRepresentationBlob(1);
     
    110119        assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_BLOB_BYTE_2, resultBytes[1]);
    111120    }
    112    
    113    
     121
    114122    /**
    115      * Test of deleteCachedRepresentationInfo method, of class JdbcCachedRepresentationDao.
    116      *  public int deleteCachedRepresentationInfo(Number internalID);
     123     * Test of deleteCachedRepresentationInfo method, of class
     124     * JdbcCachedRepresentationDao. public int
     125     * deleteCachedRepresentationInfo(Number internalID);
    117126     */
    118     @Test 
     127    @Test
    119128    public void testDeleteCachedRepresentationInfo() {
    120129        System.out.println("deleteCachedRepresentationInfo");
     
    122131        int result = jdbcCachedRepresentationDao.deleteCachedRepresentation(internalID);
    123132        assertEquals(1, result);
    124        
     133
    125134        int resultTwo = jdbcCachedRepresentationDao.deleteCachedRepresentation(internalID);
    126135        assertEquals(0, resultTwo);
    127        
     136
    128137        Number internalIDDoNotDelete = 5;
    129         int resultThree =jdbcCachedRepresentationDao.deleteCachedRepresentation(internalIDDoNotDelete);
     138        int resultThree = jdbcCachedRepresentationDao.deleteCachedRepresentation(internalIDDoNotDelete);
    130139        assertEquals(0, resultThree);
    131140    }
    132141
    133142    /**
    134      * Test of addCachedRepresentationInfo method, of class JdbcCachedRepresentationDao.
    135      * public CachedRepresentationInfo addCachedRepresentationInfo(CachedRepresentationInfo cached);   
     143     * Test of addCachedRepresentationInfo method, of class
     144     * JdbcCachedRepresentationDao. public CachedRepresentationInfo
     145     * addCachedRepresentationInfo(CachedRepresentationInfo cached);
    136146     */
    137     @Test 
    138     public void testAddCachedRepresentation() throws SerialException, SQLException{
     147    @Test
     148    public void testAddCachedRepresentation() throws SerialException, SQLException {
    139149        System.out.println("addCachedRepresentation");
    140        
     150
    141151        CachedRepresentationInfo cachedInfo = new CachedRepresentationInfo();
    142152        cachedInfo.setMimeType("text/plain");
     
    144154        cachedInfo.setType("text");
    145155        cachedInfo.setRef(null);
    146        
    147         String  blobString = "111";
    148         byte[] blobBytes = blobString.getBytes();       
     156
     157        String blobString = "111";
     158        byte[] blobBytes = blobString.getBytes();
    149159        final Blob cachedBlob = new SerialBlob(blobBytes);
    150        
     160
    151161        Number result = jdbcCachedRepresentationDao.addCachedRepresentation(cachedInfo, cachedBlob);
    152162        // checking
     
    157167        assertEquals("text", addedCachedInfo.getType());
    158168        assertFalse(addedCachedInfo.getRef() == null); // new non-null external identifier should be assigned
    159        
     169
    160170        Blob addedBlob = jdbcCachedRepresentationDao.getCachedRepresentationBlob(result);
    161171        int lengthBlob = 3;
    162172        String addedBlobString = new String(addedBlob.getBytes(1, lengthBlob));
    163173        assertEquals(blobString, addedBlobString);
    164      
     174
    165175    }
    166176   
    167  
     177   
    168178}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDaoTest.java

    r3594 r3598  
    1818package eu.dasish.annotation.backend.dao.impl;
    1919
     20import eu.dasish.annotation.backend.TestBackendConstants;
    2021import java.io.File;
    2122import java.io.FileNotFoundException;
     
    2324import java.net.URL;
    2425import java.util.Scanner;
     26import java.util.UUID;
    2527import org.junit.After;
    2628import org.junit.Before;
     29import org.junit.Test;
    2730import org.springframework.beans.factory.annotation.Autowired;
    2831import org.springframework.dao.DataAccessException;
    2932import org.springframework.jdbc.core.JdbcTemplate;
     33import static org.junit.Assert.*;
     34import org.junit.runner.RunWith;
     35import org.springframework.test.context.ContextConfiguration;
     36import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    3037/**
    3138 *
    3239 * @author olhsha
    3340 */
    34 
     41@RunWith(SpringJUnit4ClassRunner.class)
     42@ContextConfiguration({"/spring-test-config/dataSource.xml"})
    3543public class JdbcResourceDaoTest {
    3644   
     
    4048   private String getNormalisedSql() throws FileNotFoundException, URISyntaxException {
    4149        // remove the unsupported sql for the test
    42         final URL sqlUrl = JdbcNotebookDaoTest.class.getResource("/sql/DashishAnnotatorCreate.sql");
     50        final URL sqlUrl = JdbcResourceDaoTest.class.getResource("/sql/DashishAnnotatorCreate.sql");
    4351        String sqlString = new Scanner(new File(sqlUrl.toURI()), "UTF8").useDelimiter("\\Z").next();
    4452        for (String unknownToken : new String[]{
     
    8088    }
    8189   
    82    
     90    /**
     91     * Test of stringURItoExternalID method
     92     * public String stringURItoExternalID(String uri);
     93     */
     94    @Test
     95    public void testStringURItoExternalID() {
     96        JdbcResourceDao jdbcResourceDao = new JdbcResourceDao();
     97        System.out.println("test stringURItoExternalID");
     98        jdbcResourceDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI);
     99        String randomUUID = UUID.randomUUID().toString();
     100        String uri = TestBackendConstants._TEST_SERVLET_URI + randomUUID;
     101        String externalID = jdbcResourceDao.stringURItoExternalID(uri);
     102        assertEquals(randomUUID, externalID);
     103    }
     104   
     105    /**
     106     * Test of externalIDtoURI method
     107     * public String externalIDtoURI(String externalID);
     108     */
     109    @Test
     110    public void testExternalIDtoURI() {
     111        System.out.println("test stringURItoExternalID");
     112        JdbcResourceDao jdbcResourceDao = new JdbcResourceDao();
     113        jdbcResourceDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI);
     114        String randomUUID = UUID.randomUUID().toString();
     115        String uri = TestBackendConstants._TEST_SERVLET_URI + randomUUID;
     116        String uriResult = jdbcResourceDao.externalIDtoURI(randomUUID);
     117        assertEquals(uri, uriResult);
     118    }
    83119
    84120}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDaoTest.java

    r3593 r3598  
    6565        assertEquals(expResult, result);
    6666    }
     67   
     68    /**
     69     * Test of getInternalIDFromURI method,
     70     * public Number getInternalIDFromURI(UUID externalID);
     71     */
     72    @Test
     73    public void testGetInternalIDFRomURI() {
     74        System.out.println("test getInternalIDFromURI");
     75        jdbcSourceDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI);
     76        String uri = TestBackendConstants._TEST_SERVLET_URI + TestBackendConstants._TEST_SOURCE_1_EXT_ID;
     77        Number result = jdbcSourceDao.getInternalIDFromURI(uri);
     78        assertEquals(1, result.intValue());
     79    }
     80   
    6781
    6882    /**
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDaoTest.java

    r3463 r3598  
    6464        assertEquals(expResult, result);
    6565    }
     66   
     67    /**
     68     * Test of getInternalIDFromURI method,
     69     * public Number getInternalIDFromURI(UUID externalID);
     70     */
     71    @Test
     72    public void testGetInternalIDFRomURI() {
     73        System.out.println("test getInternalIDFromURI");
     74        jdbcVersionDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI);
     75        String uri = TestBackendConstants._TEST_SERVLET_URI + TestBackendConstants._TEST_VERSION_1_EXT_ID;
     76        Number result = jdbcVersionDao.getInternalIDFromURI(uri);
     77        assertEquals(1, result.intValue());
     78    }
     79   
     80
    6681
    6782    /**
Note: See TracChangeset for help on using the changeset viewer.