Changeset 3218


Ignore:
Timestamp:
08/01/13 14:21:02 (11 years ago)
Author:
olhsha
Message:

handling permissions by adding and deleting an annotation: dao and REST. All is tested (annotation methods)

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
Files:
13 edited
1 moved

Legend:

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

    r3206 r3218  
    7474     * @return annotationIdentifier of the newly added annotation; returns null if something went wrong and annotation was not added or more than one row in the annotation table was affected
    7575     */
    76     public Annotation addAnnotation(Annotation annotation, Number ownerID);
     76    public Annotation addAnnotation(Annotation annotation, Number ownerID) throws SQLException;
    7777 
    7878    /**
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/NotebookDao.java

    r3189 r3218  
    8282     */
    8383    List<AnnotationIdentifier> getAnnotationExternalIDs(NotebookIdentifier notebookId);
     84   
     85    /**
     86     *
     87     * @param annotationID
     88     * @return removes the rows with annotationID from notebooks_annotations table
     89     */
     90    int removeAnnotation(Number annotationID);
    8491}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/PermissionsDao.java

    r3216 r3218  
    1818package eu.dasish.annotation.backend.dao;
    1919
     20import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
     21import eu.dasish.annotation.backend.identifiers.UserIdentifier;
     22import eu.dasish.annotation.schema.Permission;
    2023import eu.dasish.annotation.schema.UserWithPermission;
     24import java.sql.SQLException;
    2125import java.util.List;
    2226
     
    3438    public List<UserWithPermission>  retrievePermissions(Number annotationId);
    3539   
     40    /**
     41     *
     42     * @param annotationIdenitifier
     43     * @param userIdentifier
     44     * @param permission
     45     * @return the amount of rows added to the table annotations_principals_permissions
     46     */
     47    public int addAnnotationPrincipalPermission(AnnotationIdentifier annotationIdenitifier, UserIdentifier userIdentifier, Permission permission) throws SQLException;
     48   
     49    /**
     50     *
     51     * @param annotationID
     52     * @return remove all the rows with annotationID from the table annotations_principals_permissions
     53     */
     54    public int removeAnnotation(Number annotationID);
     55
    3656}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r3214 r3218  
    1919
    2020import eu.dasish.annotation.backend.dao.AnnotationDao;
     21import eu.dasish.annotation.backend.dao.NotebookDao;
     22import eu.dasish.annotation.backend.dao.PermissionsDao;
     23import eu.dasish.annotation.backend.dao.UserDao;
    2124import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
    2225import eu.dasish.annotation.schema.Annotation;
     
    3235import java.util.Map;
    3336import javax.sql.DataSource;
     37import org.springframework.beans.factory.annotation.Autowired;
    3438import org.springframework.dao.DataAccessException;
    3539import org.springframework.jdbc.core.RowMapper;
     
    4549
    4650public class JdbcAnnotationDao extends JdbcResourceDao implements AnnotationDao {
    47 
    48    
     51   
     52   @Autowired
     53   PermissionsDao jdbcPermissionsDao;
     54   
     55   @Autowired
     56   UserDao jdbcUserDao;
     57   
     58   @Autowired
     59   NotebookDao jdbcNotebookDao;
     60   
    4961    public JdbcAnnotationDao(DataSource dataSource) {
    5062        setDataSource(dataSource);
     
    126138    };
    127139 
     140    //////////////////////////////////////////////////////////////////////////
    128141   @Override
    129142    public Annotation getAnnotation(Number annotationID) throws SQLException{
     
    157170           result.setOwner(ownerREF);
    158171           
    159            /*TODO
    160             * Add permissions also to the database
    161             * ResourceREF permissionsREF = new ResourceREF();
    162            permissionsREF.setRef(String.valueOf(rs.getInt("permissions")));
    163            result.setPermissions(permissionsREF);*/
    164            
     172           
     173//           ResourceREF permissionsREF = new ResourceREF();
     174//           PermissionList permissionList = new PermissionList();
     175//           permissionsREF.setRef(permissionList.getURI());
     176//           result.setPermissions(permissionsREF);
     177//           
     178           //Permissions can be retrieved separately
    165179           
    166180           // TODO: add source, also to the database
    167            
    168            // TODO add external reference
    169181           
    170182           result.setBody(convertToAnnotationBody(rs.getString(body_xml)));
     
    217229     
    218230   @Override   
    219      public int deleteAnnotation(Number annotationId) throws SQLException{
    220         String sqlAnnotation = "DELETE FROM " + annotationTableName + " where "+annotation_id + " = ?";
    221         String sqlPermissions = "DELETE FROM " + permissionsTableName + " where "+annotation_id + " = ?";
     231     public int deleteAnnotation(Number annotationId) throws SQLException{         
     232             
    222233        String sqlNotebooks = "DELETE FROM " + notebooksAnnotationsTableName + " where "+annotation_id + " = ?";
    223234        int affectedNotebooks = getSimpleJdbcTemplate().update(sqlNotebooks, annotationId);
     235       
     236               
     237        String sqlPermissions = "DELETE FROM " + permissionsTableName + " where "+annotation_id + " = ?";       
    224238        int affectedPermissions = getSimpleJdbcTemplate().update(sqlPermissions, annotationId);
     239       
     240        String sqlAnnotation = "DELETE FROM " + annotationTableName + " where "+annotation_id + " = ?";
    225241        int affectedAnnotations = getSimpleJdbcTemplate().update(sqlAnnotation, annotationId);
    226242        if (affectedAnnotations>1) {
     
    236252   // Chnage it when the decision is taken!!!
    237253    @Override
    238     public Annotation addAnnotation(Annotation annotation, Number ownerID) {
     254    public Annotation addAnnotation(Annotation annotation, Number ownerID) throws SQLException{
    239255       
    240256        if (annotation == null) {
     
    249265            result.setOwner(ownerRef);
    250266           
     267            // generate a new annotation ID
    251268            AnnotationIdentifier annotationIdentifier = new AnnotationIdentifier();
    252269            result.setURI(annotationIdentifier.toString());
     
    261278            String sql = "INSERT INTO "+annotationTableName + "("+external_id+","+ time_stamp+"," + owner_id+","+headline+","+body_xml+" ) VALUES (:externalId, :timeStamp,  :ownerId, :headline, :bodyXml)";
    262279            final int affectedRows = getSimpleJdbcTemplate().update(sql, params);
     280           
    263281            if (affectedRows == 1) {
    264                 return result;
     282                 return result;
    265283            }
    266284            else {
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java

    r3189 r3218  
    287287        return annotationIds;
    288288    }
     289   
     290    ////////////////////////////////////////////////////////////
     291    @Override
     292    public int removeAnnotation(Number annotationID){       
     293        String sqlNotebooks = "DELETE FROM " + notebooksAnnotationsTableName + " where "+annotation_id + " = ?";
     294        int affectedNotebooks = getSimpleJdbcTemplate().update(sqlNotebooks, annotationID);
     295        return affectedNotebooks;
     296    }
    289297}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcPermissionsDao.java

    r3216 r3218  
    1818package eu.dasish.annotation.backend.dao.impl;
    1919
     20import eu.dasish.annotation.backend.dao.AnnotationDao;
    2021import eu.dasish.annotation.backend.dao.PermissionsDao;
    2122import eu.dasish.annotation.backend.dao.UserDao;
     23import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
     24import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    2225import eu.dasish.annotation.schema.Permission;
    2326import eu.dasish.annotation.schema.UserWithPermission;
    2427import java.sql.ResultSet;
    2528import java.sql.SQLException;
     29import java.util.HashMap;
    2630import java.util.List;
     31import java.util.Map;
    2732import javax.sql.DataSource;
    2833import org.springframework.beans.factory.annotation.Autowired;
     
    3742    @Autowired
    3843    private UserDao jdbcUserDao;
     44   
     45    @Autowired
     46    private AnnotationDao jdbcAnnotationDao;
    3947   
    4048   
     
    4351    }
    4452
     53    ///////////////////////////////////////////////////////////////////
    4554    @Override
    4655    public List<UserWithPermission> retrievePermissions(Number annotationId) {
     
    6271    };
    6372   
     73    /////////////////////////////////////////////////////////////////////////////////////////
     74    @Override
     75    public int addAnnotationPrincipalPermission(AnnotationIdentifier annotationIdenitifier, UserIdentifier userIdentifier, Permission permission) throws SQLException {
     76        Map<String, Object> paramsPermissions = new HashMap<String, Object>();
     77        paramsPermissions.put("annotationId", jdbcAnnotationDao.getAnnotationID(annotationIdenitifier));
     78        paramsPermissions.put("principalId", jdbcUserDao.getInternalID(userIdentifier));
     79        paramsPermissions.put("status", permission.value());
     80        String sqlUpdatePermissionTable = "INSERT INTO " + permissionsTableName + " (" + annotation_id + "," + principal_id + "," + permission + ") VALUES (:annotationId, :principalId, :status)";
     81        final int affectedPermissions = getSimpleJdbcTemplate().update(sqlUpdatePermissionTable, paramsPermissions);
     82        return affectedPermissions;
     83    }
     84   
     85    @Override
     86    public int removeAnnotation(Number annotationID){       
     87        String sqlPermissions = "DELETE FROM " + permissionsTableName + " where "+annotation_id + " = ?";       
     88        int affectedPermissions = getSimpleJdbcTemplate().update(sqlPermissions, annotationID);
     89        return affectedPermissions;
     90    }
     91   /////////////////////////////////////////////////////////////////////////////////
     92    //TODO replace name "user" in the scheme beacuse it is misleading. E.g. replace it with
     93    // getUser actual gives you the list of PAIRS (user, permission) that are refferred from an annotation
     94//   @Override
     95//   public PermissionList makeFreshPermissionList(UserIdentifier owner) {
     96//       PermissionList result = new PermissionList();
     97//       
     98//       result.setURI((new PermissionListIdentifier()).toString());
     99//       
     100//       UserWithPermission idOwner = new UserWithPermission();
     101//       idOwner.setPermission(Permission.fromValue("owner"));
     102//       idOwner.setRef(owner.toString());
     103//       
     104//       result.getUser().add(idOwner);
     105//       return result;
     106//   }
     107   
    64108}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java

    r3206 r3218  
    2020import eu.dasish.annotation.backend.BackendConstants;
    2121import eu.dasish.annotation.backend.dao.AnnotationDao;
     22import eu.dasish.annotation.backend.dao.NotebookDao;
     23import eu.dasish.annotation.backend.dao.PermissionsDao;
    2224import eu.dasish.annotation.backend.dao.UserDao;
    2325import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
     
    2527import eu.dasish.annotation.schema.Annotation;
    2628import eu.dasish.annotation.schema.ObjectFactory;
     29import eu.dasish.annotation.schema.Permission;
    2730import java.sql.SQLException;
    28 import javax.servlet.ServletContext;
    2931import javax.servlet.http.HttpServletRequest;
    3032import javax.ws.rs.Consumes;
     
    4850@Path("/annotations")
    4951public class AnnotationResource {
    50    
     52
    5153    @Autowired
    5254    private AnnotationDao annotationDao;
    5355    @Autowired
    5456    private UserDao userDao;
    55    
     57    @Autowired
     58    private PermissionsDao permissionsDao;
     59    @Autowired
     60    private NotebookDao notebookDao;
    5661    //for Peter, see also http://stackoverflow.com/questions/6140697/jersey-the-context-annotation-for-injection-how-does-it-work
    5762    @Context
    5863    private HttpServletRequest httpServletRequest;
    59    
    60     @Context
    61     private ServletContext servletContext;
    62    
    63    
    64     public void setHttpRequest(HttpServletRequest request){
    65        this.httpServletRequest =  request;
     64
     65    public void setHttpRequest(HttpServletRequest request) {
     66        this.httpServletRequest = request;
    6667    }
    67    
    68     public AnnotationResource(){
     68
     69    public AnnotationResource() {
    6970    }
    70    
     71
    7172    /*public AnnotationResource(@Context HttpServletRequest request){
    72         this.httpServletRequest =  request;
    73     }*/
    74            
    75            
     73     this.httpServletRequest =  request;
     74     }*/
    7675    @GET
    7776    @Produces(MediaType.TEXT_XML)
    78     @Path("{annotationid: "+BackendConstants.regExpIdentifier+"}")
    79     public JAXBElement<Annotation> getAnnotation(@PathParam("annotationid") String annotationIdentifier) throws SQLException{
     77    @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}")
     78    public JAXBElement<Annotation> getAnnotation(@PathParam("annotationid") String annotationIdentifier) throws SQLException {
    8079        final Annotation annotation = annotationDao.getAnnotation(annotationDao.getAnnotationID(new AnnotationIdentifier(annotationIdentifier)));
    8180        return new ObjectFactory().createAnnotation(annotation);
    8281    }
    83    
     82
    8483    @DELETE
    85     @Path("{annotationid: "+BackendConstants.regExpIdentifier+"}")
     84    @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}")
    8685    /*
    8786     Delete _aid_. The related sources that are not related to other annotations must be deleted as well (TODO)
    8887     */
    89     public String deleteAnnotation(@PathParam("annotationid") String annotationIdentifier) throws SQLException{
    90         return Integer.toString(annotationDao.deleteAnnotation(annotationDao.getAnnotationID(new AnnotationIdentifier(annotationIdentifier))));
     88    public String deleteAnnotation(@PathParam("annotationid") String annotationIdentifier) throws SQLException {
     89        Number annotationID = annotationDao.getAnnotationID(new AnnotationIdentifier(annotationIdentifier));       
     90        String result = Integer.toString(annotationDao.deleteAnnotation(annotationID));
     91        return result;
    9192    }
    92    
     93
    9394    // TODO: should be returning the envelope!!!
    94     @POST   
     95    @POST
    9596    @Consumes(MediaType.APPLICATION_XML)
    9697    @Produces(MediaType.APPLICATION_XML)
    9798    @Path("")
    98     public JAXBElement<Annotation> createAnnotation(Annotation annotation) {
    99        
     99    public JAXBElement<Annotation> createAnnotation(Annotation annotation) throws SQLException {
     100
    100101        String remoteUser = httpServletRequest.getRemoteUser();
    101102        Number userID;
    102        
     103
    103104        if (remoteUser == null) {
    104105            // happens in client testing
     106            // TODO sould be adjusted when the user handling mechanism is settled
    105107            userID = null;
     108        } else {
     109            userID = userDao.getInternalID(new UserIdentifier(remoteUser));
    106110        }
    107         else {
    108            userID= userDao.getInternalID(new UserIdentifier(remoteUser));
    109         }
    110        
     111
    111112        Annotation newAnnotation = annotationDao.addAnnotation(annotation, userID);
    112113        if (newAnnotation == null) {
    113114            return null;
    114115        } else {
     116            int affectedPermissions = permissionsDao.addAnnotationPrincipalPermission(new AnnotationIdentifier(newAnnotation.getURI()), new UserIdentifier(remoteUser), Permission.OWNER);
    115117            return (new ObjectFactory().createAnnotation(newAnnotation));
    116118        }
    117119    }
    118    
    119    
    120    
    121120}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java

    r3211 r3218  
    2020import eu.dasish.annotation.backend.TestBackendConstants;
    2121import eu.dasish.annotation.backend.TestInstances;
     22import eu.dasish.annotation.backend.dao.NotebookDao;
     23import eu.dasish.annotation.backend.dao.PermissionsDao;
    2224import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
    2325import eu.dasish.annotation.schema.Annotation;
     
    2729import java.util.ArrayList;
    2830import java.util.List;
     31import org.jmock.Expectations;
     32import org.jmock.Mockery;
    2933import static org.junit.Assert.*;
    3034import org.junit.Test;
     
    3943 */
    4044@RunWith(SpringJUnit4ClassRunner.class)
    41 @ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-config/annotationDao.xml"})
    42 
     45@ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-test-config/mockery.xml", "/spring-test-config/mockNotebookDao.xml",  "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-config/annotationDao.xml"})
    4346public class JdbcAnnotationDaoTest extends JdbcResourceDaoTest{
    4447   
    4548    @Autowired
    4649    JdbcAnnotationDao jdbcAnnotationDao;
     50   
     51    @Autowired
     52    private PermissionsDao permissionsDao;
     53   
     54    @Autowired
     55    private NotebookDao notebookDao;
     56   
     57    @Autowired
     58    private Mockery mockery;
    4759   
    4860    TestInstances testInstances = new TestInstances();
     
    155167    @Test
    156168    public void testDeleteAnnotation() throws SQLException{
    157         System.out.println("deleteAnnotation");       
     169        System.out.println("deleteAnnotation");
     170       
     171         mockery.checking(new Expectations() {
     172            {
     173                oneOf(permissionsDao).removeAnnotation(5);
     174                will(returnValue(1));
     175               
     176                oneOf(notebookDao).removeAnnotation(5);
     177                will(returnValue(3));
     178            }
     179        });
     180       
    158181        int result = jdbcAnnotationDao.deleteAnnotation(5);
    159182        assertEquals(1, result);
     
    171194    public void testAddAnnotation() throws SQLException{
    172195        System.out.println("test_addAnnotation");
    173         Annotation annotationToAdd = testInstances.getAnnotationToAdd();
     196        final Annotation annotationToAdd = testInstances.getAnnotationToAdd();
     197       
     198       
    174199        Annotation result = jdbcAnnotationDao.addAnnotation(annotationToAdd, 5);
    175         assertFalse(result == null);
    176200       
    177201        AnnotationIdentifier generatedAnnotationExternalID  = new AnnotationIdentifier(result.getURI());
    178        
    179202        Annotation addedAnnotation = jdbcAnnotationDao.getAnnotation(jdbcAnnotationDao.getAnnotationID(generatedAnnotationExternalID));       
    180203        assertEquals(annotationToAdd.getBody().getAny().get(0), addedAnnotation.getBody().getAny().get(0));
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDaoTest.java

    r3215 r3218  
    4949 */
    5050@RunWith(SpringJUnit4ClassRunner.class)
    51 @ContextConfiguration({"/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockUserDao.xml",
     51@ContextConfiguration({"/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml",
    5252    "/spring-test-config/dataSource.xml", "/spring-config/notebookDao.xml"})
    5353public class JdbcNotebookDaoTest extends JdbcResourceDaoTest{
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcPermissionsDaoTest.java

    r3216 r3218  
    4040@RunWith(SpringJUnit4ClassRunner.class)
    4141@ContextConfiguration({"/spring-test-config/mockery.xml", "/spring-test-config/dataSource.xml", "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-config/permissionsDao.xml"})
    42 public class PermissionsDaoTest extends JdbcResourceDaoTest{
     42public class JdbcPermissionsDaoTest extends JdbcResourceDaoTest{
    4343   
    4444    @Autowired
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDaoTest.java

    r3211 r3218  
    3838   
    3939    @Autowired
    40     private JdbcUserDao jdbcUserDao;
     40    JdbcUserDao jdbcUserDao;
    4141    TestInstances testInstances = new TestInstances();
    4242
     
    5656        assertEquals(null, testThree);
    5757    }
     58   
     59   
     60    /**
     61     * public UserIdentifier getExternalID(Number internalId)
     62     */
     63    @Test
     64    public void testGetExternalID() {
     65        UserIdentifier testOne = jdbcUserDao.getExternalID(3);
     66        assertEquals(TestBackendConstants._TEST_USER_3_EXT_ID, testOne.toString());
     67       
     68        UserIdentifier testTwo = jdbcUserDao.getExternalID(null);
     69        assertEquals(null, testTwo);
     70    }
     71   
     72   
    5873}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java

    r3211 r3218  
    2222import eu.dasish.annotation.backend.TestInstances;
    2323import eu.dasish.annotation.backend.dao.AnnotationDao;
     24import eu.dasish.annotation.backend.dao.NotebookDao;
     25import eu.dasish.annotation.backend.dao.PermissionsDao;
    2426import eu.dasish.annotation.backend.dao.UserDao;
    2527import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
    2628import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    2729import eu.dasish.annotation.schema.Annotation;
     30import eu.dasish.annotation.schema.Permission;
    2831import eu.dasish.annotation.schema.ResourceREF;
    2932import java.sql.SQLException;
     
    4043import javax.servlet.ServletException;
    4144import org.springframework.mock.web.MockHttpServletRequest;
    42 import org.springframework.web.context.ContextLoaderListener;
    43 import org.springframework.web.context.WebApplicationContext;
    4445/**
    4546 *
     
    4849
    4950@RunWith(value = SpringJUnit4ClassRunner.class)
    50 @ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockery.xml"})
     51@ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockery.xml"})
    5152public class AnnotationResourceTest {
    5253   
     
    5758    @Autowired
    5859    private UserDao userDao;
     60    @Autowired
     61    private PermissionsDao permissionsDao;
     62    @Autowired
     63    private NotebookDao notebookDao;
    5964   
    6065    @Autowired
     
    7883            {
    7984                oneOf(annotationDao).getAnnotationID(new AnnotationIdentifier(annotationIdentifier));               
    80                 will(returnValue(annotationID));
     85                will(returnValue(annotationID));               
    8186               
    8287                oneOf(annotationDao).getAnnotation(annotationID);               
     
    95100    public void testDeleteAnnotation() throws SQLException {
    96101        System.out.println("deleteAnnotation");
     102       
    97103        mockery.checking(new Expectations() {
    98104            {
    99105                oneOf(annotationDao).getAnnotationID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT));               
    100                 will(returnValue(5));
     106                will(returnValue(5));     
    101107               
    102108                oneOf(annotationDao).deleteAnnotation(5);
     
    133139       
    134140        final Annotation addedAnnotation = annotationToAdd;
    135         AnnotationIdentifier annotationIdentifier = new GenericType<AnnotationIdentifier>(){}.getRawClass().newInstance();
     141        final AnnotationIdentifier annotationIdentifier = new GenericType<AnnotationIdentifier>(){}.getRawClass().newInstance();
    136142        addedAnnotation.setURI(annotationIdentifier.toString());
    137143        ResourceREF ownerRef = new ResourceREF();
     
    139145        addedAnnotation.setOwner(ownerRef);
    140146       
    141      
     147        final UserIdentifier owner = new UserIdentifier(TestBackendConstants._TEST_USER_5_EXT_ID);
     148       
    142149        mockery.checking(new Expectations() {
    143150            {
    144                 oneOf(userDao).getInternalID(new UserIdentifier(TestBackendConstants._TEST_USER_5_EXT_ID));
     151                oneOf(userDao).getInternalID(owner);
    145152                will(returnValue(5));
    146153               
    147154                oneOf(annotationDao).addAnnotation(annotationToAdd, 5);
    148155                will(returnValue(addedAnnotation));
     156           
     157                oneOf(permissionsDao).addAnnotationPrincipalPermission(annotationIdentifier, owner, Permission.OWNER);
     158                will(returnValue(1));
    149159            }
    150160        });
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java

    r3211 r3218  
    2222import eu.dasish.annotation.backend.TestBackendConstants;
    2323import eu.dasish.annotation.backend.dao.AnnotationDao;
    24 import eu.dasish.annotation.backend.dao.UserDao;
     24import eu.dasish.annotation.backend.dao.NotebookDao;
     25import eu.dasish.annotation.backend.dao.PermissionsDao;
    2526import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
    2627import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    2728import eu.dasish.annotation.schema.Annotation;
    2829import eu.dasish.annotation.schema.ObjectFactory;
    29 import eu.dasish.annotation.schema.ResourceREF;
     30import eu.dasish.annotation.schema.Permission;
    3031import java.sql.SQLException;
    31 import javax.servlet.http.HttpServletRequest;
    3232import javax.ws.rs.core.MediaType;
    3333import javax.xml.bind.JAXBElement;
     
    4343   
    4444    private AnnotationDao annotationDao;
    45     private UserDao userDao;
     45    private PermissionsDao permissionsDao;
     46    private NotebookDao notebookDao;
    4647   
    4748    public AnnotationsTest() {
    48         super(AnnotationResource.class.getPackage().getName());
     49        super(AnnotationResource.class.getPackage().getName());       
    4950        annotationDao = webAppContext.getBean(AnnotationDao.class);
    50         userDao = webAppContext.getBean(UserDao.class);
     51        permissionsDao = webAppContext.getBean(PermissionsDao.class);
     52        notebookDao = webAppContext.getBean(NotebookDao.class);
    5153    }
    5254   
     
    143145       
    144146        final Annotation addedAnnotation = annotationToAdd;
    145         AnnotationIdentifier annotationIdentifier = new GenericType<AnnotationIdentifier>(){}.getRawClass().newInstance();
     147        final AnnotationIdentifier annotationIdentifier = new GenericType<AnnotationIdentifier>(){}.getRawClass().newInstance();
    146148        addedAnnotation.setURI(annotationIdentifier.toString());
    147        
     149        final UserIdentifier owner = new UserIdentifier(TestBackendConstants._TEST_USER_5_EXT_ID);
    148150        mockery.checking(new Expectations() {
    149151            {   
    150                 oneOf(annotationDao).addAnnotation(with(any(Annotation.class)), with(any(Number.class)));
     152               
     153            // TODO sould be mpre strict demands on  inputs  when the user handling mechanism is settled
     154                oneOf(annotationDao).addAnnotation(with(aNonNull(Annotation.class)), with(any(Number.class)));
    151155                will(returnValue(addedAnnotation));
     156               
     157                oneOf(permissionsDao).addAnnotationPrincipalPermission(with(aNonNull(AnnotationIdentifier.class)), with(aNonNull(UserIdentifier.class)), with(aNonNull(Permission.class)));
     158                will(returnValue(1));
    152159            }
    153160        });
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebookResourceTest.java

    r3211 r3218  
    4747 */
    4848@RunWith(value = SpringJUnit4ClassRunner.class)
    49 @ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockery.xml"})
     49@ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockery.xml"})
    5050public class NotebookResourceTest {
    5151
Note: See TracChangeset for help on using the changeset viewer.