Changeset 3453
- Timestamp:
- 08/21/13 13:02:59 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r3452 r3453 87 87 public JAXBElement<Annotation> createAnnotation(Annotation annotation) throws SQLException { 88 88 String remoteUser = httpServletRequest.getRemoteUser(); 89 Number userID = null; 90 if (remoteUser != null) { 91 userID = daoDispatcher.getUserInternalIdentifier(new UserIdentifier(remoteUser)); 92 } 89 Number userID = daoDispatcher.getUserInternalIdentifier(new UserIdentifier(remoteUser)); 93 90 Number newAnnotationID = daoDispatcher.addUsersAnnotation(annotation, userID); 94 91 Annotation newAnnotation = daoDispatcher.getAnnotation(newAnnotationID); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestInstances.java
r3347 r3453 35 35 final private Annotation _annotationOne; 36 36 final private Annotation _annotationToAdd; 37 final private Annotation _annotationToAddNewSource;38 37 39 38 public TestInstances(){ 40 39 _annotationOne = makeAnnotationOne(); 41 _annotationToAdd = makeAnnotationToAdd(); 42 _annotationToAddNewSource = makeAnnotationToAddNewSource(); 40 _annotationToAdd = makeAnnotationToAdd(); 43 41 } 44 42 … … 66 64 } 67 65 68 private Annotation makeAnnotationToAddNewSource(){ 69 Annotation result = makeAnnotation(TestBackendConstants._TEST_ANNOT_TO_ADD_NEW_SOURCE_BODY, TestBackendConstants._TEST_ANNOT_TO_ADD_NEW_SOURCE_HEADLINE, 5); 70 71 NewSourceInfo newSourceInfo = new NewSourceInfo(); 72 newSourceInfo.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK); 73 newSourceInfo.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID); 74 // TODO: so far, the version is the external version id generated when a version is added 75 // because for now the version is used to keep external id of the version, not is human-friendly headline 76 // fix it by adding external Id to the version 77 newSourceInfo.setVersion(null); 78 79 NewOrExistingSourceInfo noeSourceInfo = new NewOrExistingSourceInfo(); 80 noeSourceInfo.setNewSource(newSourceInfo); 81 NewOrExistingSourceInfos noeSourceInfos = new NewOrExistingSourceInfos(); 82 noeSourceInfos.getTarget().add(noeSourceInfo); 83 result.setTargetSources(noeSourceInfos); 84 85 return result; 86 } 87 88 89 // so far tests only adding annot with existing sources!!! 90 // TODO: add non-existing sources 66 91 67 private Annotation makeAnnotation(String bodyTxt, String headline, int ownerId){ 92 68 Annotation result = new Annotation(); … … 108 84 } 109 85 110 //private111 112 86 113 87 public Annotation getAnnotationOne(){ … … 119 93 } 120 94 121 public Annotation getAnnotationToAddNewSource(){122 return _annotationToAddNewSource;123 }124 95 125 96 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java
r3452 r3453 140 140 owner.setRef(ownerString); 141 141 addedAnnotation.setOwner(owner); 142 addedAnnotation.setURI((new AnnotationIdentifier()).toString()); 142 addedAnnotation.setURI((new AnnotationIdentifier()).toString()); 143 addedAnnotation.setTimeStamp(Helpers.setXMLGregorianCalendar(Timestamp.valueOf("2013-08-12 11:25:00.383000"))); 143 144 144 addedAnnotation.setTimeStamp(Helpers.setXMLGregorianCalendar(Timestamp.valueOf("2013-08-12 11:25:00.383000")));145 145 mockery.checking(new Expectations() { 146 146 { -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java
r3452 r3453 20 20 import eu.dasish.annotation.backend.dao.DaoDispatcher; 21 21 import com.sun.jersey.api.client.ClientResponse; 22 import com.sun.jersey.api.client.GenericType; 22 23 import eu.dasish.annotation.backend.Helpers; 23 24 import eu.dasish.annotation.backend.TestBackendConstants; 24 import eu.dasish.annotation.backend.TestInstances;25 25 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 26 26 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 27 27 import eu.dasish.annotation.schema.Annotation; 28 import eu.dasish.annotation.schema.AnnotationBody; 28 29 import eu.dasish.annotation.schema.ObjectFactory; 29 30 import eu.dasish.annotation.schema.ResourceREF; … … 56 57 */ 57 58 @Test 58 public void testGetAnnotation() throws SQLException {59 public void testGetAnnotation() throws SQLException, DatatypeConfigurationException{ 59 60 System.out.println("testGetAnnotation"); 60 61 final String annotationIdentifier= TestBackendConstants._TEST_ANNOT_2_EXT; 61 62 final int annotationID = 2; 62 final Annotation testAnnotation = new ObjectFactory().createAnnotation(); 63 final Annotation expectedAnnotation = (new TestInstances()).getAnnotationOne(); 63 final Annotation testAnnotation = new Annotation(); 64 ResourceREF owner = new ResourceREF(); 65 owner.setRef("5"); 66 testAnnotation.setOwner(owner); 67 testAnnotation.setURI((new AnnotationIdentifier()).toString()); 68 testAnnotation.setTimeStamp(Helpers.setXMLGregorianCalendar(Timestamp.valueOf("2013-08-12 11:25:00.383000"))); 64 69 65 70 //final Number annotationID = daoDispatcher.getAnnotationInternalIdentifier(new AnnotationIdentifier(annotationIdentifier)); … … 71 76 72 77 oneOf(daoDispatcher).getAnnotation(annotationID); 73 will(returnValue( expectedAnnotation));78 will(returnValue(testAnnotation)); 74 79 } 75 80 }); … … 82 87 assertEquals(testAnnotation.getBody(), entity.getBody()); 83 88 assertEquals(testAnnotation.getHeadline(), entity.getHeadline()); 84 assertEquals(testAnnotation.getOwner() , entity.getOwner());89 assertEquals(testAnnotation.getOwner().getRef(), entity.getOwner().getRef()); 85 90 assertEquals(testAnnotation.getPermissions(), entity.getPermissions()); 86 91 assertEquals(testAnnotation.getTargetSources(), entity.getTargetSources()); … … 128 133 public void testCreateAnnotation() throws SQLException, InstantiationException, IllegalAccessException, DatatypeConfigurationException{ 129 134 System.out.println("test createAnnotation"); 130 final Annotation annotationToAdd = new ObjectFactory().createAnnotation(); 135 // Peter's workaround on absence of "ObjectFactory.create... for annotations 136 137 final Annotation annotationToAdd = new Annotation(); 138 139 final JAXBElement<Annotation> jaxbElement = new JAXBElement<Annotation>(new QName("http://www.dasish.eu/ns/addit", "annotation"), Annotation.class, null, annotationToAdd); 140 //final Annotation annotToAddJB = jaxbElement.getValue(); 131 141 132 // Number userID = null; 133 // if (remoteUser != null) { 134 // userID = daoDispatcher.getUserInternalIdentifier(new UserIdentifier(remoteUser)); 135 // } 136 // Number newAnnotationID = daoDispatcher.addUsersAnnotation(annotation, userID); 137 // Annotation newAnnotation = daoDispatcher.getAnnotation(newAnnotationID); 142 // for setting up mockery 143 //userID = daoDispatcher.getUserInternalIdentifier(new UserIdentifier(remoteUser)); 144 //Number newAnnotationID = daoDispatcher.addUsersAnnotation(annotation, userID); 145 //Annotation newAnnotation = daoDispatcher.getAnnotation(newAnnotationID); 138 146 final String ownerString = "5"; 139 147 final Number ownerID = 5; … … 151 159 will(returnValue(ownerID)); 152 160 153 oneOf(daoDispatcher).addUsersAnnotation(annotationToAdd, ownerID); 161 //oneOf(daoDispatcher).addUsersAnnotation(annotToAddJB, ownerID); 162 oneOf(daoDispatcher).addUsersAnnotation(with(aNonNull(Annotation.class)), with(aNonNull(Number.class))); 154 163 will(returnValue(newAnnotationID)); 155 164 … … 159 168 }); 160 169 161 // Peter's workaround on absence of "ObjectFactory.create... for annotations 162 final JAXBElement<Annotation> jaxbElement = new JAXBElement<Annotation>(new QName("http://www.dasish.eu/ns/addit", "annotation"), Annotation.class, null, annotationToAdd); 170 163 171 164 172 final String requestUrl = "annotations"; 165 173 System.out.println("requestUrl: " + requestUrl); 166 ClientResponse response = resource().path(requestUrl). accept(MediaType.APPLICATION_XML).type(MediaType.APPLICATION_XML).post(ClientResponse.class, jaxbElement);174 ClientResponse response = resource().path(requestUrl).type(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML).post(ClientResponse.class, jaxbElement); 167 175 assertEquals(200, response.getStatus()); 168 176 169 177 Annotation entity = response.getEntity(Annotation.class); 170 assertEquals(annotationToAdd.getBody(), entity.getBody()); 171 assertEquals(annotationToAdd.getHeadline(), entity.getHeadline()); 172 assertEquals(annotationToAdd.getPermissions(), entity.getPermissions()); 173 assertEquals(annotationToAdd.getTargetSources(), entity.getTargetSources()); 174 assertEquals(annotationToAdd.getTimeStamp(), entity.getTimeStamp()); 178 assertEquals(addedAnnotation.getBody(), entity.getBody()); 179 assertEquals(addedAnnotation.getHeadline(), entity.getHeadline()); 180 assertEquals(addedAnnotation.getPermissions(), entity.getPermissions()); 181 assertEquals(addedAnnotation.getTargetSources(), entity.getTargetSources()); 182 assertEquals(addedAnnotation.getTimeStamp(), entity.getTimeStamp()); 183 assertEquals(addedAnnotation.getOwner().getRef(), entity.getOwner().getRef()); 175 184 } 176 185 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebookResourceTest.java
r3408 r3453 47 47 @RunWith(value = SpringJUnit4ClassRunner.class) 48 48 @ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockUserDao.xml", 49 "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mock ery.xml"})49 "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockDaoDispatcher.xml", "/spring-test-config/mockery.xml"}) 50 50 public class NotebookResourceTest { 51 51
Note: See TracChangeset
for help on using the changeset viewer.