Changeset 3218
- Timestamp:
- 08/01/13 14:21:02 (11 years ago)
- 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 74 74 * @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 75 75 */ 76 public Annotation addAnnotation(Annotation annotation, Number ownerID) ;76 public Annotation addAnnotation(Annotation annotation, Number ownerID) throws SQLException; 77 77 78 78 /** -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/NotebookDao.java
r3189 r3218 82 82 */ 83 83 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); 84 91 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/PermissionsDao.java
r3216 r3218 18 18 package eu.dasish.annotation.backend.dao; 19 19 20 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 21 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 22 import eu.dasish.annotation.schema.Permission; 20 23 import eu.dasish.annotation.schema.UserWithPermission; 24 import java.sql.SQLException; 21 25 import java.util.List; 22 26 … … 34 38 public List<UserWithPermission> retrievePermissions(Number annotationId); 35 39 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 36 56 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r3214 r3218 19 19 20 20 import eu.dasish.annotation.backend.dao.AnnotationDao; 21 import eu.dasish.annotation.backend.dao.NotebookDao; 22 import eu.dasish.annotation.backend.dao.PermissionsDao; 23 import eu.dasish.annotation.backend.dao.UserDao; 21 24 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 22 25 import eu.dasish.annotation.schema.Annotation; … … 32 35 import java.util.Map; 33 36 import javax.sql.DataSource; 37 import org.springframework.beans.factory.annotation.Autowired; 34 38 import org.springframework.dao.DataAccessException; 35 39 import org.springframework.jdbc.core.RowMapper; … … 45 49 46 50 public 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 49 61 public JdbcAnnotationDao(DataSource dataSource) { 50 62 setDataSource(dataSource); … … 126 138 }; 127 139 140 ////////////////////////////////////////////////////////////////////////// 128 141 @Override 129 142 public Annotation getAnnotation(Number annotationID) throws SQLException{ … … 157 170 result.setOwner(ownerREF); 158 171 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 165 179 166 180 // TODO: add source, also to the database 167 168 // TODO add external reference169 181 170 182 result.setBody(convertToAnnotationBody(rs.getString(body_xml))); … … 217 229 218 230 @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 222 233 String sqlNotebooks = "DELETE FROM " + notebooksAnnotationsTableName + " where "+annotation_id + " = ?"; 223 234 int affectedNotebooks = getSimpleJdbcTemplate().update(sqlNotebooks, annotationId); 235 236 237 String sqlPermissions = "DELETE FROM " + permissionsTableName + " where "+annotation_id + " = ?"; 224 238 int affectedPermissions = getSimpleJdbcTemplate().update(sqlPermissions, annotationId); 239 240 String sqlAnnotation = "DELETE FROM " + annotationTableName + " where "+annotation_id + " = ?"; 225 241 int affectedAnnotations = getSimpleJdbcTemplate().update(sqlAnnotation, annotationId); 226 242 if (affectedAnnotations>1) { … … 236 252 // Chnage it when the decision is taken!!! 237 253 @Override 238 public Annotation addAnnotation(Annotation annotation, Number ownerID) {254 public Annotation addAnnotation(Annotation annotation, Number ownerID) throws SQLException{ 239 255 240 256 if (annotation == null) { … … 249 265 result.setOwner(ownerRef); 250 266 267 // generate a new annotation ID 251 268 AnnotationIdentifier annotationIdentifier = new AnnotationIdentifier(); 252 269 result.setURI(annotationIdentifier.toString()); … … 261 278 String sql = "INSERT INTO "+annotationTableName + "("+external_id+","+ time_stamp+"," + owner_id+","+headline+","+body_xml+" ) VALUES (:externalId, :timeStamp, :ownerId, :headline, :bodyXml)"; 262 279 final int affectedRows = getSimpleJdbcTemplate().update(sql, params); 280 263 281 if (affectedRows == 1) { 264 return result;282 return result; 265 283 } 266 284 else { -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java
r3189 r3218 287 287 return annotationIds; 288 288 } 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 } 289 297 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcPermissionsDao.java
r3216 r3218 18 18 package eu.dasish.annotation.backend.dao.impl; 19 19 20 import eu.dasish.annotation.backend.dao.AnnotationDao; 20 21 import eu.dasish.annotation.backend.dao.PermissionsDao; 21 22 import eu.dasish.annotation.backend.dao.UserDao; 23 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 24 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 22 25 import eu.dasish.annotation.schema.Permission; 23 26 import eu.dasish.annotation.schema.UserWithPermission; 24 27 import java.sql.ResultSet; 25 28 import java.sql.SQLException; 29 import java.util.HashMap; 26 30 import java.util.List; 31 import java.util.Map; 27 32 import javax.sql.DataSource; 28 33 import org.springframework.beans.factory.annotation.Autowired; … … 37 42 @Autowired 38 43 private UserDao jdbcUserDao; 44 45 @Autowired 46 private AnnotationDao jdbcAnnotationDao; 39 47 40 48 … … 43 51 } 44 52 53 /////////////////////////////////////////////////////////////////// 45 54 @Override 46 55 public List<UserWithPermission> retrievePermissions(Number annotationId) { … … 62 71 }; 63 72 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 64 108 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r3206 r3218 20 20 import eu.dasish.annotation.backend.BackendConstants; 21 21 import eu.dasish.annotation.backend.dao.AnnotationDao; 22 import eu.dasish.annotation.backend.dao.NotebookDao; 23 import eu.dasish.annotation.backend.dao.PermissionsDao; 22 24 import eu.dasish.annotation.backend.dao.UserDao; 23 25 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; … … 25 27 import eu.dasish.annotation.schema.Annotation; 26 28 import eu.dasish.annotation.schema.ObjectFactory; 29 import eu.dasish.annotation.schema.Permission; 27 30 import java.sql.SQLException; 28 import javax.servlet.ServletContext;29 31 import javax.servlet.http.HttpServletRequest; 30 32 import javax.ws.rs.Consumes; … … 48 50 @Path("/annotations") 49 51 public class AnnotationResource { 50 52 51 53 @Autowired 52 54 private AnnotationDao annotationDao; 53 55 @Autowired 54 56 private UserDao userDao; 55 57 @Autowired 58 private PermissionsDao permissionsDao; 59 @Autowired 60 private NotebookDao notebookDao; 56 61 //for Peter, see also http://stackoverflow.com/questions/6140697/jersey-the-context-annotation-for-injection-how-does-it-work 57 62 @Context 58 63 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; 66 67 } 67 68 public AnnotationResource() {68 69 public AnnotationResource() { 69 70 } 70 71 71 72 /*public AnnotationResource(@Context HttpServletRequest request){ 72 this.httpServletRequest = request; 73 }*/ 74 75 73 this.httpServletRequest = request; 74 }*/ 76 75 @GET 77 76 @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 { 80 79 final Annotation annotation = annotationDao.getAnnotation(annotationDao.getAnnotationID(new AnnotationIdentifier(annotationIdentifier))); 81 80 return new ObjectFactory().createAnnotation(annotation); 82 81 } 83 82 84 83 @DELETE 85 @Path("{annotationid: " +BackendConstants.regExpIdentifier+"}")84 @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}") 86 85 /* 87 86 Delete _aid_. The related sources that are not related to other annotations must be deleted as well (TODO) 88 87 */ 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; 91 92 } 92 93 93 94 // TODO: should be returning the envelope!!! 94 @POST 95 @POST 95 96 @Consumes(MediaType.APPLICATION_XML) 96 97 @Produces(MediaType.APPLICATION_XML) 97 98 @Path("") 98 public JAXBElement<Annotation> createAnnotation(Annotation annotation) {99 99 public JAXBElement<Annotation> createAnnotation(Annotation annotation) throws SQLException { 100 100 101 String remoteUser = httpServletRequest.getRemoteUser(); 101 102 Number userID; 102 103 103 104 if (remoteUser == null) { 104 105 // happens in client testing 106 // TODO sould be adjusted when the user handling mechanism is settled 105 107 userID = null; 108 } else { 109 userID = userDao.getInternalID(new UserIdentifier(remoteUser)); 106 110 } 107 else { 108 userID= userDao.getInternalID(new UserIdentifier(remoteUser)); 109 } 110 111 111 112 Annotation newAnnotation = annotationDao.addAnnotation(annotation, userID); 112 113 if (newAnnotation == null) { 113 114 return null; 114 115 } else { 116 int affectedPermissions = permissionsDao.addAnnotationPrincipalPermission(new AnnotationIdentifier(newAnnotation.getURI()), new UserIdentifier(remoteUser), Permission.OWNER); 115 117 return (new ObjectFactory().createAnnotation(newAnnotation)); 116 118 } 117 119 } 118 119 120 121 120 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r3211 r3218 20 20 import eu.dasish.annotation.backend.TestBackendConstants; 21 21 import eu.dasish.annotation.backend.TestInstances; 22 import eu.dasish.annotation.backend.dao.NotebookDao; 23 import eu.dasish.annotation.backend.dao.PermissionsDao; 22 24 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 23 25 import eu.dasish.annotation.schema.Annotation; … … 27 29 import java.util.ArrayList; 28 30 import java.util.List; 31 import org.jmock.Expectations; 32 import org.jmock.Mockery; 29 33 import static org.junit.Assert.*; 30 34 import org.junit.Test; … … 39 43 */ 40 44 @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"}) 43 46 public class JdbcAnnotationDaoTest extends JdbcResourceDaoTest{ 44 47 45 48 @Autowired 46 49 JdbcAnnotationDao jdbcAnnotationDao; 50 51 @Autowired 52 private PermissionsDao permissionsDao; 53 54 @Autowired 55 private NotebookDao notebookDao; 56 57 @Autowired 58 private Mockery mockery; 47 59 48 60 TestInstances testInstances = new TestInstances(); … … 155 167 @Test 156 168 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 158 181 int result = jdbcAnnotationDao.deleteAnnotation(5); 159 182 assertEquals(1, result); … … 171 194 public void testAddAnnotation() throws SQLException{ 172 195 System.out.println("test_addAnnotation"); 173 Annotation annotationToAdd = testInstances.getAnnotationToAdd(); 196 final Annotation annotationToAdd = testInstances.getAnnotationToAdd(); 197 198 174 199 Annotation result = jdbcAnnotationDao.addAnnotation(annotationToAdd, 5); 175 assertFalse(result == null);176 200 177 201 AnnotationIdentifier generatedAnnotationExternalID = new AnnotationIdentifier(result.getURI()); 178 179 202 Annotation addedAnnotation = jdbcAnnotationDao.getAnnotation(jdbcAnnotationDao.getAnnotationID(generatedAnnotationExternalID)); 180 203 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 49 49 */ 50 50 @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", 52 52 "/spring-test-config/dataSource.xml", "/spring-config/notebookDao.xml"}) 53 53 public 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 40 40 @RunWith(SpringJUnit4ClassRunner.class) 41 41 @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{42 public class JdbcPermissionsDaoTest extends JdbcResourceDaoTest{ 43 43 44 44 @Autowired -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDaoTest.java
r3211 r3218 38 38 39 39 @Autowired 40 privateJdbcUserDao jdbcUserDao;40 JdbcUserDao jdbcUserDao; 41 41 TestInstances testInstances = new TestInstances(); 42 42 … … 56 56 assertEquals(null, testThree); 57 57 } 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 58 73 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java
r3211 r3218 22 22 import eu.dasish.annotation.backend.TestInstances; 23 23 import eu.dasish.annotation.backend.dao.AnnotationDao; 24 import eu.dasish.annotation.backend.dao.NotebookDao; 25 import eu.dasish.annotation.backend.dao.PermissionsDao; 24 26 import eu.dasish.annotation.backend.dao.UserDao; 25 27 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 26 28 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 27 29 import eu.dasish.annotation.schema.Annotation; 30 import eu.dasish.annotation.schema.Permission; 28 31 import eu.dasish.annotation.schema.ResourceREF; 29 32 import java.sql.SQLException; … … 40 43 import javax.servlet.ServletException; 41 44 import org.springframework.mock.web.MockHttpServletRequest; 42 import org.springframework.web.context.ContextLoaderListener;43 import org.springframework.web.context.WebApplicationContext;44 45 /** 45 46 * … … 48 49 49 50 @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/mock NotebookDao.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"}) 51 52 public class AnnotationResourceTest { 52 53 … … 57 58 @Autowired 58 59 private UserDao userDao; 60 @Autowired 61 private PermissionsDao permissionsDao; 62 @Autowired 63 private NotebookDao notebookDao; 59 64 60 65 @Autowired … … 78 83 { 79 84 oneOf(annotationDao).getAnnotationID(new AnnotationIdentifier(annotationIdentifier)); 80 will(returnValue(annotationID)); 85 will(returnValue(annotationID)); 81 86 82 87 oneOf(annotationDao).getAnnotation(annotationID); … … 95 100 public void testDeleteAnnotation() throws SQLException { 96 101 System.out.println("deleteAnnotation"); 102 97 103 mockery.checking(new Expectations() { 98 104 { 99 105 oneOf(annotationDao).getAnnotationID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT)); 100 will(returnValue(5)); 106 will(returnValue(5)); 101 107 102 108 oneOf(annotationDao).deleteAnnotation(5); … … 133 139 134 140 final Annotation addedAnnotation = annotationToAdd; 135 AnnotationIdentifier annotationIdentifier = new GenericType<AnnotationIdentifier>(){}.getRawClass().newInstance();141 final AnnotationIdentifier annotationIdentifier = new GenericType<AnnotationIdentifier>(){}.getRawClass().newInstance(); 136 142 addedAnnotation.setURI(annotationIdentifier.toString()); 137 143 ResourceREF ownerRef = new ResourceREF(); … … 139 145 addedAnnotation.setOwner(ownerRef); 140 146 141 147 final UserIdentifier owner = new UserIdentifier(TestBackendConstants._TEST_USER_5_EXT_ID); 148 142 149 mockery.checking(new Expectations() { 143 150 { 144 oneOf(userDao).getInternalID( new UserIdentifier(TestBackendConstants._TEST_USER_5_EXT_ID));151 oneOf(userDao).getInternalID(owner); 145 152 will(returnValue(5)); 146 153 147 154 oneOf(annotationDao).addAnnotation(annotationToAdd, 5); 148 155 will(returnValue(addedAnnotation)); 156 157 oneOf(permissionsDao).addAnnotationPrincipalPermission(annotationIdentifier, owner, Permission.OWNER); 158 will(returnValue(1)); 149 159 } 150 160 }); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java
r3211 r3218 22 22 import eu.dasish.annotation.backend.TestBackendConstants; 23 23 import eu.dasish.annotation.backend.dao.AnnotationDao; 24 import eu.dasish.annotation.backend.dao.UserDao; 24 import eu.dasish.annotation.backend.dao.NotebookDao; 25 import eu.dasish.annotation.backend.dao.PermissionsDao; 25 26 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 26 27 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 27 28 import eu.dasish.annotation.schema.Annotation; 28 29 import eu.dasish.annotation.schema.ObjectFactory; 29 import eu.dasish.annotation.schema. ResourceREF;30 import eu.dasish.annotation.schema.Permission; 30 31 import java.sql.SQLException; 31 import javax.servlet.http.HttpServletRequest;32 32 import javax.ws.rs.core.MediaType; 33 33 import javax.xml.bind.JAXBElement; … … 43 43 44 44 private AnnotationDao annotationDao; 45 private UserDao userDao; 45 private PermissionsDao permissionsDao; 46 private NotebookDao notebookDao; 46 47 47 48 public AnnotationsTest() { 48 super(AnnotationResource.class.getPackage().getName()); 49 super(AnnotationResource.class.getPackage().getName()); 49 50 annotationDao = webAppContext.getBean(AnnotationDao.class); 50 userDao = webAppContext.getBean(UserDao.class); 51 permissionsDao = webAppContext.getBean(PermissionsDao.class); 52 notebookDao = webAppContext.getBean(NotebookDao.class); 51 53 } 52 54 … … 143 145 144 146 final Annotation addedAnnotation = annotationToAdd; 145 AnnotationIdentifier annotationIdentifier = new GenericType<AnnotationIdentifier>(){}.getRawClass().newInstance();147 final AnnotationIdentifier annotationIdentifier = new GenericType<AnnotationIdentifier>(){}.getRawClass().newInstance(); 146 148 addedAnnotation.setURI(annotationIdentifier.toString()); 147 149 final UserIdentifier owner = new UserIdentifier(TestBackendConstants._TEST_USER_5_EXT_ID); 148 150 mockery.checking(new Expectations() { 149 151 { 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))); 151 155 will(returnValue(addedAnnotation)); 156 157 oneOf(permissionsDao).addAnnotationPrincipalPermission(with(aNonNull(AnnotationIdentifier.class)), with(aNonNull(UserIdentifier.class)), with(aNonNull(Permission.class))); 158 will(returnValue(1)); 152 159 } 153 160 }); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebookResourceTest.java
r3211 r3218 47 47 */ 48 48 @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/mock ery.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"}) 50 50 public class NotebookResourceTest { 51 51
Note: See TracChangeset
for help on using the changeset viewer.