Changeset 3408


Ignore:
Timestamp:
08/18/13 16:21:58 (11 years ago)
Author:
olhsha
Message:

refactored DAO-s tests are added, but not all working yet. Also: add 8 more tests to dispatcher class

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
Files:
5 deleted
17 edited
2 moved

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java

    r3407 r3408  
    2121import eu.dasish.annotation.schema.Annotation;
    2222import eu.dasish.annotation.schema.AnnotationInfo;
     23import eu.dasish.annotation.schema.Permission;
    2324import eu.dasish.annotation.schema.ResourceREF;
     25import eu.dasish.annotation.schema.UserWithPermission;
    2426import java.sql.SQLException;
    2527import java.sql.Timestamp;
     
    5052     * @param annotationID
    5153     * @return the Annotation object with empty list of sources
    52      * constructing a complete Annotation object from theresult and "retrieveSourceIDs" is done in "CompoundRequests"
     54     * constructing a complete Annotation object from there sult and "retrieveSourceIDs" is done in "DaoDispatchter"
    5355     *
    5456     */
     
    5961     *
    6062     * @param annotationId
    61      * @return
    62      * result[0] = # removed "annotations_principals_perissions" rows
    63      * result[1] = # removed "annotatiobs_target_sources" rows
    64      * result[2] = # removed annotation rows (should be 1)
     63     * @return removed annotation rows (should be 1)
    6564     */
    6665   
    67     public int[] deleteAnnotation(Number annotationId) throws SQLException;
     66    public int deleteAnnotation(Number annotationId) throws SQLException;
    6867   
     68    /**
     69     *
     70     * @param annotationId
     71     * @return # removed annotation_source rows for given annotationID
     72     */
     73   
     74    public int deleteAllAnnotationSource(Number annotationId) throws SQLException;
    6975   
    7076   
     
    131137    public int addAnnotationSourcePair(Number annotationID, Number sourceID) throws SQLException;
    132138   
     139    public int deleteAnnotationPrincipalPermissions(Number annotationID) throws SQLException ;
     140
     141    /**
     142     *
     143     * @param annotationID
     144     * @param userID
     145     * @param permission
     146     * @return the amount of rows added to the table annotations_principals_permissions
     147     */
     148    public int addAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission) throws SQLException;
     149   
     150       /**
     151     *
     152     * @param annotationId
     153     * @return retrieves all the pairs (user-permission) for "annotationId" from the table annotations_principals permissions
     154     */
     155    public List<Map<Number, String>>  retrievePermissions(Number annotationId);
     156   
    133157}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/SourceDao.java

    r3407 r3408  
    1919
    2020import eu.dasish.annotation.backend.identifiers.SourceIdentifier;
    21 import eu.dasish.annotation.schema.NewOrExistingSourceInfo;
    2221import eu.dasish.annotation.schema.Source;
    2322import eu.dasish.annotation.schema.SourceInfo;
    2423import java.sql.SQLException;
    2524import java.util.List;
    26 import java.util.Map;
    2725
    2826/**
     
    5351     *
    5452     * @param internalId
    55      * @return result[0] # deleted rows in "sources_versions" table name
    56      * result[1] # deleted rows in "source" table
     53     * @return # deleted rows in "source" table
    5754     */
    58     public int[] deleteSource(Number internalID);
     55    public int deleteSource(Number internalID);
    5956   
    6057    /**
     
    6966   
    7067    public int addSourceVersion(Number sourceID, Number versionID) throws SQLException; 
     68   
     69    public int deleteAllSourceVersion(Number sourceID) throws SQLException; 
     70   
    7171   
    7272   
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/VersionDao.java

    r3407 r3408  
    1919
    2020import eu.dasish.annotation.backend.identifiers.VersionIdentifier;
    21 import eu.dasish.annotation.schema.CachedRepresentationInfo;
    2221import eu.dasish.annotation.schema.Version;
    2322import java.util.List;
     
    5655     
    5756    /** @param versionID
    58      * @return
    59      * result[0] # deleted rows in the joit table "versions_cached_representations"
    60      * result[1] # deleted rows in "version" table
     57     * @return deleted rows in "version" table
    6158     */
    6259   
    63     public int[] deleteVersion(Number versionID);
     60    public int deleteVersion(Number versionID);
    6461   
    6562    /**
     
    8582    public int addVersionCachedRepresentation(Number versionID, Number cachedID);
    8683   
     84    public int deleteAllVersionCachedRepresentation(Number versionID);
     85   
     86    // Not tested
     87    public boolean versionIsInUse(Number versionsID);
    8788}
    8889   
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r3407 r3408  
    2323import eu.dasish.annotation.schema.Annotation;
    2424import eu.dasish.annotation.schema.AnnotationInfo;
    25 import eu.dasish.annotation.schema.NewOrExistingSourceInfo;
    26 import eu.dasish.annotation.schema.NewOrExistingSourceInfos;
     25import eu.dasish.annotation.schema.Permission;
    2726import eu.dasish.annotation.schema.ResourceREF;
    28 import eu.dasish.annotation.schema.SourceInfo;
     27import eu.dasish.annotation.schema.UserWithPermission;
    2928import java.lang.String;
    3029import java.sql.ResultSet;
     
    202201        @Override
    203202        public Annotation mapRow(ResultSet rs, int rowNumber) throws SQLException {
    204            
    205             Map<String, Object> result = new HashMap<String, Object>();
    206            
    207203            Annotation annotation = new Annotation();
    208204
     
    234230    //////////////////////////////////////////////////////
    235231    @Override
    236     public int[] deleteAnnotation(Number annotationID) throws SQLException {
    237 
    238         int[] result = new int[3];
     232    public int deleteAnnotation(Number annotationID) throws SQLException {
     233        if (annotationIsInUse(annotationID)) {
     234            return 0;
     235        }
    239236       
    240         if (annotationIsInUse(annotationID)) {
    241             result[0] =0;
    242             result[1] =0;
    243             result[2] =0;
    244             return result;
    245         }
    246        
    247         String sqlPermissions = "DELETE FROM " + permissionsTableName + " where " + annotation_id + " = ?";
    248         result[0] = getSimpleJdbcTemplate().update(sqlPermissions, annotationID); // removed "permission" rows
    249        
     237        String sqlAnnotation = "DELETE FROM " + annotationTableName + " where " + annotation_id + " = ?";
     238        return (getSimpleJdbcTemplate().update(sqlAnnotation, annotationID));
     239    }
     240   
     241    //////////////////////////////////////////////////////
     242    @Override
     243    public int deleteAllAnnotationSource(Number annotationID) throws SQLException {
    250244        String sqlTargetSources = "DELETE FROM " + annotationsSourcesTableName + " where " + annotation_id + " = ?";
    251         result[1] = getSimpleJdbcTemplate().update(sqlTargetSources, annotationID); // removed "annotations_target_sources" rows
     245        return getSimpleJdbcTemplate().update(sqlTargetSources, annotationID); // removed "annotations_target_sources" rows
    252246       
    253         String sqlAnnotation = "DELETE FROM " + annotationTableName + " where " + annotation_id + " = ?";
    254         result[2] = getSimpleJdbcTemplate().update(sqlAnnotation, annotationID); // removed annotations rows
    255 
    256         return result;
    257     }
     247    }
     248   
    258249
    259250    // TODO: so far URI in the xml is the same as the external_id in the DB!!
     
    295286    }
    296287
    297     ///////////////////////////////////////////////////////////
    298     private ResourceREF getResourceREF(String resourceID) {
    299         ResourceREF result = new ResourceREF();
    300         result.setRef(resourceID);
    301         return result;
    302     }
     288   
    303289
    304290 
     
    317303    /////////////// helpers //////////////////
    318304   
     305    ///////////////////////////////////////////////////////////
     306    private ResourceREF getResourceREF(String resourceID) {
     307        ResourceREF result = new ResourceREF();
     308        result.setRef(resourceID);
     309        return result;
     310    }
     311   
    319312        //////////////////////////////
    320313    private boolean annotationIsInUse(Number sourceID) {
     
    334327    };
    335328   
     329    //////////////////////////////////////////////////////
     330    @Override
     331    public int deleteAnnotationPrincipalPermissions(Number annotationID) throws SQLException {
     332        String sqlPermissions = "DELETE FROM " + permissionsTableName + " where " + annotation_id + " = ?";
     333        return getSimpleJdbcTemplate().update(sqlPermissions, annotationID); // removed "permission" rows
     334       
     335    }
     336   
     337     /////////////////////////////////////////////////////////////////////////////////////////
     338    @Override
     339    public int addAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission) throws SQLException {
     340        Map<String, Object> paramsPermissions = new HashMap<String, Object>();
     341        paramsPermissions.put("annotationId", annotationID);
     342        paramsPermissions.put("principalId", userID);
     343        paramsPermissions.put("status", permission.value());
     344        String sqlUpdatePermissionTable = "INSERT INTO " + permissionsTableName + " (" + annotation_id + "," + principal_id + "," + permission + ") VALUES (:annotationId, :principalId, :status)";
     345        final int affectedPermissions = getSimpleJdbcTemplate().update(sqlUpdatePermissionTable, paramsPermissions);
     346        return affectedPermissions;
     347    }
     348   
     349   
     350      ///////////////////////////////////////////////////////////////////
     351    @Override
     352    public List<Map<Number, String>> retrievePermissions(Number annotationId) {
     353        if (annotationId == null) {
     354            return null;
     355        }
     356        String sql = "SELECT " + principal_id + "," + permission + " FROM " + permissionsTableName + " WHERE " + annotation_id + "  = ?";
     357        List<Map<Number, String>> result = getSimpleJdbcTemplate().query(sql, principalsPermissionsRowMapper, annotationId.toString());
     358        return result;
     359    }
     360    private final RowMapper<Map<Number, String>> principalsPermissionsRowMapper = new RowMapper<Map<Number, String>>() {
     361        @Override
     362        public Map<Number, String> mapRow(ResultSet rs, int rowNumber) throws SQLException {
     363            Map<Number,String> result = new HashMap<Number, String>();
     364            result.put(rs.getInt(principal_id),rs.getString(permission));
     365            return result;
     366        }
     367    };
     368   
    336369}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java

    r3407 r3408  
    102102    @Override
    103103    public int deleteCachedRepresentationInfo(Number internalID) {
    104         // ask the higher level if it can be deleted
    105104        if (cachedIsInUse(internalID)){
    106105           return 0;
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java

    r3395 r3408  
    2323import java.sql.ResultSet;
    2424import java.sql.SQLException;
    25 import java.util.ArrayList;
    2625import java.util.List;
    2726import javax.xml.datatype.DatatypeConfigurationException;
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDao.java

    r3407 r3408  
    7676    };
    7777
    78    
    79     ///////////////////////////////////////////////////////////////////
    80     @Override
    81     public int[] deleteSource(Number internalID) {
    82         int[] result = new int[2];       
     78    ///////////////////////////////////////////////////////////////////
     79    @Override
     80    public int deleteSource(Number internalID) {
    8381        if (sourceIsInUse(internalID)){
    84             result[0] =0;
    85             result[1] =0;
    86             return result;
    87         }
    88 
     82            return 0;
     83        }
     84        String sqlSourcesVersions = "DELETE FROM " + sourceTableName + " WHERE " + source_id + " = ? LIMIT 1";
     85        int result = getSimpleJdbcTemplate().update(sqlSourcesVersions, internalID);
     86        return result;
     87
     88    }
     89
     90   
     91    ///////////////////////////////////////////////////////////////////
     92    @Override
     93    public int deleteAllSourceVersion(Number internalID) {
    8994        String sqlSourcesVersions = "DELETE FROM " + sourcesVersionsTableName + " WHERE " + source_id + " = ?";
    90         result[0] = getSimpleJdbcTemplate().update(sqlSourcesVersions, internalID);
    91 
    92         String sql = "DELETE FROM " + sourceTableName + " WHERE " + source_id + " = ?";
    93         result[1] = getSimpleJdbcTemplate().update(sql, internalID);
    94 
     95        int result = getSimpleJdbcTemplate().update(sqlSourcesVersions, internalID);
    9596        return result;
    9697
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDao.java

    r3407 r3408  
    103103    /////////////////////////////////////////
    104104    @Override
    105     public int[] deleteVersion(Number internalID) {
     105    public int deleteVersion(Number internalID) {
    106106       
    107         int[] result = new int[2];       
     107        int result = 0;       
    108108        if (versionIsInUse(internalID)) {
    109             // firs delete sources that refer to it!
    110             result[0]=0;
    111             result[1]=0;
    112109            return result;
    113110        }
    114111       
    115         // remove all the pairs (internalID, cached_representation) from the joint table "versions_cahched_representations"   
    116         String sqlVersionsCachedRepresentations = "DELETE FROM " + versionsCachedRepresentationsTableName + " where " + version_id + " = ?";
    117         result[0] = getSimpleJdbcTemplate().update(sqlVersionsCachedRepresentations, internalID);
    118        
    119         // the main action: remove the version with internalID from "version" table
    120112        String sql = "DELETE FROM " + versionTableName + " where " + version_id + " = ?";
    121         result[1] = getSimpleJdbcTemplate().update(sql, internalID);     
     113        result = getSimpleJdbcTemplate().update(sql, internalID);     
    122114        return result;
    123115
     
    150142    return (getSimpleJdbcTemplate().update(sql.toString(), params));
    151143    }
     144   
     145    ////////////////////////////////////////////
     146    @Override
     147    public int deleteAllVersionCachedRepresentation(Number versionID){
     148    StringBuilder sql = new StringBuilder("DELETE FROM ");
     149    sql.append(versionsCachedRepresentationsTableName).append(" WHERE ").append(version_id).append(" = ?");
     150    return (getSimpleJdbcTemplate().update(sql.toString(), versionID));
     151    }
    152152       
    153153    ////////////////////////////////////////////
     
    166166   
    167167   
    168     ///////////////////// PRIVATE //////////////////////////////
    169    
    170     private boolean versionIsInUse(Number versionsID) {
     168    @Override
     169    public boolean versionIsInUse(Number versionsID) {
    171170        String sql = "SELECT " + source_id + " FROM " + sourcesVersionsTableName + " WHERE " + version_id + "= ? LIMIT 1";
    172171        List<Number> result = getSimpleJdbcTemplate().query(sql, sourceIDRowMapper, versionsID);
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/integration/DaoDispatcher.java

    r3407 r3408  
    2222import eu.dasish.annotation.backend.dao.CachedRepresentationDao;
    2323import eu.dasish.annotation.backend.dao.NotebookDao;
    24 import eu.dasish.annotation.backend.dao.PermissionsDao;
    2524import eu.dasish.annotation.backend.dao.SourceDao;
    2625import eu.dasish.annotation.backend.dao.UserDao;
     
    4948 * @author olhsha
    5049 */
    51 public class DaoRequestor {
     50public class DaoDispatcher {
    5251
    5352    @Autowired
    5453    UserDao userDao;
    5554    @Autowired
    56     PermissionsDao permissionsDao;
    57     @Autowired
    5855    CachedRepresentationDao cachedRepresentationDao;
    5956    @Autowired
     
    6562    @Autowired
    6663    NotebookDao notebookDao;
    67    
    68    
    69    
    70     public Number getAnnotationInternalIdentifier(AnnotationIdentifier annotationIdentifier){
     64
     65    public Number getAnnotationInternalIdentifier(AnnotationIdentifier annotationIdentifier) {
    7166        return annotationDao.getInternalID(annotationIdentifier);
    7267    }
    73    
    74      public AnnotationIdentifier getAnnotationExternalIdentifier(Number annotationID){
     68
     69    public AnnotationIdentifier getAnnotationExternalIdentifier(Number annotationID) {
    7570        return annotationDao.getExternalID(annotationID);
    7671    }
    7772
    78      public Number getUserInternalIdentifier(UserIdentifier userIdentifier){
     73    public Number getUserInternalIdentifier(UserIdentifier userIdentifier) {
    7974        return userDao.getInternalID(userIdentifier);
    8075    }
    81    
    82      public UserIdentifier getUserExternalIdentifier(Number userID){
     76
     77    public UserIdentifier getUserExternalIdentifier(Number userID) {
    8378        return userDao.getExternalID(userID);
    84     } 
    85      
     79    }
     80
    8681    /**
    8782     *
     
    121116        return result;
    122117    }
    123    
    124     /**
    125      * 
     118
     119    /**
     120     *
    126121     * @param versionID
    127      * @return 
    128      * result[0] # deleted rows in the joit table "versions_cached_representations"
    129      * result[1] # deleted rows in "version" table
    130      * result[2] # deleted cached representations (which are not referred by other versions)
    131      *
    132      */
    133 
     122     * @return result[0] # deleted rows in "version" table result[1] # deleted
     123     * rows in the joint table "versions_cached_representations" result[2] #
     124     * deleted cached representations (which are not referred by other versions)
     125     *
     126     */
    134127    public int[] deleteVersionWithCachedRepresentations(Number versionID) {
    135128        int[] result = new int[3];
    136         List<Number> cachedRepresentations = versionDao.retrieveCachedRepresentationList(versionID);
    137         int[] deleteVersion = versionDao.deleteVersion(versionID);
    138         result[0] = deleteVersion[0];
    139         result[1] = deleteVersion[1];
     129        if (!versionDao.versionIsInUse(versionID)) {
     130            List<Number> cachedRepresentations = versionDao.retrieveCachedRepresentationList(versionID);
     131            result[1] = versionDao.deleteAllVersionCachedRepresentation(versionID);
     132            result[0] = versionDao.deleteVersion(versionID);
     133            result[2] = 0;
     134            for (Number cachedID : cachedRepresentations) {
     135                result[2] = result[2] + cachedRepresentationDao.deleteCachedRepresentationInfo(cachedID);
     136
     137            }
     138        } else {
     139            result[0] = 0;
     140            result[1] = 0;
     141            result[2] = 0;
     142        }
     143        return result;
     144    }
     145
     146    /**
     147     *
     148     * @param sourceID
     149     * @return result[0] # deleted rows in "source" table result[1] # deleted
     150     * rows in "sources_versions" table name result[2] # deleted rows in
     151     * "version" table
     152     */
     153    public int[] deleteSourceWithVersions(Number sourceID) throws SQLException {
     154        int[] result = new int[3];
     155        List<Number> versions = sourceDao.retrieveVersionList(sourceID);
     156        result[1] = sourceDao.deleteAllSourceVersion(sourceID);
     157        result[0] = sourceDao.deleteSource(sourceID);
    140158        result[3] = 0;
    141         for (Number cachedID : cachedRepresentations) {
    142             result[3] = result[3] + cachedRepresentationDao.deleteCachedRepresentationInfo(cachedID);
    143 
    144         }
    145         return result;
    146     }
    147    
    148     /**
    149      *
    150      * @param sourceID
    151      * @return result[0] # deleted rows in "sources_versions" table name
    152      * result[1] # deleted rows in "source" table
    153      * result[2] # deleted rows in "version" table (not used by the other sources)
    154      */
    155     public int[] deleteSourceWithVersions(Number sourceID){
    156         int[] result = new int[3]; 
    157         List<Number> versions = sourceDao.retrieveVersionList(sourceID);
    158         int[] deleteSource = sourceDao.deleteSource(sourceID);
    159         result[0] = deleteSource[0];
    160         result[1]=deleteSource[1];
    161         result[3] =0;
    162159        for (Number versionID : versions) {
    163160            int[] deleteVersion = deleteVersionWithCachedRepresentations(versionID);
    164             result[3]=result[3]+deleteVersion[1];
    165         }
    166       return result;
    167      
    168     }
    169    
     161            result[3] = result[3] + deleteVersion[1];
     162        }
     163        return result;
     164
     165    }
     166
    170167    /**
    171168     * @param source
    172      * @return internal Id of the newly added source or -1 if the source is not added because no version for it;
    173      * in the last case the rest-interface  will return envelope asking to add a version (with the cached representation);
    174      * after the clinet adds the version (s)he gets the version external ID which is to be set in source;
    175      * the the client asks to add the source again.
    176      * @throws SQLException
    177      */
    178     public Number addSourceAndPairSourceVersion(NewSourceInfo newSource) throws SQLException{
     169     * @return internal Id of the newly added source or -1 if the source is not
     170     * added because no version for it; in the last case the rest-interface will
     171     * return envelope asking to add a version (with the cached representation);
     172     * after the clinet adds the version (s)he gets the version external ID
     173     * which is to be set in source; the the client asks to add the source
     174     * again.
     175     * @throws SQLException
     176     */
     177    public Number addSourceAndPairSourceVersion(NewSourceInfo newSource) throws SQLException {
    179178        Number versionID = versionDao.getInternalID(new VersionIdentifier(newSource.getVersion()));
    180179        if (versionID == null) {
     
    186185        source.setURI(externalIdentifier.toString());
    187186        source.setLink(newSource.getLink());
    188         source.setVersion(newSource.getVersion());       
     187        source.setVersion(newSource.getVersion());
    189188        Number result = sourceDao.addSource(source);
    190189        final int sourceVersions = sourceDao.addSourceVersion(result, versionID);
    191190        return result;
    192191    }
    193    
    194  
    195192
    196193    ///////////////////////////////////////////////
    197    
    198     /**
    199      *
     194    /**
     195     *
    200196     * @param annotationID
    201197     * @param sources
    202      * @return the mapping temporarySourceID -> peristenExternalSOurceId
    203      * adds a source from "sources" to the DB if it is not there, to the table "target_source"
    204      * adds the wro (annotationID, sourceID) to the joint table "annotations_sources"
    205      * @throws SQLException
     198     * @return the mapping temporarySourceID -> peristenExternalSOurceId adds a
     199     * source from "sources" to the DB if it is not there, to the table
     200     * "target_source" adds the wro (annotationID, sourceID) to the joint table
     201     * "annotations_sources"
     202     * @throws SQLException
    206203     */
    207204    public Map<String, String> addTargetSourcesToAnnotation(Number annotationID, List<NewOrExistingSourceInfo> sources) throws SQLException {
     
    222219        }
    223220        return result;
    224     }
    225    
    226    
    227       ////////////////////////////////////////////////////////////////////////
    228    
     221    }
     222
     223    ////////////////////////////////////////////////////////////////////////
    229224    public List<Number> getFilteredAnnotationIDs(String link, String text, String access, String namespace, UserIdentifier owner, Timestamp after, Timestamp before) {
    230225
    231226        List<Number> annotationIDs = null;
    232        
     227
    233228        if (link != null) {
    234229            List<Number> sourceIDs = sourceDao.getSourcesForLink(link);
    235230            annotationIDs = annotationDao.retrieveAnnotationList(sourceIDs);
    236231        }
    237        
    238         Number ownerID =  null; 
     232
     233        Number ownerID = null;
    239234        if (owner != null) {
    240235            ownerID = userDao.getInternalID(owner);
     
    244239    }
    245240
    246      /**
    247      * 
     241    /**
     242     *
    248243     * @param annotationId
    249      * @return
    250      * result[0] = # removed "annotations_principals_permissions" rows
    251      * result[1] = # removed "annotations_target_sources" rows
    252      * result[2] = # removed annotation rows (should be 1)
    253      * result[3] = # deleted sources
    254      */
    255     public int[] deleteAnnotationWithSources(Number annotationID) throws SQLException {
     244     * @return result[0] = # removed annotation rows (should be 1) result[1] = #
     245     * removed "annotations_principals_permissions" rows result[2] = # removed
     246     * "annotations_target_sources" rows result[3] = # deleted sources
     247     */
     248    public int[] deleteAnnotationWithSourcesAndPermissions(Number annotationID) throws SQLException {
    256249        int[] result = new int[4];
    257         List<Number> sourceIDs = annotationDao.retrieveSourceIDs(annotationID);       
    258         int[] deleteAnnotation = annotationDao.deleteAnnotation(annotationID);
    259         result[0]= deleteAnnotation[0];
    260         result[1]= deleteAnnotation[1];
    261         result[2] = deleteAnnotation[2];
    262         result[3]=0;
     250        result[1] = annotationDao.deleteAnnotationPrincipalPermissions(annotationID);
     251        List<Number> sourceIDs = annotationDao.retrieveSourceIDs(annotationID);
     252        result[2] = annotationDao.deleteAllAnnotationSource(annotationID);
     253        result[0] = annotationDao.deleteAnnotation(annotationID);
     254        result[3] = 0;
    263255        for (Number sourceID : sourceIDs) {
    264256            int[] deleteSource = deleteSourceWithVersions(sourceID);
     
    267259        return result;
    268260    }
    269      
    270    
    271     public Annotation getAnnotation(Number annotationID) throws SQLException{
     261
     262    public Annotation getAnnotation(Number annotationID) throws SQLException {
    272263        Annotation result = annotationDao.getAnnotationWithoutSources(annotationID);
    273264        List<Number> sourceIDs = annotationDao.retrieveSourceIDs(annotationID);
    274265        for (Number sourceID : sourceIDs) {
    275             NewOrExistingSourceInfo noesi = new  NewOrExistingSourceInfo();
     266            NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();
    276267            Source source = sourceDao.getSource(sourceID);
    277268            SourceInfo sourceInfo = new SourceInfo();
     
    284275        return result;
    285276    }
    286    
    287    
     277
    288278    //need to return an envelope!
    289     public Annotation addAnnotationWithTargetSources(Annotation annotation, Number userID) throws SQLException{
    290        
     279    public Annotation addAnnotationWithTargetSources(Annotation annotation, Number userID) throws SQLException {
     280
    291281        Number annotationID = annotationDao.addAnnotation(annotation, userID);
    292        
     282
    293283        List<NewOrExistingSourceInfo> sources = annotation.getTargetSources().getTarget();
    294         Map<String, String> sourceIdPairs= addTargetSourcesToAnnotation(annotationID, sources);
    295        
    296         if (sourceIdPairs.containsValue(null)){
    297            // for one of the soirces there was no version and cached representation
     284        Map<String, String> sourceIdPairs = addTargetSourcesToAnnotation(annotationID, sources);
     285
     286        if (sourceIdPairs.containsValue(null)) {
     287            // for one of the soirces there was no version and cached representation
    298288            // envelope
    299            return annotation;
     289            return annotation;
    300290        }
    301291        String body = Helpers.serializeBody(annotation.getBody());
    302292        String newBody = Helpers.replace(body, sourceIdPairs);
    303293        int affectedAnnotRows = annotationDao.updateBody(annotationID, newBody);
    304        
     294
    305295        // Add the permission (annotation_id, owner);
    306         int affectedPermissions = permissionsDao.addAnnotationPrincipalPermission(annotationID, userID, Permission.OWNER);
    307        
     296        int affectedPermissions = annotationDao.addAnnotationPrincipalPermission(annotationID, userID, Permission.OWNER);
     297
    308298        Annotation newAnnotation = getAnnotation(annotationID);
    309299        return newAnnotation;
    310300    }
    311    
    312 }
     301}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java

    r3407 r3408  
    1919
    2020import eu.dasish.annotation.backend.BackendConstants;
    21 import eu.dasish.annotation.backend.dao.integration.DaoRequestor;
     21import eu.dasish.annotation.backend.dao.integration.DaoDispatcher;
    2222import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
    2323import eu.dasish.annotation.backend.identifiers.UserIdentifier;
     
    4646public class AnnotationResource {
    4747
    48     private DaoRequestor requestor;
     48    private DaoDispatcher requestor;
    4949    @Context
    5050    private HttpServletRequest httpServletRequest;
     
    7272    public String deleteAnnotation(@PathParam("annotationid") String annotationIdentifier) throws SQLException {
    7373        final Number annotationID = requestor.getAnnotationInternalIdentifier(new AnnotationIdentifier(annotationIdentifier));
    74         int[] resultDelete = requestor.deleteAnnotationWithSources(annotationID);
    75         String result = Integer.toString(resultDelete[4]);
     74        int[] resultDelete = requestor.deleteAnnotationWithSourcesAndPermissions(annotationID);
     75        String result = Integer.toString(resultDelete[0]);
    7676        return result;
    7777    }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/MockObjectsFactory.java

    r3221 r3408  
    2121import eu.dasish.annotation.backend.dao.CachedRepresentationDao;
    2222import eu.dasish.annotation.backend.dao.NotebookDao;
    23 import eu.dasish.annotation.backend.dao.PermissionsDao;
    2423import eu.dasish.annotation.backend.dao.SourceDao;
    2524import eu.dasish.annotation.backend.dao.UserDao;
     
    5251    }
    5352   
    54     public PermissionsDao newPermissionsDao() {
    55         return context.mock(PermissionsDao.class);
    56     }
    57    
     53   
    5854    public SourceDao newSourceDao() {
    5955        return context.mock(SourceDao.class);
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java

    r3407 r3408  
    1818package eu.dasish.annotation.backend.dao.impl;
    1919
     20import eu.dasish.annotation.backend.Helpers;
    2021import eu.dasish.annotation.backend.TestBackendConstants;
    2122import eu.dasish.annotation.backend.TestInstances;
    2223import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
    23 import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    2424import eu.dasish.annotation.schema.Annotation;
    2525import eu.dasish.annotation.schema.AnnotationInfo;
    26 import eu.dasish.annotation.schema.NewOrExistingSourceInfo;
    27 import eu.dasish.annotation.schema.NewOrExistingSourceInfos;
     26import eu.dasish.annotation.schema.Permission;
    2827import eu.dasish.annotation.schema.ResourceREF;
    29 import eu.dasish.annotation.schema.SourceInfo;
    3028import java.sql.SQLException;
    3129import java.sql.Timestamp;
     
    3331import java.util.List;
    3432import java.util.Map;
    35 import org.jmock.Expectations;
    3633import static org.junit.Assert.*;
    3734import org.junit.Test;
     
    5350    TestInstances testInstances = new TestInstances();
    5451
    55     /**
    56      * Test of getAnnotationInfos method, of class JdbcAnnotationDao.
    57      * List<AnnotationInfo> getAnnotationInfos(List<Number> annotationIDs)
    58      */
    5952   
    6053      /**
    61      * Test of retrieveSourceIDs method, of class JdbcSourceDao.
     54     * Test of retrieveSourceIDs method, of class JdbcAnnotationDao.
    6255     */
    6356    @Test
     
    7164    }
    7265   
     66    ///////////////////////////////////////////
     67    @Test
     68    public void testDeleteAllAnnotationSource() throws SQLException{
     69        System.out.println("test deleteAllAnnotationSources");
     70        assertEquals(2, jdbcAnnotationDao.deleteAllAnnotationSource(2));
     71        assertEquals(0, jdbcAnnotationDao.deleteAllAnnotationSource(2));
     72    }
     73   
     74    ///////////////////////////////////////////
     75    @Test
     76    public void testDeleteAnnotationPrinciplePermissions() throws SQLException{
     77        System.out.println("test deleteAllAnnotationSources");
     78        int result = jdbcAnnotationDao.deleteAnnotationPrincipalPermissions(2);
     79        assertEquals(3, result);
     80        assertEquals(0, jdbcAnnotationDao.deleteAnnotationPrincipalPermissions(2));
     81    }
     82   
     83    ///////////////////////////////////////////
     84    @Test
     85    public void testAddAnnotationPrinciplePermission() throws SQLException{
     86        System.out.println("test addAnnotationSources");
     87        int result = jdbcAnnotationDao.addAnnotationPrincipalPermission(2, 1, Permission.READER);
     88        assertEquals(1, result);
     89    }
     90   
     91    ///////////////////////////////////////////
     92    @Test
     93    public void testAddAnnotationSourcePair() throws SQLException{
     94        System.out.println("test addAnnotationSourcePair");
     95        assertEquals(1, jdbcAnnotationDao.addAnnotationSourcePair(1,2));
     96    }
     97   
     98    ////////////////////////////////
     99   
    73100    @Test
    74101    public void testGetAnnotationInfos() {
     
    150177    /**
    151178     *
    152      * Test of getAnnotation method, of class JdbcAnnotationDao. Annotation
     179     * Test of getAnnotationWithoutSources method, of class JdbcAnnotationDao. Annotation
    153180     * getAnnotation(Number annotationlID)
    154181     */
    155182    @Test
    156     public void getAnnotation() throws SQLException {
    157         System.out.println("test getAnnotation");
     183    public void getAnnotationWithoutSources() throws SQLException {
     184        System.out.println("test getAnnotationWithoutSources");
    158185
    159186        /// dummy test
     
    174201     * Test of deletAnnotation method, of class JdbcAnnotationDao.
    175202     */
     203     /**
     204     *
     205     * @param annotationId
     206     * @return removed annotation rows (should be 1)
     207     */
    176208    @Test
    177209    public void testDeleteAnnotation() throws SQLException {
    178210        System.out.println("deleteAnnotation");
    179         // result[0] = # removed "annotations_principals_perissions" rows
    180         // result[1] = # removed "annotatiobs_target_sources" rows
    181         // result[2] = # removed annotation rows (should be 1)
    182        
    183         int[] result = jdbcAnnotationDao.deleteAnnotation(5);
    184         assertEquals(3, result[0]);
    185         assertEquals(2, result[1]);
    186         assertEquals(1, result[2]);
    187        
    188         // now, try to delete the same annotation one more time
    189         // if it has been already deleted then the method under testing should return 0
    190    
    191         result = jdbcAnnotationDao.deleteAnnotation(5);
    192         assertEquals(0, result[0]);
    193         assertEquals(0, result[1]);
    194         assertEquals(0, result[2]);
     211       
     212        // to provide integrity, first delete rows in the joint tables
     213        jdbcAnnotationDao.deleteAllAnnotationSource(5);
     214        jdbcAnnotationDao.deleteAnnotationPrincipalPermissions(5);
     215       
     216        assertEquals(1, jdbcAnnotationDao.deleteAnnotation(5));
     217        assertEquals(0, jdbcAnnotationDao.deleteAnnotation(5));
    195218    }
    196219
     
    219242 
    220243
    221 
    222 //        NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();
    223 //        NewSourceInfo nsi = new NewSourceInfo();
    224 //        nsi.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);
    225 //        nsi.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID);
    226 //        nsi.setVersion(null);
    227 //        noesi.setNewSource(nsi);
    228 //
    229 //
    230 //        NewOrExistingSourceInfo noesiTwo = new NewOrExistingSourceInfo();
    231 //        SourceInfo si = new SourceInfo();
    232 //        si.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);
    233 //        si.setRef((new SourceIdentifier()).toString());
    234 //        si.setVersion(null);
    235 //        noesiTwo.setSource(si);
    236 //
    237 //        final Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> map = new HashMap<NewOrExistingSourceInfo, NewOrExistingSourceInfo>();
    238 //        map.put(noesi, noesiTwo);
    239 //
    240 //
    241 //        mockery.checking(new Expectations() {
    242 //            {
    243 //                oneOf(sourceDao).addTargetSources(with(aNonNull(Number.class)), with(aNonNull(List.class)));
    244 //                will(returnValue(map));
    245 //            }
    246 //        });
    247 
    248  
    249     /**
    250      * testing public List<Number> getAnnotationIDsForSources(List<Number> sourceIDs);
     244    /**
     245     * testing public List<Number> retrieveAnnotationList(List<Number> sourceIDs);
    251246   
    252247    **/
    253248    @Test   
    254     public void testGetAnnotationIDsForSources() {
    255         System.out.println("test getAnnotationIDs for sources");
     249    public void testRetrieveAnnotationList() {
     250        System.out.println("test retrieveAnnotationlist");
    256251        List<Number> sources = new ArrayList<Number>();
    257252        sources.add(1);
     
    263258    }
    264259   
     260    //////////////////////////////////
     261   
     262   
    265263    @Test   
    266264    public void testGetExternalID() {
     
    320318        Timestamp after_1 = new Timestamp(System.currentTimeMillis());       
    321319        List<Number> result_5 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, "some html", null, null, 1, after_1, null);       
    322         assertEquals(0, result_5.size());
    323        
    324        
    325     }
    326    
    327      /**
    328      * Test of contructNewOrExistingSourceInfo method, of class JdbcSourceDao.
    329      */
    330     @Test
    331     public void testContructNewOrExistingSourceInfo() {
    332         System.out.println("contructNewOrExistingSourceInfo");
    333 
    334         List<SourceInfo> sourceInfoList = new ArrayList<SourceInfo>();
    335 
    336         SourceInfo sourceInfoOne = new SourceInfo();
    337         sourceInfoOne.setLink(TestBackendConstants._TEST_SOURCE_1_LINK);
    338         sourceInfoOne.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID);
    339         sourceInfoOne.setRef(TestBackendConstants._TEST_VERSION_1_EXT_ID);
    340 
    341         SourceInfo sourceInfoTwo = new SourceInfo();
    342         sourceInfoTwo.setLink(TestBackendConstants._TEST_SOURCE_2_LINK);
    343         sourceInfoTwo.setRef(TestBackendConstants._TEST_SOURCE_2_EXT_ID);
    344         sourceInfoTwo.setRef(TestBackendConstants._TEST_VERSION_3_EXT_ID);
    345 
    346         sourceInfoList.add(sourceInfoOne);
    347         sourceInfoList.add(sourceInfoTwo);
    348 
    349 //        NewOrExistingSourceInfos result = jdbcSourceDao.contructNewOrExistingSourceInfo(sourceInfoList);
    350 //        assertEquals(2, result.getTarget().size());
    351 //        assertEquals(sourceInfoOne, result.getTarget().get(0).getSource());
    352 //        assertEquals(sourceInfoTwo, result.getTarget().get(1).getSource());
    353 
    354     }
    355 
    356 //    /**
    357 //     * Test of addTargetSources method, of class JdbcSourceDao. public
    358 //     * Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo>
    359 //     * addTargetSources(Number annotationID, List<NewOrExistingSourceInfo>
    360 //     * sources)
    361 //     */
    362 //    @Test
    363 //    public void testAddTargetSourcesOnExistingSource() {
    364 //        System.out.println("addTargetSources : adding the old source");
    365 //
    366 //        NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();
    367 //        SourceInfo si = new SourceInfo();
    368 //        si.setLink(TestBackendConstants._TEST_SOURCE_1_LINK);
    369 //        si.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID);
    370 //        si.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);
    371 //        noesi.setSource(si);
    372 //
    373 //        List<NewOrExistingSourceInfo> listnoesi = new ArrayList<NewOrExistingSourceInfo>();
    374 //        listnoesi.add(noesi);
    375 //
    376 //        try {
    377 //            Map<String, String> result = jdbcSourceDao.addTargetSources(5, listnoesi);
    378 //            assertEquals(0, result.size()); // no new peristsent source IDs are produced
    379 //        } catch (SQLException e) {
    380 //            System.out.println(e);
    381 //        }
    382 //    }
    383 //
    384 //    /**
    385 //     * Test of addTargetSources method, of class JdbcSourceDao. public
    386 //     * Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo>
    387 //     * addTargetSources(Number annotationID, List<NewOrExistingSourceInfo>
    388 //     * sources)
    389 //     */
    390 //    @Test
    391 //    public void testAddTargetSourcesOnNewSource() {
    392 //        System.out.println("addTargetSources : adding the new source");
    393 //
    394 //        NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();
    395 //        NewSourceInfo nsi = new NewSourceInfo();
    396 //        nsi.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);
    397 //        nsi.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID);
    398 //        nsi.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);
    399 //        noesi.setNewSource(nsi);
    400 //
    401 //        List<NewOrExistingSourceInfo> listnoesiTwo = new ArrayList<NewOrExistingSourceInfo>();
    402 //        listnoesiTwo.add(noesi);
    403 //       
    404 //        mockery.checking(new Expectations() {
    405 //            {
    406 //                oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID));
    407 //                will(returnValue(1));
    408 //            }
    409 //        });
    410 //
    411 //        try {
    412 //            Map<String, String> result = jdbcSourceDao.addTargetSources(5, listnoesiTwo);
    413 //            assertEquals(1, result.size());// a new identifier must be produced
    414 //            SourceIdentifier sourceIdentifier = new SourceIdentifier(result.get(TestBackendConstants._TEST_TEMP_SOURCE_ID));
    415 //            assertFalse(null == sourceIdentifier.getUUID()); // check if a proper uuid has been assigned
    416 //        } catch (SQLException e) {
    417 //            System.out.print(e);
    418 //        }
    419 //
    420 //    }
    421 //   
     320        assertEquals(1, result_5.size());
     321       
     322       
     323    }
     324   
     325    //////////////////////////////////
     326    @Test
     327    public void testUpdateBody() throws SQLException{
     328        System.out.println("test UpdateAnnotationBody");
     329        String serializedNewBody = "new body";
     330        int result = jdbcAnnotationDao.updateBody(2, serializedNewBody);
     331        assertEquals(1, result);
     332        Annotation updatedAnnotation= jdbcAnnotationDao.getAnnotationWithoutSources(2);
     333        assertEquals(serializedNewBody, Helpers.serializeBody(updatedAnnotation.getBody()));
     334    }
     335
     336   
     337    // public List<Map<Number, String>> retrievePermissions(Number annotationId)
     338   
     339    @Test
     340    public void testRetrievePermissions (){
     341        // VALUES (2, 3, 'owner');
     342        //VALUES (2, 4, 'writer');
     343        //VALUES (2, 5, 'reader');
     344        System.out.println("test Permissions");
     345        List<Map<Number, String>> result = jdbcAnnotationDao.retrievePermissions(2);
     346        assertEquals(2, result.size());
     347        assertEquals("owner", result.get(0).get(3));
     348        assertEquals("writer", result.get(0).get(4));
     349        assertEquals("reader", result.get(0).get(5));
     350       
     351       
     352    }
    422353}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDaoTest.java

    r3407 r3408  
    8080    public void testGetCachedRepresentationInfo() {
    8181        System.out.println("getCachedRepresentationInfo");
    82         Number internalID = 1;
    8382       
    84         CachedRepresentationInfo expResult = new CachedRepresentationInfo();
    85         expResult.setMimeType(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_MIME_TYPE_);
    86         expResult.setRef(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_);
    87         expResult.setTool(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_TOOL_);
    88         expResult.setType(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_TYPE_);
    89        
    90         CachedRepresentationInfo result = jdbcCachedRepresentationDao.getCachedRepresentationInfo(internalID);
    91         assertEquals(expResult.getMimeType(), result.getMimeType());
    92         assertEquals(expResult.getType(), result.getType());
    93         assertEquals(expResult.getTool(), result.getTool());
    94         assertEquals(expResult.getRef(), result.getRef());
     83        CachedRepresentationInfo result = jdbcCachedRepresentationDao.getCachedRepresentationInfo(1);
     84        assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_MIME_TYPE_, result.getMimeType());
     85        assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_, result.getType());
     86        assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_TOOL_, result.getTool());
     87        assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_TYPE_, result.getRef());
    9588    }
    9689
     
    131124        Number result = jdbcCachedRepresentationDao.addCachedRepresentationInfo(cached);
    132125        CachedRepresentationInfo addedCached = jdbcCachedRepresentationDao.getCachedRepresentationInfo(result);
     126        assertEquals(8, result.intValue());
    133127        assertEquals("text/plain", addedCached.getMimeType());
    134128        assertEquals("vi", addedCached.getTool());
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDaoTest.java

    r3407 r3408  
    1919
    2020import eu.dasish.annotation.backend.TestBackendConstants;
    21 import eu.dasish.annotation.backend.dao.VersionDao;
    2221import eu.dasish.annotation.backend.identifiers.SourceIdentifier;
    2322import eu.dasish.annotation.backend.identifiers.VersionIdentifier;
     
    2726import java.util.ArrayList;
    2827import java.util.List;
    29 import org.jmock.Expectations;
    30 import org.jmock.Mockery;
    3128import org.junit.Test;
    3229import static org.junit.Assert.*;
     
    7572     */
    7673    @Test
    77     @Ignore
    7874    public void testGetSource() {
    7975        System.out.println("getSource");
    8076        Number internalID = 1;
    81         final Number internalVersionID = 1;
    82         final VersionIdentifier externalVersionID = new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID);
    83 
    84 //        mockery.checking(new Expectations() {
    85 //            {
    86 //                oneOf(versionDao).getExternalID(internalVersionID);
    87 //                will(returnValue(externalVersionID));
    88 //            }
    89 //        });
    90 
    9177        Source result = jdbcSourceDao.getSource(internalID);
    9278        assertEquals(TestBackendConstants._TEST_SOURCE_1_EXT_ID, result.getURI());
     
    10288    public void testDeleteSource() {
    10389        System.out.println("deleteSource");
     90       
     91        // remove the rows from the joint table to keep integrity
     92        jdbcSourceDao.deleteAllSourceVersion(1);
    10493
    10594        // test 1
    106         int[] result = jdbcSourceDao.deleteSource(1); //the source is in use, should not be deleted
    107         assertEquals(0, result[0]); //
    108         assertEquals(0, result[1]);
     95        int result = jdbcSourceDao.deleteSource(1); //the source is in use, should not be deleted
     96        assertEquals(0, result);
    10997
    11098        // test 2
    111         final int[] versionDeleted = new int[3];
    112         versionDeleted[0] = 0; // versions_cahced_representations
    113         versionDeleted[1] = 1; // version deleted
    114         versionDeleted[2] = 0; // deleted cached representations; version 7 does not have them
    115 //        mockery.checking(new Expectations() {
    116 //            {
    117 //                oneOf(versionDao).deleteVersion(7);
    118 //                will(returnValue(versionDeleted)); // no other sources refer to this version # 5
    119 //            }
    120 //        });
     99        int resultTwo = jdbcSourceDao.deleteSource(5);// the source will be deleted because it is not referred by any annotation
     100        assertEquals(1, resultTwo);
     101    }
     102   
     103    /**
     104     * Test of deleteAllSourceVersion method, of class JdbcSourceDao.
     105     */
     106    @Test
     107    public void testDeleteAllSourceVersion() {
     108        System.out.println("test deleteAllSourceVersion");
     109       assertEquals(2, jdbcSourceDao.deleteAllSourceVersion(1));
    121110
    122         int[] resultTwo = jdbcSourceDao.deleteSource(5);// the source will be deleted because it is not referred by any annotation
    123         assertEquals(1, resultTwo[0]); // row (5,7) in "sorces_versions" is deleted
    124         assertEquals(1, resultTwo[1]); //source 5 is deleted from "source" table
    125111    }
    126112
     113    /**
     114     * Test of addSourceVersion method, of class JdbcSourceDao.
     115     */
     116    @Test
     117    public void testAddSourceVersion() throws SQLException{
     118        System.out.println("test addSourceVersion");
     119       assertEquals(1, jdbcSourceDao.addSourceVersion(1,3));
     120
     121    }
     122   
    127123    /**
    128124     * Test of addSource method, of class JdbcSourceDao.
    129125     */
    130126    @Test
    131     @Ignore
    132127    public void testAddSource() throws SQLException {
    133128        System.out.println("addSource");
    134129
    135130        String link = "http://www.sagradafamilia.cat/";
    136 
    137131        // test 1: existing version
    138132        Source freshSource = new Source();
     
    141135        freshSource.setURI(null);
    142136        freshSource.setTimeSatmp(null);
    143 
    144 //        mockery.checking(new Expectations() {
    145 //            {
    146 //                oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID));
    147 //                will(returnValue(1));
    148 //            }
    149 //        });
    150 
     137       
    151138        Number result = jdbcSourceDao.addSource(freshSource);
    152139        assertEquals(6, result);
    153        
    154 //        mockery.checking(new Expectations() {
    155 //            {
    156 //                oneOf(versionDao).getExternalID(1); // used in getSource
    157 //                will(returnValue(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID)));
    158 //               
    159 //               
    160 //            }
    161 //        });
    162140        Source addedSource = jdbcSourceDao.getSource(result);
    163141        assertEquals(link, addedSource.getLink());
     
    167145        ////////// test 2 non-existing version
    168146        freshSource.setVersion(TestBackendConstants._TEST_VERSION_NONEXIST_EXT_ID);
    169 //        mockery.checking(new Expectations() {
    170 //            {
    171 //                oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_NONEXIST_EXT_ID));
    172 //                will(returnValue(null));
    173 //            }
    174 //        });
    175 
    176 
    177147        Number resultTwo = jdbcSourceDao.addSource(freshSource);
    178148        assertEquals(-1, resultTwo); // addversion (preferably with cached representation
     
    189159        test.add(1);
    190160        test.add(2);
    191 
    192 //        mockery.checking(new Expectations() {
    193 //            {
    194 //                oneOf(versionDao).getExternalID(1);
    195 //                will(returnValue(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID)));
    196 //
    197 //                oneOf(versionDao).getExternalID(3);
    198 //                will(returnValue(new VersionIdentifier(TestBackendConstants._TEST_VERSION_3_EXT_ID)));
    199 //            }
    200 //        });
    201 
    202161        List<SourceInfo> result = jdbcSourceDao.getSourceInfos(test);
    203162        assertEquals(2, result.size());
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDaoTest.java

    r3407 r3408  
    8686     */
    8787    @Test
    88     @Ignore
    8988    public void testDeleteVersion() {
    9089        System.out.println("deleteVersion");
    91 //        mockery.checking(new Expectations() {
    92 //            {
    93 //                oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(5);
    94 //                will(returnValue(0));
    95 //
    96 //            }
    97 //        });
    98         int[] result = jdbcVersionDao.deleteVersion(6);
    99         assertEquals(1, result[0]); //versions-cached
    100         assertEquals(1, result[1]); // version
    101         assertEquals(0, result[2]);//cached 5 is in use
    102 
    103 
    104         int[] resultTwo = jdbcVersionDao.deleteVersion(5); // version is in use by the source 4
    105         assertEquals(0, resultTwo[0]);
    106         assertEquals(0, resultTwo[1]);
    107         assertEquals(0, resultTwo[2]);
     90       
     91        // remove the rows from the joint table to keep integrity
     92        jdbcVersionDao.deleteAllVersionCachedRepresentation(6);
     93        int result = jdbcVersionDao.deleteVersion(6);
     94        assertEquals(1, result);
     95        assertEquals(0, jdbcVersionDao.deleteVersion(6)); // delete the same version: nothing happen
     96       
     97        int resultTwo = jdbcVersionDao.deleteVersion(5); // version is in use by the source 4
     98        assertEquals(0, resultTwo);
    10899
    109100    }
     
    117108
    118109        Version freshVersion = new Version();
    119 
    120110        Number result = jdbcVersionDao.addVersion(freshVersion);
    121111        assertEquals(8, result);
    122112        Version addedVersion = jdbcVersionDao.getVersion(result);
    123         assertFalse(null == addedVersion.getVersion());
     113        assertFalse(null == addedVersion.getVersion()); // extend once "version" information is fixed, and becomes different from externalID
    124114    }
    125115   
     
    145135        assertEquals(expResult, result);
    146136    }
     137    ////////////////////////////////////////////////////////
     138    @Test
     139    public void deleteVersionCachedRepresentation(){
     140        System.out.println("test deleteVersionCachedRepresentation");
     141        assertEquals(1, jdbcVersionDao.deleteVersionCachedRepresentation(1, 1));
     142        assertEquals(0, jdbcVersionDao.deleteVersionCachedRepresentation(1, 2));
     143       
     144    }
     145   
     146    ////////////////////////////////////////////////////////
     147    @Test
     148    public void deleteAllVersionCachedRepresentation(){
     149        System.out.println("test deleteAllVersionCachedRepresentation");
     150        assertEquals(2, jdbcVersionDao.deleteAllVersionCachedRepresentation(1));
     151    }
     152   
     153    ////////////////////////////////////////////////////////
     154    @Test
     155    public void addVersionCachedRepresentation(){
     156        System.out.println("test addVersionCachedRepresentation");
     157        assertEquals(1, jdbcVersionDao.addVersionCachedRepresentation(1, 7));
     158    }
    147159}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/integration/DaoDispatcherTest.java

    r3407 r3408  
    1818package eu.dasish.annotation.backend.dao.integration;
    1919
     20import eu.dasish.annotation.backend.TestBackendConstants;
     21import eu.dasish.annotation.backend.dao.AnnotationDao;
     22import eu.dasish.annotation.backend.dao.CachedRepresentationDao;
     23import eu.dasish.annotation.backend.dao.NotebookDao;
     24import eu.dasish.annotation.backend.dao.SourceDao;
     25import eu.dasish.annotation.backend.dao.UserDao;
     26import eu.dasish.annotation.backend.dao.VersionDao;
    2027import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
     28import eu.dasish.annotation.backend.identifiers.CachedRepresentationIdentifier;
    2129import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    2230import eu.dasish.annotation.schema.Annotation;
     
    2432import eu.dasish.annotation.schema.NewOrExistingSourceInfo;
    2533import eu.dasish.annotation.schema.NewSourceInfo;
     34import eu.dasish.annotation.schema.SourceInfo;
     35import java.sql.SQLException;
    2636import java.sql.Timestamp;
     37import java.util.ArrayList;
    2738import java.util.List;
    2839import java.util.Map;
    29 import org.junit.After;
    30 import org.junit.AfterClass;
    31 import org.junit.Before;
    32 import org.junit.BeforeClass;
     40import org.jmock.Expectations;
     41import org.jmock.Mockery;
    3342import org.junit.Test;
    3443import static org.junit.Assert.*;
    3544import org.junit.runner.RunWith;
     45import org.springframework.beans.factory.annotation.Autowired;
    3646import org.springframework.test.context.ContextConfiguration;
    3747import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
     
    4353@RunWith(SpringJUnit4ClassRunner.class)
    4454@ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml",
    45     "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockNotebookDao.xml",
    46     "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockVersionDao.xml", "/spring-config/cachedRepresentationDao.xml"})
    47 public class DaoRequestorTest {
    48    
    49     public DaoRequestorTest() {
    50     }
    51    
    52    
    53     /**
    54      * Test of getAnnotationInternalIdentifier method, of class DaoRequestor.
     55    "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockNotebookDao.xml",
     56    "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockVersionDao.xml", "/spring-test-config/cachedRepresentationDao.xml"})
     57public class DaoDispatcherTest {
     58
     59    private DaoDispatcher daoDispatcher;
     60    private Mockery mockery;
     61    @Autowired
     62    UserDao userDao;
     63    @Autowired
     64    CachedRepresentationDao cachedRepresentationDao;
     65    @Autowired
     66    VersionDao versionDao;
     67    @Autowired
     68    SourceDao sourceDao;
     69    @Autowired
     70    AnnotationDao annotationDao;
     71    @Autowired
     72    NotebookDao notebookDao;
     73
     74    public DaoDispatcherTest() {
     75    }
     76
     77    /**
     78     * Test of getAnnotationInternalIdentifier method, of class DaoDispatcher.
    5579     */
    5680    @Test
    5781    public void testGetAnnotationInternalIdentifier() {
    5882        System.out.println("getAnnotationInternalIdentifier");
    59         AnnotationIdentifier annotationIdentifier = null;
    60         DaoRequestor instance = new DaoRequestor();
    61         Number expResult = null;
    62         Number result = instance.getAnnotationInternalIdentifier(annotationIdentifier);
    63         assertEquals(expResult, result);
    64         // TODO review the generated test code and remove the default call to fail.
    65         fail("The test case is a prototype.");
    66     }
    67 
    68     /**
    69      * Test of getAnnotationExternalIdentifier method, of class DaoRequestor.
     83        final AnnotationIdentifier annotationIdentifier = new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_2_EXT);
     84
     85        mockery.checking(new Expectations() {
     86            {
     87                oneOf(annotationDao).getInternalID(annotationIdentifier);
     88                will(returnValue(2));
     89            }
     90        });
     91        assertEquals(2, daoDispatcher.getAnnotationInternalIdentifier(annotationIdentifier));
     92    }
     93
     94    /**
     95     * Test of getAnnotationExternalIdentifier method, of class DaoDispatcher.
    7096     */
    7197    @Test
    7298    public void testGetAnnotationExternalIdentifier() {
    7399        System.out.println("getAnnotationExternalIdentifier");
    74         Number annotationID = null;
    75         DaoRequestor instance = new DaoRequestor();
    76         AnnotationIdentifier expResult = null;
    77         AnnotationIdentifier result = instance.getAnnotationExternalIdentifier(annotationID);
    78         assertEquals(expResult, result);
    79         // TODO review the generated test code and remove the default call to fail.
    80         fail("The test case is a prototype.");
    81     }
    82 
    83     /**
    84      * Test of getUserInternalIdentifier method, of class DaoRequestor.
     100        final AnnotationIdentifier annotationIdentifier = new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_2_EXT);
     101
     102        mockery.checking(new Expectations() {
     103            {
     104                oneOf(annotationDao).getExternalID(2);
     105                will(returnValue(annotationIdentifier));
     106            }
     107        });
     108        assertEquals(TestBackendConstants._TEST_ANNOT_2_EXT, daoDispatcher.getAnnotationExternalIdentifier(2).toString());
     109    }
     110
     111    /**
     112     * Test of getUserInternalIdentifier method, of class DaoDispatcher.
    85113     */
    86114    @Test
    87115    public void testGetUserInternalIdentifier() {
    88116        System.out.println("getUserInternalIdentifier");
    89         UserIdentifier userIdentifier = null;
    90         DaoRequestor instance = new DaoRequestor();
    91         Number expResult = null;
    92         Number result = instance.getUserInternalIdentifier(userIdentifier);
    93         assertEquals(expResult, result);
    94         // TODO review the generated test code and remove the default call to fail.
    95         fail("The test case is a prototype.");
    96     }
    97 
    98     /**
    99      * Test of getUserExternalIdentifier method, of class DaoRequestor.
     117
     118        final UserIdentifier userIdentifier = new UserIdentifier(TestBackendConstants._TEST_USER_5_EXT_ID);
     119
     120        mockery.checking(new Expectations() {
     121            {
     122                oneOf(annotationDao).getInternalID(userIdentifier);
     123                will(returnValue(5));
     124            }
     125        });
     126        assertEquals(5, daoDispatcher.getUserInternalIdentifier(userIdentifier));
     127    }
     128
     129    /**
     130     * Test of getUserExternalIdentifier method, of class DaoDispatcher.
    100131     */
    101132    @Test
    102133    public void testGetUserExternalIdentifier() {
    103134        System.out.println("getUserExternalIdentifier");
    104         Number userID = null;
    105         DaoRequestor instance = new DaoRequestor();
    106         UserIdentifier expResult = null;
    107         UserIdentifier result = instance.getUserExternalIdentifier(userID);
    108         assertEquals(expResult, result);
    109         // TODO review the generated test code and remove the default call to fail.
    110         fail("The test case is a prototype.");
    111     }
    112 
    113     /**
    114      * Test of deleteCachedForVersion method, of class DaoRequestor.
     135        final UserIdentifier userIdentifier = new UserIdentifier(TestBackendConstants._TEST_USER_5_EXT_ID);
     136
     137        mockery.checking(new Expectations() {
     138            {
     139                oneOf(annotationDao).getExternalID(5);
     140                will(returnValue(userIdentifier));
     141            }
     142        });
     143        assertEquals(TestBackendConstants._TEST_USER_5_EXT_ID, daoDispatcher.getUserExternalIdentifier(5));
     144    }
     145
     146    /**
     147     * Test of deleteCachedForVersion method, of class DaoDispatcher.
    115148     */
    116149    @Test
    117150    public void testDeleteCachedForVersion() {
    118151        System.out.println("deleteCachedForVersion");
    119         Number versionID = null;
    120         Number cachedID = null;
    121         DaoRequestor instance = new DaoRequestor();
    122         int[] expResult = null;
    123         int[] result = instance.deleteCachedForVersion(versionID, cachedID);
    124         assertArrayEquals(expResult, result);
    125         // TODO review the generated test code and remove the default call to fail.
    126         fail("The test case is a prototype.");
    127     }
    128 
    129     /**
    130      * Test of addCachedForVersion method, of class DaoRequestor.
     152        mockery.checking(new Expectations() {
     153            {
     154                oneOf(versionDao).deleteVersionCachedRepresentation(6, 5);
     155                will(returnValue(1));
     156
     157                oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(5);
     158                will(returnValue(0)); // cached is used by another version
     159
     160            }
     161        });
     162
     163        int[] result = daoDispatcher.deleteCachedForVersion(6, 5);
     164        assertEquals(2, result.length);
     165        assertEquals(1, result[0]);
     166        assertEquals(0, result[1]);
     167    }
     168
     169    /**
     170     * Test of addCachedForVersion method, of class DaoDispatcher.
    131171     */
    132172    @Test
    133173    public void testAddCachedForVersion() {
    134174        System.out.println("addCachedForVersion");
    135         Number versionID = null;
    136         CachedRepresentationInfo cached = null;
    137         DaoRequestor instance = new DaoRequestor();
    138         Number[] expResult = null;
    139         Number[] result = instance.addCachedForVersion(versionID, cached);
    140         assertArrayEquals(expResult, result);
    141         // TODO review the generated test code and remove the default call to fail.
    142         fail("The test case is a prototype.");
    143     }
    144    
    145    
    146    
    147      /**
     175        String mime = "text/html";
     176        String type = "text";
     177        String tool = "latex";
     178        final CachedRepresentationInfo newCached = new CachedRepresentationInfo();
     179        newCached.setMimeType(mime);
     180        newCached.setType(type);
     181        newCached.setTool(tool);
     182        final Number newID = 8;
     183        final Number versionID = 1;
     184        mockery.checking(new Expectations() {
     185            {
     186                oneOf(cachedRepresentationDao).getInternalID(new CachedRepresentationIdentifier(newCached.getRef()));
     187                will(returnValue(null));
     188
     189                oneOf(cachedRepresentationDao).addCachedRepresentationInfo(newCached);
     190                will(returnValue(newID));
     191
     192                one(versionDao).addVersionCachedRepresentation(versionID, newID);
     193                will(returnValue(1));
     194
     195            }
     196        });
     197
     198
     199        Number[] result = daoDispatcher.addCachedForVersion(6, newCached);
     200        assertEquals(2, result.length);
     201        assertEquals(newID, result[0]);
     202        assertEquals(1, result[1]);
     203    }
     204
     205    /////////////////////////////////////////////
     206    public void testDeleteVersionWithCachedRepresentations() {
     207        System.out.println("deleteVersion");
     208        final List<Number> cachedList = new ArrayList<Number>();
     209        cachedList.add(5);
     210
     211        mockery.checking(new Expectations() {
     212            {
     213                oneOf(versionDao).versionIsInUse(6);
     214                will(returnValue(false));
     215               
     216                oneOf(versionDao).retrieveCachedRepresentationList(6);
     217                will(returnValue(cachedList));
     218
     219                oneOf(versionDao).deleteAllVersionCachedRepresentation(6);
     220                will(returnValue(1));
     221               
     222                oneOf(versionDao).deleteVersion(6);
     223                will(returnValue(1));
     224
     225                oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(5);
     226                will(returnValue(0)); // cached is used by another version
     227               
     228               
     229
     230            }
     231        });
     232
     233        int[] result = daoDispatcher.deleteVersionWithCachedRepresentations(6);
     234        assertEquals(1, result[0]); //version
     235        assertEquals(1, result[1]); // versions-cached
     236        assertEquals(0, result[2]);//cached 5 is in use
     237       
     238        //Another test
     239       
     240        mockery.checking(new Expectations() {
     241            {
     242                oneOf(versionDao).versionIsInUse(5);
     243                will(returnValue(true));
     244            }
     245        });
     246
     247
     248        int[] resultTwo = daoDispatcher.deleteVersionWithCachedRepresentations(5); // version is in use by the source 4
     249        assertEquals(0, resultTwo[0]);
     250        assertEquals(0, resultTwo[1]);
     251        assertEquals(0, resultTwo[2]);
     252
     253    }
     254
     255    @Test
     256    public void testDeleteSource() throws SQLException {
     257
     258        // test 1
     259        int[] result = daoDispatcher.deleteSourceWithVersions(1); //the source is in use, should not be deleted
     260        assertEquals(0, result[0]); //
     261        assertEquals(0, result[1]);
     262
     263        // test 2
     264        final int[] versionDeleted = new int[3];
     265        versionDeleted[0] = 0; // versions_cahced_representations
     266        versionDeleted[1] = 1; // version deleted
     267        versionDeleted[2] = 0; // deleted cached representations; version 7 does not have them
     268//        mockery.checking(new Expectations() {
     269//            {
     270//                oneOf(versionDao).deleteVersion(7);
     271//                will(returnValue(versionDeleted)); // no other sources refer to this version # 5
     272//            }
     273//        });
     274
     275        int[] resultTwo = daoDispatcher.deleteSourceWithVersions(5);// the source will be deleted because it is not referred by any annotation
     276        assertEquals(1, resultTwo[0]); // row (5,7) in "sorces_versions" is deleted
     277        assertEquals(1, resultTwo[1]);
     278    }
     279
     280    /**
    148281     * Test of addVersion method, of class JdbcVersionDao.
    149282     */
     
    162295//        assertEquals(1, result[1].intValue());
    163296//    }
    164 
    165      /**
     297    /**
    166298     *
    167299     */
     
    183315//
    184316//    /**
    185 //     * Test of deleteVersionWithCachedRepresentations method, of class DaoRequestor.
     317//     * Test of deleteVersionWithCachedRepresentations method, of class DaoDispatcher.
    186318//     */
    187319//    @Test
     
    189321//        System.out.println("deleteVersionWithCachedRepresentations");
    190322//        Number versionID = null;
    191 //        DaoRequestor instance = new DaoRequestor();
     323//        DaoDispatcher instance = new DaoDispatcher();
    192324//        int[] expResult = null;
    193325//        int[] result = instance.deleteVersionWithCachedRepresentations(versionID);
     
    196328//        fail("The test case is a prototype.");
    197329//    }
    198 
    199     /**
    200      * Test of deleteSourceWithVersions method, of class DaoRequestor.
    201      */
    202     @Test
    203     public void testDeleteSourceWithVersions() {
     330    /**
     331     * Test of deleteSourceWithVersions method, of class DaoDispatcher.
     332     */
     333    @Test
     334    public void testDeleteSourceWithVersions() throws SQLException {
    204335        System.out.println("deleteSourceWithVersions");
    205336        Number sourceID = null;
    206         DaoRequestor instance = new DaoRequestor();
     337        DaoDispatcher instance = new DaoDispatcher();
    207338        int[] expResult = null;
    208339        int[] result = instance.deleteSourceWithVersions(sourceID);
     
    213344
    214345    /**
    215      * Test of addSourceAndPairSourceVersion method, of class DaoRequestor.
     346     * Test of addSourceAndPairSourceVersion method, of class DaoDispatcher.
    216347     */
    217348    @Test
     
    219350        System.out.println("addSourceAndPairSourceVersion");
    220351        NewSourceInfo newSource = null;
    221         DaoRequestor instance = new DaoRequestor();
     352        DaoDispatcher instance = new DaoDispatcher();
    222353        Number expResult = null;
    223354        Number result = instance.addSourceAndPairSourceVersion(newSource);
     
    228359
    229360    /**
    230      * Test of addTargetSourcesToAnnotation method, of class DaoRequestor.
     361     * Test of addTargetSourcesToAnnotation method, of class DaoDispatcher.
    231362     */
    232363    @Test
    233364    public void testAddTargetSourcesToAnnotation() throws Exception {
    234365        System.out.println("addTargetSourcesToAnnotation");
     366
     367
     368//        NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();
     369//        NewSourceInfo nsi = new NewSourceInfo();
     370//        nsi.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);
     371//        nsi.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID);
     372//        nsi.setVersion(null);
     373//        noesi.setNewSource(nsi);
     374//
     375//
     376//        NewOrExistingSourceInfo noesiTwo = new NewOrExistingSourceInfo();
     377//        SourceInfo si = new SourceInfo();
     378//        si.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);
     379//        si.setRef((new SourceIdentifier()).toString());
     380//        si.setVersion(null);
     381//        noesiTwo.setSource(si);
     382//
     383//        final Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> map = new HashMap<NewOrExistingSourceInfo, NewOrExistingSourceInfo>();
     384//        map.put(noesi, noesiTwo);
     385//
     386//
     387//        mockery.checking(new Expectations() {
     388//            {
     389//                oneOf(sourceDao).addTargetSources(with(aNonNull(Number.class)), with(aNonNull(List.class)));
     390//                will(returnValue(map));
     391//            }
     392//        });
     393
     394
    235395        Number annotationID = null;
    236396        List<NewOrExistingSourceInfo> sources = null;
    237         DaoRequestor instance = new DaoRequestor();
     397        DaoDispatcher instance = new DaoDispatcher();
    238398        Map expResult = null;
    239399        Map result = instance.addTargetSourcesToAnnotation(annotationID, sources);
     
    244404
    245405    /**
    246      * Test of getFilteredAnnotationIDs method, of class DaoRequestor.
     406     * Test of getFilteredAnnotationIDs method, of class DaoDispatcher.
    247407     */
    248408    @Test
     
    256416        Timestamp after = null;
    257417        Timestamp before = null;
    258         DaoRequestor instance = new DaoRequestor();
     418        DaoDispatcher instance = new DaoDispatcher();
    259419        List expResult = null;
    260420        List result = instance.getFilteredAnnotationIDs(link, text, access, namespace, owner, after, before);
     
    265425
    266426    /**
    267      * Test of deleteAnnotationWithSources method, of class DaoRequestor.
     427     * Test of deleteAnnotationWithSources method, of class DaoDispatcher.
    268428     */
    269429    @Test
     
    271431        System.out.println("deleteAnnotationWithSources");
    272432        Number annotationID = null;
    273         DaoRequestor instance = new DaoRequestor();
     433        DaoDispatcher instance = new DaoDispatcher();
    274434        int[] expResult = null;
    275         int[] result = instance.deleteAnnotationWithSources(annotationID);
     435        int[] result = instance.deleteAnnotationWithSourcesAndPermissions(annotationID);
    276436        assertArrayEquals(expResult, result);
    277437        // TODO review the generated test code and remove the default call to fail.
     
    280440
    281441    /**
    282      * Test of getAnnotation method, of class DaoRequestor.
     442     * Test of getAnnotation method, of class DaoDispatcher.
    283443     */
    284444    @Test
     
    286446        System.out.println("getAnnotation");
    287447        Number annotationID = null;
    288         DaoRequestor instance = new DaoRequestor();
     448        DaoDispatcher instance = new DaoDispatcher();
    289449        Annotation expResult = null;
    290450        Annotation result = instance.getAnnotation(annotationID);
     
    295455
    296456    /**
    297      * Test of addAnnotationWithTargetSources method, of class DaoRequestor.
    298      */
    299     @Test
    300     public void testAddAnnotationWithTargetSources() throws Exception {
    301         System.out.println("addAnnotationWithTargetSources");
    302         Annotation annotation = null;
    303         Number userID = null;
    304         DaoRequestor instance = new DaoRequestor();
    305         Annotation expResult = null;
    306         Annotation result = instance.addAnnotationWithTargetSources(annotation, userID);
    307         assertEquals(expResult, result);
    308         // TODO review the generated test code and remove the default call to fail.
    309         fail("The test case is a prototype.");
    310     }
     457     *
     458     * @param annotationId
     459     * @return result[0] = # removed "annotations_principals_permissions" rows
     460     * result[1] = # removed "annotations_target_sources" rows result[2] = #
     461     * removed annotation rows (should be 1)
     462     */
     463    @Test
     464    public void testDeleteAnnotationWithSourcesAndPermissions() throws SQLException {
     465        System.out.println("test deleteAnnotationWithSourcesAndPermissions");
     466        // result[0] = # removed "annotations_principals_perissions" rows
     467        // result[1] = # removed "annotatiobs_target_sources" rows
     468        // result[2] = # removed annotation rows (should be 1)
     469
     470        int[] result = daoDispatcher.deleteAnnotationWithSourcesAndPermissions(5);
     471        assertEquals(3, result[0]);
     472        assertEquals(2, result[1]);
     473        assertEquals(1, result[2]);
     474
     475        // now, try to delete the same annotation one more time
     476        // if it has been already deleted then the method under testing should return 0
     477
     478        result = daoDispatcher.deleteAnnotationWithSourcesAndPermissions(5);
     479        assertEquals(0, result[0]);
     480        assertEquals(0, result[1]);
     481        assertEquals(0, result[2]);
     482    }
     483
     484    /**
     485     * Test of contructNewOrExistingSourceInfo method, of class JdbcSourceDao.
     486     */
     487    @Test
     488    public void testContructNewOrExistingSourceInfo() {
     489        System.out.println("contructNewOrExistingSourceInfo");
     490
     491        List<SourceInfo> sourceInfoList = new ArrayList<SourceInfo>();
     492
     493        SourceInfo sourceInfoOne = new SourceInfo();
     494        sourceInfoOne.setLink(TestBackendConstants._TEST_SOURCE_1_LINK);
     495        sourceInfoOne.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID);
     496        sourceInfoOne.setRef(TestBackendConstants._TEST_VERSION_1_EXT_ID);
     497
     498        SourceInfo sourceInfoTwo = new SourceInfo();
     499        sourceInfoTwo.setLink(TestBackendConstants._TEST_SOURCE_2_LINK);
     500        sourceInfoTwo.setRef(TestBackendConstants._TEST_SOURCE_2_EXT_ID);
     501        sourceInfoTwo.setRef(TestBackendConstants._TEST_VERSION_3_EXT_ID);
     502
     503        sourceInfoList.add(sourceInfoOne);
     504        sourceInfoList.add(sourceInfoTwo);
     505
     506//        NewOrExistingSourceInfos result = jdbcSourceDao.contructNewOrExistingSourceInfo(sourceInfoList);
     507//        assertEquals(2, result.getTarget().size());
     508//        assertEquals(sourceInfoOne, result.getTarget().get(0).getSource());
     509//        assertEquals(sourceInfoTwo, result.getTarget().get(1).getSource());
     510
     511    }
     512//    /**
     513//     * Test of addTargetSources method, of class JdbcSourceDao. public
     514//     * Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo>
     515//     * addTargetSources(Number annotationID, List<NewOrExistingSourceInfo>
     516//     * sources)
     517//     */
     518//    @Test
     519//    public void testAddTargetSourcesOnExistingSource() {
     520//        System.out.println("addTargetSources : adding the old source");
     521//
     522//        NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();
     523//        SourceInfo si = new SourceInfo();
     524//        si.setLink(TestBackendConstants._TEST_SOURCE_1_LINK);
     525//        si.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID);
     526//        si.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);
     527//        noesi.setSource(si);
     528//
     529//        List<NewOrExistingSourceInfo> listnoesi = new ArrayList<NewOrExistingSourceInfo>();
     530//        listnoesi.add(noesi);
     531//
     532//        try {
     533//            Map<String, String> result = jdbcSourceDao.addTargetSources(5, listnoesi);
     534//            assertEquals(0, result.size()); // no new peristsent source IDs are produced
     535//        } catch (SQLException e) {
     536//            System.out.println(e);
     537//        }
     538//    }
     539//
     540//    /**
     541//     * Test of addTargetSources method, of class JdbcSourceDao. public
     542//     * Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo>
     543//     * addTargetSources(Number annotationID, List<NewOrExistingSourceInfo>
     544//     * sources)
     545//     */
     546//    @Test
     547//    public void testAddTargetSourcesOnNewSource() {
     548//        System.out.println("addTargetSources : adding the new source");
     549//
     550//        NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();
     551//        NewSourceInfo nsi = new NewSourceInfo();
     552//        nsi.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);
     553//        nsi.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID);
     554//        nsi.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);
     555//        noesi.setNewSource(nsi);
     556//
     557//        List<NewOrExistingSourceInfo> listnoesiTwo = new ArrayList<NewOrExistingSourceInfo>();
     558//        listnoesiTwo.add(noesi);
     559//       
     560//        mockery.checking(new Expectations() {
     561//            {
     562//                oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID));
     563//                will(returnValue(1));
     564//            }
     565//        });
     566//
     567//        try {
     568//            Map<String, String> result = jdbcSourceDao.addTargetSources(5, listnoesiTwo);
     569//            assertEquals(1, result.size());// a new identifier must be produced
     570//            SourceIdentifier sourceIdentifier = new SourceIdentifier(result.get(TestBackendConstants._TEST_TEMP_SOURCE_ID));
     571//            assertFalse(null == sourceIdentifier.getUUID()); // check if a proper uuid has been assigned
     572//        } catch (SQLException e) {
     573//            System.out.print(e);
     574//        }
     575//
     576//    }
     577//   
    311578}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java

    r3407 r3408  
    2323import eu.dasish.annotation.backend.dao.AnnotationDao;
    2424import eu.dasish.annotation.backend.dao.NotebookDao;
    25 import eu.dasish.annotation.backend.dao.PermissionsDao;
    2625import eu.dasish.annotation.backend.dao.SourceDao;
    2726import eu.dasish.annotation.backend.dao.UserDao;
     
    5251@ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml",
    5352    "/spring-test-config/mockSourceDao.xml",
    54     "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockery.xml"})
     53    "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockery.xml"})
    5554public class AnnotationResourceTest {
    5655   
     
    6160    @Autowired
    6261    private UserDao userDao;
    63     @Autowired
    64     private PermissionsDao permissionsDao;
    6562    @Autowired
    6663    private NotebookDao notebookDao; 
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java

    r3407 r3408  
    2323import eu.dasish.annotation.backend.dao.AnnotationDao;
    2424import eu.dasish.annotation.backend.dao.NotebookDao;
    25 import eu.dasish.annotation.backend.dao.PermissionsDao;
    2625import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
    2726import eu.dasish.annotation.backend.identifiers.UserIdentifier;
     
    4342   
    4443    private AnnotationDao annotationDao;
    45     private PermissionsDao permissionsDao;
    4644    private NotebookDao notebookDao;
    4745   
     
    4947        super(AnnotationResource.class.getPackage().getName());       
    5048        annotationDao = webAppContext.getBean(AnnotationDao.class);
    51         permissionsDao = webAppContext.getBean(PermissionsDao.class);
    5249        notebookDao = webAppContext.getBean(NotebookDao.class);
    5350    }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebookResourceTest.java

    r3380 r3408  
    1919
    2020import eu.dasish.annotation.backend.TestBackendConstants;
    21 import eu.dasish.annotation.backend.dao.AnnotationDao;
    2221import eu.dasish.annotation.backend.dao.NotebookDao;
    2322import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
     
    4847@RunWith(value = SpringJUnit4ClassRunner.class)
    4948@ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockUserDao.xml",
    50     "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockery.xml"})
     49    "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockery.xml"})
    5150public class NotebookResourceTest {
    5251
Note: See TracChangeset for help on using the changeset viewer.