Changeset 4176
- Timestamp:
- 12/10/13 17:36:30 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java
r4175 r4176 21 21 import com.sun.jersey.api.client.WebResource; 22 22 import com.sun.jersey.api.client.WebResource.Builder; 23 import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;24 23 import com.sun.jersey.core.util.Base64; 25 24 import com.sun.jersey.spi.spring.container.servlet.SpringServlet; … … 31 30 import eu.dasish.annotation.backend.dao.impl.JdbcResourceDaoTest; 32 31 import eu.dasish.annotation.schema.Annotation; 32 import eu.dasish.annotation.schema.AnnotationBody; 33 import eu.dasish.annotation.schema.AnnotationBody.TextBody; 33 34 import eu.dasish.annotation.schema.ObjectFactory; 34 35 import eu.dasish.annotation.schema.ResponseBody; … … 40 41 import java.net.URL; 41 42 import java.sql.SQLException; 42 import java.util.ArrayList;43 import java.util.List;44 43 import java.util.Scanner; 45 44 import java.util.UUID; 46 import javax.servlet.http.HttpServletRequest;47 import javax.ws.rs.core.Context;48 45 import javax.ws.rs.core.HttpHeaders; 49 46 import javax.ws.rs.core.MediaType; … … 54 51 import static org.junit.Assert.*; 55 52 import org.junit.Before; 56 import org.junit.Ignore;57 53 import org.junit.runner.RunWith; 58 54 import org.springframework.beans.factory.annotation.Autowired; 59 55 import org.springframework.dao.DataAccessException; 60 56 import org.springframework.jdbc.core.JdbcTemplate; 61 import org.springframework.mock.web.MockHttpServletRequest;62 57 import org.springframework.test.context.ContextConfiguration; 63 58 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; … … 157 152 System.out.println("requestUrl: " + requestUrl); 158 153 159 Builder responseBuilder = getAuthenticatedResource(resource().path(requestUrl)).accept(MediaType.TEXT_XML); 160 154 Builder responseBuilder = getAuthenticatedResource(resource().path(requestUrl)).accept(MediaType.TEXT_XML); 161 155 ClientResponse response = responseBuilder.get(ClientResponse.class); 162 156 … … 185 179 */ 186 180 @Test 187 @Ignore188 181 public void testDeleteAnnotation() throws SQLException { 189 182 System.out.println("testDeleteAnnotation"); 190 //final Number annotationID = daoDispatcher.getAnnotationInternalIdentifier(UUID.fromString(UUID)); 191 //int[] resultDelete = daoDispatcher.deleteAnnotation(annotationID); 192 193 final int[] mockDelete = new int[4]; 194 mockDelete[0] = 1; // # deleted annotations 195 mockDelete[3] = 1; // # deleted annotation_prinipal_permissions 196 mockDelete[2] = 2; // # deleted annotations_target_Targets, (5,3), (5,4) 197 mockDelete[3] = 1; // # deletd Targets, 4 198 199 final String baseURI = this.getBaseURI().toString(); 200 201 final String requestUrl = "annotations/" + TestBackendConstants._TEST_ANNOT_5_EXT; 183 String externalIDstring = TestBackendConstants._TEST_ANNOT_5_EXT; 184 final String requestUrl = "annotations/" + externalIDstring; 202 185 System.out.println("requestUrl: " + requestUrl); 203 ClientResponse response = resource().path(requestUrl).delete(ClientResponse.class); 186 187 Builder responseBuilder = getAuthenticatedResource(resource().path(requestUrl)).accept(MediaType.TEXT_XML); 188 ClientResponse response = responseBuilder.delete(ClientResponse.class); 204 189 assertEquals(200, response.getStatus()); 205 190 assertEquals("1 annotation(s) deleted.", response.getEntity(String.class)); 206 207 208 191 } 209 192 … … 213 196 */ 214 197 @Test 215 @Ignore216 198 public void testCreateAnnotation() throws SQLException, InstantiationException, IllegalAccessException, DatatypeConfigurationException, Exception { 217 199 System.out.println("test createAnnotation"); 218 // Peter's workaround on absence of "ObjectFactory.create... for annotations 219 //final JAXBElement<Annotation> jaxbElement = new JAXBElement<Annotation>(new QName("http://www.dasish.eu/ns/addit", "annotation"), Annotation.class, null, annotationToAdd); 220 221 final String ownerString = "5"; 222 final Number ownerID = 5; 223 final Number newAnnotationID = 6; 224 225 ResponseBody responseBody = new ResponseBody(); 226 final JAXBElement<ResponseBody> jaxbElement = (new ObjectFactory()).createResponseBody(responseBody); 227 responseBody.setPermissions(null); 228 final Annotation addedAnnotation = new Annotation(); 229 responseBody.setAnnotation(addedAnnotation); 230 responseBody.setActionList(null); 231 232 TargetInfoList TargetInfoList = new TargetInfoList(); 233 addedAnnotation.setTargets(TargetInfoList); 234 addedAnnotation.setOwnerRef(ownerString); 235 addedAnnotation.setURI(TestBackendConstants._TEST_SERVLET_URI_annotations + UUID.randomUUID().toString()); 236 addedAnnotation.setLastModified(DatatypeFactory.newInstance().newXMLGregorianCalendar(TestBackendConstants._TEST_ANNOT_2_TIME_STAMP)); 237 TargetInfo TargetInfo = new TargetInfo(); 238 TargetInfo.setLink("google.nl"); 239 TargetInfo.setRef(UUID.randomUUID().toString()); 240 TargetInfo.setVersion("vandaag"); 241 TargetInfoList.getTargetInfo().add(TargetInfo); 242 243 final List<Number> Targets = new ArrayList<Number>(); 244 Targets.add(6); 245 246 final String baseURI = this.getBaseURI().toString(); 247 248 final String requestUrl = "annotations"; 249 System.out.println("requestUrl: " + requestUrl); 250 ClientResponse response = resource().path(requestUrl).type(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML).post(ClientResponse.class, jaxbElement); 200 System.out.println("POST "+resource().getURI().toString()+"annotations/"); 201 final String ownerString = resource().getURI().toString()+"users/"+TestBackendConstants._TEST_USER_5_EXT_ID; 202 final Annotation annotationToAdd = new Annotation(); 203 final JAXBElement<Annotation> jaxbElement = (new ObjectFactory()).createAnnotation(annotationToAdd); 204 annotationToAdd.setPermissions(null); 205 annotationToAdd.setOwnerRef(ownerString); 206 annotationToAdd.setURI(resource().getURI().toString()+"annotations/"+ UUID.randomUUID().toString()); 207 annotationToAdd.setLastModified(DatatypeFactory.newInstance().newXMLGregorianCalendar(TestBackendConstants._TEST_ANNOT_2_TIME_STAMP)); 208 209 TargetInfoList targetInfoList = new TargetInfoList(); 210 annotationToAdd.setTargets(targetInfoList); 211 TargetInfo targetInfo = new TargetInfo(); 212 targetInfo.setLink("http://nl.wikipedia.org/wiki/Viktor_Janoekovytsj#Biografie"); 213 targetInfo.setRef(resource().getURI().toString()+"targets/"+UUID.randomUUID().toString()); 214 targetInfo.setVersion("5 apr 2013 om 18:42"); 215 targetInfoList.getTargetInfo().add(targetInfo); 216 217 AnnotationBody annotationBody = new AnnotationBody(); 218 annotationBody.setXmlBody(null); 219 TextBody textBody = new TextBody(); 220 textBody.setMimeType("plain/text"); 221 textBody.setValue("yanuk - zek"); 222 annotationBody.setTextBody(textBody); 223 annotationToAdd.setBody(annotationBody); 224 225 Builder responseBuilder = getAuthenticatedResource(resource().path("annotations/")).type(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML); 226 ClientResponse response = responseBuilder.post(ClientResponse.class, jaxbElement); 251 227 assertEquals(200, response.getStatus()); 252 228 253 229 ResponseBody entity = response.getEntity(ResponseBody.class); 254 230 Annotation entityA = entity.getAnnotation(); 255 assertEquals(addedAnnotation.getBody(), entityA.getBody()); 256 assertEquals(addedAnnotation.getHeadline(), entityA.getHeadline()); 257 assertEquals(addedAnnotation.getPermissions(), entityA.getPermissions()); 258 assertEquals(addedAnnotation.getTargets().getTargetInfo().get(0).getLink(), entityA.getTargets().getTargetInfo().get(0).getLink()); 259 assertEquals(addedAnnotation.getTargets().getTargetInfo().get(0).getRef(), entityA.getTargets().getTargetInfo().get(0).getRef()); 260 assertEquals(addedAnnotation.getTargets().getTargetInfo().get(0).getVersion(), entityA.getTargets().getTargetInfo().get(0).getVersion()); 261 assertEquals(addedAnnotation.getLastModified(), entityA.getLastModified()); 262 assertEquals(addedAnnotation.getOwnerRef(), entityA.getOwnerRef()); 231 assertEquals(annotationToAdd.getBody().getTextBody().getValue(), entityA.getBody().getTextBody().getValue()); 232 assertEquals(annotationToAdd.getBody().getTextBody().getMimeType(), entityA.getBody().getTextBody().getMimeType()); 233 assertEquals(annotationToAdd.getHeadline(), entityA.getHeadline()); 234 assertEquals(1, entityA.getPermissions().getUserWithPermission().size()); 235 assertEquals("owner", entityA.getPermissions().getUserWithPermission().get(0).getPermission().value()); 236 assertEquals(annotationToAdd.getOwnerRef(), entityA.getPermissions().getUserWithPermission().get(0).getRef()); 237 assertEquals(annotationToAdd.getTargets().getTargetInfo().get(0).getLink(), entityA.getTargets().getTargetInfo().get(0).getLink()); 238 // new ref is generated 239 //assertEquals(annotationToAdd.getTargets().getTargetInfo().get(0).getRef(), entityA.getTargets().getTargetInfo().get(0).getRef()); 240 assertEquals(annotationToAdd.getTargets().getTargetInfo().get(0).getVersion(), entityA.getTargets().getTargetInfo().get(0).getVersion()); 241 //last modified is updated by the server 242 //assertEquals(annotationToAdd.getLastModified(), entityA.getLastModified()); 243 assertEquals(annotationToAdd.getOwnerRef(), entityA.getOwnerRef()); 263 244 } 264 245
Note: See TracChangeset
for help on using the changeset viewer.