Changeset 4173
- Timestamp:
- 12/10/13 15:18:42 (10 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend
- Files:
-
- 13 added
- 2 deleted
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/nb-configuration.xml
r4013 r4173 21 21 <config-file>src/main/resources/spring-config/applicationContext-security.xml</config-file> 22 22 <config-file>src/main/resources/spring-config/securityDataSource.xml</config-file> 23 <config-file>src/test/resources/spring-test-config/jaxbMarshallerFactory.xml</config-file> 24 <config-file>src/test/resources/spring-integrity-test-config/dataSource.xml</config-file> 25 <config-file>src/test/resources/spring-integrity-test-config/annotationDao.xml</config-file> 26 <config-file>src/test/resources/spring-integrity-test-config/userDao.xml</config-file> 27 <config-file>src/test/resources/spring-integrity-test-config/targetDao.xml</config-file> 28 <config-file>src/test/resources/spring-integrity-test-config/cachedRepresentationDao.xml</config-file> 29 <config-file>src/test/resources/spring-integrity-test-config/componentscan.xml</config-file> 30 <config-file>src/test/resources/spring-integrity-test-config/dbIntegrityService.xml</config-file> 31 <config-file>src/test/resources/spring-integrity-test-config/JaxbMarshallerFactory.xml</config-file> 23 32 </config-files> 24 33 <config-file-groups/> -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/pom.xml
r4070 r4173 243 243 <version>${slf4j.version}</version> 244 244 </dependency> 245 246 <groupId> joda-time</groupId>247 <artifactId>j oda-time</artifactId>248 <version>2. 1</version>245 <dependency> 246 <groupId>org.glassfish.jersey.core</groupId> 247 <artifactId>jersey-server</artifactId> 248 <version>2.3.1</version> 249 249 </dependency> 250 250 </dependencies> -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/Helpers.java
r4146 r4173 19 19 20 20 import java.io.IOException; 21 import java.sql.Timestamp;22 import java.util.GregorianCalendar;23 21 import java.util.Map; 24 import java.util.TimeZone;25 import javax.xml.datatype.DatatypeConfigurationException;26 import javax.xml.datatype.DatatypeFactory;27 import javax.xml.datatype.XMLGregorianCalendar;28 22 import javax.xml.parsers.DocumentBuilder; 29 23 import javax.xml.parsers.DocumentBuilderFactory; … … 34 28 import org.w3c.dom.ls.LSSerializer; 35 29 import org.xml.sax.SAXException; 36 import org.joda.time.DateTime;37 import org.joda.time.DateTimeZone;38 30 39 31 /** -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r4146 r4173 316 316 StringBuilder sql = new StringBuilder("UPDATE "); 317 317 sql.append(annotationTableName).append(" SET "). 318 append(last_modified).append("= current_timestamp AT TIME ZONE INTERVAL '00:00' ,").318 append(last_modified).append("= current_timestamp AT TIME ZONE INTERVAL '00:00' HOUR TO MINUTE,"). 319 319 append(body_text).append("= '").append(text). 320 320 append("' WHERE ").append(annotation_id).append("= ?"); … … 334 334 StringBuilder sql = new StringBuilder("UPDATE "); 335 335 sql.append(annotationTableName).append(" SET "). 336 append(last_modified).append("= current_timestamp AT TIME ZONE 'UTC' ,").336 append(last_modified).append("= current_timestamp AT TIME ZONE 'UTC' HOUR TO MINUTE,"). 337 337 append(body_text).append("= :bodyText, "). 338 338 append(body_mimetype).append("= :bodyMimeType, "). … … 362 362 append(body_mimetype).append("= :bodyMimeType ,"). 363 363 append(headline).append("= :headline ,"). 364 append(last_modified).append("= current_timestamp AT TIME ZONE 'UTC' ,").364 append(last_modified).append("= current_timestamp AT TIME ZONE 'UTC' HOUR TO MINUTE,"). 365 365 append(is_xml).append("= :isXml"). 366 366 append(" WHERE ").append(external_id).append("= :externalID"); … … 403 403 StringBuilder sql = new StringBuilder("INSERT INTO "); 404 404 sql.append(annotationTableName).append("(").append(external_id).append(",").append(owner_id); 405 sql.append(",").append(headline).append(",").append(body_text).append(",").append(body_mimetype).append(",").append(is_xml).append(",").append(last_modified).append(" ) VALUES (:externalId, :ownerId, :headline, :bodyText, :bodyMimeType, :isXml, current_timestamp AT TIME ZONE INTERVAL '00:00' )");405 sql.append(",").append(headline).append(",").append(body_text).append(",").append(body_mimetype).append(",").append(is_xml).append(",").append(last_modified).append(" ) VALUES (:externalId, :ownerId, :headline, :bodyText, :bodyMimeType, :isXml, current_timestamp AT TIME ZONE INTERVAL '00:00' HOUR TO MINUTE)"); 406 406 int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params); 407 407 return ((affectedRows > 0) ? getInternalID(externalID) : null); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcTargetDao.java
r4146 r4173 171 171 params.put("version", target.getVersion()); 172 172 StringBuilder sql = new StringBuilder("INSERT INTO "); 173 sql.append(targetTableName).append("(").append(external_id).append(",").append(link_uri).append(",").append(version).append(",").append(last_modified).append(" ) VALUES (:externalId, :linkUri, :version, current_timestamp AT TIME ZONE INTERVAL '00:00' )");173 sql.append(targetTableName).append("(").append(external_id).append(",").append(link_uri).append(",").append(version).append(",").append(last_modified).append(" ) VALUES (:externalId, :linkUri, :version, current_timestamp AT TIME ZONE INTERVAL '00:00' HOUR TO MINUTE)"); 174 174 final int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params); 175 175 return (affectedRows > 0 ? getInternalID(UUID.fromString(externalID.toString())) : null); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r4028 r4173 33 33 import eu.dasish.annotation.schema.ResponseBody; 34 34 import java.io.IOException; 35 import java.net.URI; 36 import java.security.Principal; 35 37 import java.sql.Timestamp; 36 38 import java.util.ArrayList; … … 50 52 import javax.ws.rs.core.Context; 51 53 import javax.ws.rs.core.MediaType; 54 import javax.ws.rs.core.SecurityContext; 52 55 import javax.ws.rs.core.UriInfo; 53 56 import javax.ws.rs.ext.Providers; … … 77 80 @Context 78 81 private Providers providers; 82 83 79 84 final String default_permission = "reader"; 80 85 private static final Logger logger = LoggerFactory.getLogger(AnnotationResource.class); … … 92 97 } 93 98 99 100 94 101 public void setProviders(Providers providers) { 95 102 this.providers = providers; … … 104 111 @Secured("ROLE_USER") 105 112 public JAXBElement<Annotation> getAnnotation(@PathParam("annotationid") String ExternalIdentifier) { 106 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 113 URI baseURI = uriInfo.getBaseUri(); 114 String baseURIstr = baseURI.toString(); 115 dbIntegrityService.setServiceURI(baseURIstr); 107 116 final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(ExternalIdentifier)); 108 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 117 String remoteUser = httpServletRequest.getRemoteUser(); 118 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 109 119 if (canRead(userID, annotationID)) { 110 120 final Annotation annotation = dbIntegrityService.getAnnotation(annotationID); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/MockObjectsFactoryRest.java
r3974 r4173 46 46 return context.mock(UriInfo.class); 47 47 } 48 48 49 49 50 public Providers newProviders() { -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestBackendConstants.java
r4146 r4173 62 62 public static final String _TEST_ANNOT_TO_ADD_BODY = "<html><body>the stuff to be added</body></html>"; 63 63 64 public static final String _TEST_ANNOT_2_TIME_STAMP = "2013-08-12T09:25:00.383 Z";64 public static final String _TEST_ANNOT_2_TIME_STAMP = "2013-08-12T09:25:00.383000Z"; 65 65 66 66 public static final String annotaiontoDeleteInDB="INSERT INTO annotation (annotation_id, owner_id,headline,body_text, body_mimetype, external_id) VALUES (25, 111, 'Annotation to delete','<html><body>some html 4</body></html>', 'text/html', 00000000-0000-0000-0000-000000000025');"; … … 95 95 public static final String _TEST_NEW_Target_LINK = "http://www.sagradafamilia.cat/docs_instit/historia.php "; 96 96 97 public static final String _TEST_SERVLET_URI = "http://localhost:8080/annotator-backend/api/"; 97 98 public static final String _TEST_SERVLET_URI_annotations = "http://localhost:8080/annotator-backend/api/annotations/"; 98 99 public static final String _TEST_SERVLET_URI_Targets = "http://localhost:8080/annotator-backend/api/Targets/"; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestInstances.java
r4146 r4173 23 23 import eu.dasish.annotation.schema.TargetInfo; 24 24 import eu.dasish.annotation.schema.TargetInfoList; 25 import javax.xml.datatype.DatatypeConfigurationException; 26 import javax.xml.datatype.DatatypeFactory; 25 27 26 28 /** … … 33 35 final private Annotation _annotationToAdd; 34 36 35 public TestInstances( ){36 _annotationOne = makeAnnotationOne( );37 _annotationToAdd = makeAnnotationToAdd( );37 public TestInstances(String baseURI){ 38 _annotationOne = makeAnnotationOne(baseURI); 39 _annotationToAdd = makeAnnotationToAdd(baseURI); 38 40 } 39 41 40 42 41 private Annotation makeAnnotationOne(){ 42 Annotation result = makeAnnotation(TestBackendConstants._TEST_ANNOT_2_BODY, TestBackendConstants._TEST_BODY_MIMETYPE_HTML, TestBackendConstants._TEST_ANNOT_2_HEADLINE, TestBackendConstants._TEST_ANNOT_2_OWNER); 43 private Annotation makeAnnotationOne(String baseURI){ 44 Annotation result = makeAnnotation(baseURI, TestBackendConstants._TEST_ANNOT_2_BODY, TestBackendConstants._TEST_BODY_MIMETYPE_HTML, TestBackendConstants._TEST_ANNOT_2_HEADLINE, TestBackendConstants._TEST_USER_3_EXT_ID); 45 try { 46 result.setLastModified(DatatypeFactory.newInstance().newXMLGregorianCalendar(TestBackendConstants._TEST_ANNOT_2_TIME_STAMP)); 47 } catch (DatatypeConfigurationException dce) { 48 System.out.println("wrongly-formatted test timestamp "+TestBackendConstants._TEST_ANNOT_2_TIME_STAMP); 49 result.setLastModified(null); 50 } 43 51 return result; 44 52 } 45 53 46 private Annotation makeAnnotationToAdd( ){47 Annotation result = makeAnnotation( TestBackendConstants._TEST_ANNOT_TO_ADD_BODY, TestBackendConstants._TEST_BODY_MIMETYPE_TEXT, TestBackendConstants._TEST_ANNOT_TO_ADD_HEADLINE, 5);54 private Annotation makeAnnotationToAdd(String baseURI){ 55 Annotation result = makeAnnotation(baseURI, TestBackendConstants._TEST_ANNOT_TO_ADD_BODY, TestBackendConstants._TEST_BODY_MIMETYPE_TEXT, TestBackendConstants._TEST_ANNOT_TO_ADD_HEADLINE, TestBackendConstants._TEST_USER_3_EXT_ID); 48 56 49 57 TargetInfo TargetInfo = new TargetInfo(); … … 60 68 61 69 62 private Annotation makeAnnotation(String b odyTxt, String bodyMimeType, String headline, int ownerId){70 private Annotation makeAnnotation(String baseURI, String bodyTxt, String bodyMimeType, String headline, String ownerID){ 63 71 Annotation result = new Annotation(); 64 72 AnnotationBody body = new AnnotationBody(); … … 70 78 71 79 result.setHeadline(headline); 72 result.setOwnerRef( String.valueOf(ownerId));80 result.setOwnerRef(baseURI+"users/"+ownerID); 73 81 74 82 result.setLastModified(null); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceTest.java
r4146 r4173 79 79 @Autowired 80 80 private AnnotationDao annotationDao; 81 TestInstances testInstances = new TestInstances( );81 TestInstances testInstances = new TestInstances(TestBackendConstants._TEST_SERVLET_URI); 82 82 83 83 public DBIntegrityServiceTest() { -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r4146 r4173 48 48 @Autowired 49 49 JdbcAnnotationDao jdbcAnnotationDao; 50 TestInstances testInstances = new TestInstances( );50 TestInstances testInstances = new TestInstances(TestBackendConstants._TEST_SERVLET_URI); 51 51 52 52 /** … … 229 229 */ 230 230 @Test 231 @Ignore232 231 public void getAnnotationWithoutTargetsAndPermissions() throws SQLException, DatatypeConfigurationException { 233 232 System.out.println("test getAnnotationWithoutTargets"); … … 269 268 * Test of addAnnotation method, of class JdbcAnnotationDao. 270 269 */ 271 @Test 272 @Ignore 270 @Test 273 271 public void testAddAnnotation() throws SQLException, Exception { 274 272 System.out.println("test_addAnnotation "); … … 378 376 379 377 ////////////////////////////////// 380 @Test 381 @Ignore 378 @Test 382 379 public void testUpdateBodyText() throws SQLException{ 383 380 System.out.println("test updateBodyText"); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDaoTest.java
r3646 r4173 72 72 73 73 private String getTestDataInsertSql() throws FileNotFoundException, URISyntaxException { 74 final URL sqlUrl = Jdbc NotebookDaoTest.class.getResource("/test-data/InsertTestData.sql");74 final URL sqlUrl = JdbcResourceDaoTest.class.getResource("/test-data/InsertTestData.sql"); 75 75 String sqlString = new Scanner(new File(sqlUrl.toURI()), "UTF8").useDelimiter("\\Z").next(); 76 76 return sqlString; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcTargetDaoTest.java
r4146 r4173 161 161 */ 162 162 @Test 163 @Ignore164 163 public void testAddTarget() throws SQLException { 165 164 System.out.println("addTarget"); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDaoTest.java
r3646 r4173 39 39 @Autowired 40 40 JdbcUserDao jdbcUserDao; 41 TestInstances testInstances = new TestInstances( );41 TestInstances testInstances = new TestInstances(TestBackendConstants._TEST_SERVLET_URI); 42 42 43 43 /** -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java
r4146 r4173 19 19 20 20 import eu.dasish.annotation.backend.dao.DBIntegrityService; 21 import eu.dasish.annotation.backend.Helpers;22 21 import eu.dasish.annotation.backend.MockObjectsFactoryRest; 23 22 import eu.dasish.annotation.backend.TestBackendConstants; … … 45 44 import java.lang.InstantiationException; 46 45 import java.net.URI; 47 import java.sql.Timestamp;48 46 import java.util.ArrayList; 49 47 import java.util.List; … … 74 72 private DBIntegrityService mockDbIntegrityService; 75 73 @Autowired 74 UriInfo mockUriInfo; 75 @Autowired 76 76 private AnnotationResource annotationResource; 77 @Autowired78 UriInfo mockUriInfo;79 77 80 78 private MockHttpServletRequest mockRequest; … … 94 92 System.out.println("getAnnotation"); 95 93 final String externalIDstring= TestBackendConstants._TEST_ANNOT_2_EXT; 96 final Annotation expectedAnnotation = (new TestInstances( )).getAnnotationOne();94 final Annotation expectedAnnotation = (new TestInstances(TestBackendConstants._TEST_SERVLET_URI)).getAnnotationOne(); 97 95 annotationResource.setHttpServletRequest(mockRequest); 98 96 annotationResource.setUriInfo(mockUriInfo); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java
r4146 r4173 18 18 package eu.dasish.annotation.backend.rest; 19 19 20 import eu.dasish.annotation.backend.dao.DBIntegrityService;21 20 import com.sun.jersey.api.client.ClientResponse; 22 import eu.dasish.annotation.backend.Helpers; 21 import com.sun.jersey.api.client.WebResource; 22 import com.sun.jersey.api.client.WebResource.Builder; 23 import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; 24 import com.sun.jersey.core.util.Base64; 25 import com.sun.jersey.spi.spring.container.servlet.SpringServlet; 26 import com.sun.jersey.test.framework.JerseyTest; 27 import com.sun.jersey.test.framework.WebAppDescriptor; 23 28 import eu.dasish.annotation.backend.TestBackendConstants; 29 import eu.dasish.annotation.backend.TestInstances; 30 import eu.dasish.annotation.backend.dao.impl.JdbcResourceDaoTest; 24 31 import eu.dasish.annotation.schema.Annotation; 25 32 import eu.dasish.annotation.schema.ObjectFactory; … … 27 34 import eu.dasish.annotation.schema.TargetInfo; 28 35 import eu.dasish.annotation.schema.TargetInfoList; 36 import java.io.File; 37 import java.io.FileNotFoundException; 38 import java.net.URISyntaxException; 39 import java.net.URL; 29 40 import java.sql.SQLException; 30 import java.sql.Timestamp;31 41 import java.util.ArrayList; 32 42 import java.util.List; 43 import java.util.Scanner; 33 44 import java.util.UUID; 45 import javax.servlet.http.HttpServletRequest; 46 import javax.ws.rs.core.Context; 47 import javax.ws.rs.core.HttpHeaders; 34 48 import javax.ws.rs.core.MediaType; 35 import javax.ws.rs.core.UriInfo;36 49 import javax.xml.bind.JAXBElement; 37 50 import javax.xml.datatype.DatatypeConfigurationException; 38 51 import javax.xml.datatype.DatatypeFactory; 39 import org.jmock.Expectations;40 52 import org.junit.Test; 41 53 import static org.junit.Assert.*; 54 import org.junit.Before; 42 55 import org.junit.Ignore; 56 import org.junit.runner.RunWith; 57 import org.springframework.beans.factory.annotation.Autowired; 58 import org.springframework.dao.DataAccessException; 59 import org.springframework.jdbc.core.JdbcTemplate; 60 import org.springframework.mock.web.MockHttpServletRequest; 61 import org.springframework.test.context.ContextConfiguration; 62 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 63 import org.springframework.web.context.ContextLoaderListener; 64 import org.springframework.web.context.request.RequestContextListener; 65 43 66 /** 44 67 * 45 68 * @author olhsha 46 69 */ 47 public class AnnotationsTest extends ResourcesTest{ 48 49 private DBIntegrityService daoDispatcher; 50 51 private UriInfo uriInfo; 70 @RunWith(value = SpringJUnit4ClassRunner.class) 71 @ContextConfiguration({"/spring-integrity-test-config/dataSource.xml"}) 72 public class AnnotationsTest extends JerseyTest { 73 74 @Autowired 75 private JdbcTemplate jdbcTemplate; 52 76 53 77 public AnnotationsTest() { 54 super(AnnotationResource.class.getPackage().getName()); 55 daoDispatcher = webAppContext.getBean(DBIntegrityService.class); 56 uriInfo = webAppContext.getBean(UriInfo.class); 57 } 58 59 60 /** 61 * Test of getAnnotation method, of class annotationResource. Get <aid>. 62 * GET api/annotations/<aid> 78 super(new WebAppDescriptor.Builder(AnnotationResource.class.getPackage().getName()) 79 .servletClass(SpringServlet.class) 80 .contextParam("contextConfigLocation", "classpath*:spring-integrity-test-config/*.xml") 81 .addFilter(DummySecurityFilter.class, "DummySecurityFilter") 82 .requestListenerClass(RequestContextListener.class) 83 .contextListenerClass(ContextLoaderListener.class) 84 .build()); 85 86 } 87 88 private String getNormalisedSql() throws FileNotFoundException, URISyntaxException { 89 // remove the unsupported sql for the test 90 final URL sqlUrl = JdbcResourceDaoTest.class.getResource("/sql/DashishAnnotatorCreate.sql"); 91 String sqlString = new Scanner(new File(sqlUrl.toURI()), "UTF8").useDelimiter("\\Z").next(); 92 for (String unknownToken : new String[]{ 93 "SET client_encoding", 94 "CREATE DATABASE", 95 "\\\\connect", 96 "SET default_with_oids", 97 "ALTER SEQUENCE", 98 "ALTER TABLE ONLY", 99 "ADD CONSTRAINT", 100 "CREATE INDEX", // "ALTER TABLE ONLY [a-z]* ALTER COLUMN", 101 // "ALTER TABLE ONLY [^A]* ADD CONSTRAINT" 102 }) { 103 sqlString = sqlString.replaceAll(unknownToken, "-- " + unknownToken); 104 } 105 // obsolete(?) Peter's stuff, before body has been decided to be a text with its mimetype: sqlString = sqlString.replaceAll("body_xml xml", "body_xml text"); 106 sqlString = sqlString.replaceAll("CACHE 1;", "; -- CACHE 1;"); 107 //sqlString = sqlString.replaceAll("UUID", "text"); 108 sqlString = sqlString.replaceAll("SERIAL NOT NULL", "INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY"); 109 return sqlString; 110 } 111 112 private String getTestDataInsertSql() throws FileNotFoundException, URISyntaxException { 113 final URL sqlUrl = AnnotationsTest.class.getResource("/test-data/InsertTestData.sql"); 114 String sqlString = new Scanner(new File(sqlUrl.toURI()), "UTF8").useDelimiter("\\Z").next(); 115 return sqlString; 116 } 117 118 119 120 @Override 121 @Before 122 public void setUp() throws DataAccessException, FileNotFoundException, URISyntaxException, Exception { 123 super.setUp(); 124 jdbcTemplate.execute("DROP SCHEMA PUBLIC CASCADE"); 125 // consume the DashishAnnotatorCreate sql script to create the database 126 jdbcTemplate.execute(getNormalisedSql()); 127 jdbcTemplate.execute(getTestDataInsertSql()); 128 } 129 130 131 @Override 132 public void tearDown() throws Exception { 133 super.tearDown(); 134 } 135 /** 136 * Test of getAnnotation method, of class annotationResource. Get <aid>. GET 137 * api/annotations/<aid> 138 */ 139 @Test 140 public void testGetAnnotation() throws SQLException, DatatypeConfigurationException { 141 System.out.println("testGetAnnotation"); 142 final String externalIDstring = TestBackendConstants._TEST_ANNOT_2_EXT; 143 final Annotation testAnnotation = (new TestInstances(resource().getURI().toString())).getAnnotationOne(); 144 145 final String requestUrl = "annotations/" + externalIDstring; 146 System.out.println("requestUrl: " + requestUrl); 147 148 Builder responseBuilder = getAuthenticatedResource(resource().path(requestUrl)).accept(MediaType.TEXT_XML); 149 150 ClientResponse response = responseBuilder.get(ClientResponse.class); 151 152 assertEquals(200, response.getStatus()); 153 Annotation entity = response.getEntity(Annotation.class); 154 assertEquals(testAnnotation.getBody().getTextBody().getValue(), entity.getBody().getTextBody().getValue()); 155 assertEquals(testAnnotation.getHeadline(), entity.getHeadline()); 156 assertEquals(testAnnotation.getOwnerRef(), entity.getOwnerRef()); 157 assertEquals(3, entity.getPermissions().getUserWithPermission().size()); 158 assertEquals("owner", entity.getPermissions().getUserWithPermission().get(0).getPermission().value()); 159 assertEquals(resource().getURI()+"users/"+TestBackendConstants._TEST_USER_3_EXT_ID, entity.getPermissions().getUserWithPermission().get(0).getRef()); 160 assertEquals("writer", entity.getPermissions().getUserWithPermission().get(1).getPermission().value()); 161 assertEquals(resource().getURI()+"users/"+TestBackendConstants._TEST_USER_4_EXT_ID, entity.getPermissions().getUserWithPermission().get(1).getRef()); 162 assertEquals("reader", entity.getPermissions().getUserWithPermission().get(2).getPermission().value()); 163 assertEquals(resource().getURI()+"users/"+TestBackendConstants._TEST_USER_5_EXT_ID, entity.getPermissions().getUserWithPermission().get(2).getRef()); 164 assertEquals(2, entity.getTargets().getTargetInfo().size()); 165 assertEquals(resource().getURI().toString()+"targets/"+TestBackendConstants._TEST_Target_1_EXT_ID, entity.getTargets().getTargetInfo().get(0).getRef()); 166 assertEquals(resource().getURI().toString()+"targets/"+TestBackendConstants._TEST_Target_2_EXT_ID, entity.getTargets().getTargetInfo().get(1).getRef()); 167 assertEquals(testAnnotation.getLastModified(), entity.getLastModified()); 168 assertEquals(resource().getURI()+requestUrl, entity.getURI()); 169 } 170 171 /** 172 * Test of deleteAnnotation method, of class AnnotationResource. Delete 173 * <nid>. DELETE api/annotations/<aid> 63 174 */ 64 175 @Test 65 176 @Ignore 66 public void testGetAnnotation() throws SQLException, DatatypeConfigurationException{ 67 System.out.println("testGetAnnotation"); 68 final String externalIDstring= TestBackendConstants._TEST_ANNOT_2_EXT; 69 final int annotationID = 2; 70 final Annotation testAnnotation = new Annotation(); 71 testAnnotation.setOwnerRef("5"); 72 testAnnotation.setURI(externalIDstring); 73 testAnnotation.setLastModified(DatatypeFactory.newInstance().newXMLGregorianCalendar(TestBackendConstants._TEST_ANNOT_2_TIME_STAMP)); 74 177 public void testDeleteAnnotation() throws SQLException { 178 System.out.println("testDeleteAnnotation"); 75 179 //final Number annotationID = daoDispatcher.getAnnotationInternalIdentifier(UUID.fromString(UUID)); 76 //final Annotation annotation = daoDispatcher.getAnnotation(annotationID);77 mockeryRest.checking(new Expectations() {78 {79 80 oneOf(uriInfo).getBaseUri();81 will(returnValue("http://localhost:8080/annotator-backend/api/"));82 83 84 oneOf(daoDispatcher).setServiceURI(with(any(String.class)));85 will(doAll());86 87 oneOf(daoDispatcher).getAnnotationInternalIdentifier(with(aNonNull(UUID.class)));88 will(returnValue(annotationID));89 90 oneOf(daoDispatcher).getAnnotation(annotationID);91 will(returnValue(testAnnotation));92 }93 });94 95 final String requestUrl = "annotations/" + externalIDstring;96 System.out.println("requestUrl: " + requestUrl);97 ClientResponse response = resource().path(requestUrl).accept(MediaType.TEXT_XML).get(ClientResponse.class);98 assertEquals(200, response.getStatus());99 Annotation entity = response.getEntity(Annotation.class);100 assertEquals(testAnnotation.getBody(), entity.getBody());101 assertEquals(testAnnotation.getHeadline(), entity.getHeadline());102 assertEquals(testAnnotation.getOwnerRef(), entity.getOwnerRef());103 assertEquals(testAnnotation.getPermissions(), entity.getPermissions());104 assertEquals(testAnnotation.getTargets(), entity.getTargets());105 assertEquals(testAnnotation.getLastModified(), entity.getLastModified());106 assertEquals(testAnnotation.getURI(), entity.getURI());107 }108 109 /**110 * Test of deleteAnnotation method, of class AnnotationResource. Delete <nid>.111 * DELETE api/annotations/<aid>112 */113 @Test114 @Ignore115 public void testDeleteAnnotation() throws SQLException{116 System.out.println("testDeleteAnnotation");117 //final Number annotationID = daoDispatcher.getAnnotationInternalIdentifier(UUID.fromString(UUID));118 180 //int[] resultDelete = daoDispatcher.deleteAnnotation(annotationID); 119 181 120 182 final int[] mockDelete = new int[4]; 121 mockDelete[0]=1; // # deleted annotations 122 mockDelete[3]=1; // # deleted annotation_prinipal_permissions 123 mockDelete[2]=2; // # deleted annotations_target_Targets, (5,3), (5,4) 124 mockDelete[3]=1; // # deletd Targets, 4 125 mockeryRest.checking(new Expectations() { 126 { 127 128 oneOf(uriInfo).getBaseUri(); 129 will(returnValue("http://localhost:8080/annotator-backend/api/")); 130 131 132 oneOf(daoDispatcher).setServiceURI(with(any(String.class))); 133 will(doAll()); 134 135 oneOf(daoDispatcher).getAnnotationInternalIdentifier(with(aNonNull(UUID.class))); 136 will(returnValue(5)); 137 138 oneOf(daoDispatcher).deleteAnnotation(5); 139 will(returnValue(mockDelete)); 140 } 141 }); 183 mockDelete[0] = 1; // # deleted annotations 184 mockDelete[3] = 1; // # deleted annotation_prinipal_permissions 185 mockDelete[2] = 2; // # deleted annotations_target_Targets, (5,3), (5,4) 186 mockDelete[3] = 1; // # deletd Targets, 4 187 188 final String baseURI = this.getBaseURI().toString(); 189 142 190 final String requestUrl = "annotations/" + TestBackendConstants._TEST_ANNOT_5_EXT; 143 191 System.out.println("requestUrl: " + requestUrl); … … 146 194 assertEquals("1 annotation(s) deleted.", response.getEntity(String.class)); 147 195 148 149 } 196 197 } 198 150 199 /** 151 * Test of createAnnotation method, of class AnnotationResource. 152 * POSTapi/annotations/200 * Test of createAnnotation method, of class AnnotationResource. POST 201 * api/annotations/ 153 202 */ 154 203 @Test 155 204 @Ignore 156 public void testCreateAnnotation() throws SQLException, InstantiationException, IllegalAccessException, DatatypeConfigurationException, Exception {205 public void testCreateAnnotation() throws SQLException, InstantiationException, IllegalAccessException, DatatypeConfigurationException, Exception { 157 206 System.out.println("test createAnnotation"); 158 207 // Peter's workaround on absence of "ObjectFactory.create... for annotations … … 160 209 161 210 final String ownerString = "5"; 162 final Number ownerID = 211 final Number ownerID = 5; 163 212 final Number newAnnotationID = 6; 164 213 … … 173 222 addedAnnotation.setTargets(TargetInfoList); 174 223 addedAnnotation.setOwnerRef(ownerString); 175 addedAnnotation.setURI(TestBackendConstants._TEST_SERVLET_URI_annotations +UUID.randomUUID().toString());224 addedAnnotation.setURI(TestBackendConstants._TEST_SERVLET_URI_annotations + UUID.randomUUID().toString()); 176 225 addedAnnotation.setLastModified(DatatypeFactory.newInstance().newXMLGregorianCalendar(TestBackendConstants._TEST_ANNOT_2_TIME_STAMP)); 177 226 TargetInfo TargetInfo = new TargetInfo(); … … 179 228 TargetInfo.setRef(UUID.randomUUID().toString()); 180 229 TargetInfo.setVersion("vandaag"); 181 TargetInfoList.getTargetInfo().add(TargetInfo); 230 TargetInfoList.getTargetInfo().add(TargetInfo); 182 231 183 232 final List<Number> Targets = new ArrayList<Number>(); 184 233 Targets.add(6); 185 234 186 mockeryRest.checking(new Expectations() { 187 { 188 189 oneOf(uriInfo).getBaseUri(); 190 will(returnValue("http://localhost:8080/annotator-backend/api/")); 191 192 193 oneOf(daoDispatcher).setServiceURI(with(any(String.class))); 194 will(doAll()); 195 196 oneOf(daoDispatcher).getUserInternalIdentifier(with(any(UUID.class))); 197 will(returnValue(ownerID)); 198 199 //oneOf(daoDispatcher).addUsersAnnotation(annotToAddJB, ownerID); 200 oneOf(daoDispatcher).addUsersAnnotation(with(aNonNull(Number.class)), with(aNonNull(Annotation.class))); 201 will(returnValue(newAnnotationID)); 202 203 oneOf(daoDispatcher).getAnnotation(newAnnotationID); 204 will(returnValue(addedAnnotation)); 205 206 oneOf(daoDispatcher).getTargetsWithNoCachedRepresentation(newAnnotationID); 207 will(returnValue(Targets)); 208 } 209 }); 210 211 235 final String baseURI = this.getBaseURI().toString(); 212 236 213 237 final String requestUrl = "annotations"; … … 216 240 assertEquals(200, response.getStatus()); 217 241 218 ResponseBody entity = response.getEntity(ResponseBody.class); 242 ResponseBody entity = response.getEntity(ResponseBody.class); 219 243 Annotation entityA = entity.getAnnotation(); 220 244 assertEquals(addedAnnotation.getBody(), entityA.getBody()); … … 227 251 assertEquals(addedAnnotation.getOwnerRef(), entityA.getOwnerRef()); 228 252 } 253 254 255 256 protected Builder getAuthenticatedResource(WebResource resource) { 257 return resource.header(HttpHeaders.AUTHORIZATION, "Basic " + new String(Base64.encode(DummyPrincipal.DUMMY_PRINCIPAL.getName()+":olhapassword"))); 258 } 229 259 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql
r4146 r4173 39 39 INSERT INTO principal (principal_name, external_id, remote_id, e_mail) VALUES ('Twan', '00000000-0000-0000-0000-000000000111', 'x3', 'twagoo@mpi.nl'); --3 40 40 INSERT INTO principal (principal_name, external_id, remote_id, e_mail) VALUES ('Peter', '00000000-0000-0000-0000-000000000112', 'y4', 'Peter.Withers@mpi.nl'); -- 4 41 INSERT INTO principal (principal_name, external_id, remote_id, e_mail) VALUES ('Olha', '00000000-0000-0000-0000-000000000113', ' z5', 'olhsha@mpi.nl'); -- 541 INSERT INTO principal (principal_name, external_id, remote_id, e_mail) VALUES ('Olha', '00000000-0000-0000-0000-000000000113', 'JUnit@test.com', 'olhsha@mpi.nl'); -- 5 42 42 INSERT INTO principal (principal_name, external_id, remote_id, e_mail) VALUES ('Eric', '00000000-0000-0000-0000-000000000114', 'v6', 'eriaue@mpi.nl'); -- 6 43 43
Note: See TracChangeset
for help on using the changeset viewer.