Changeset 3186
- Timestamp:
- 07/24/13 09:41:55 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r3180 r3186 18 18 package eu.dasish.annotation.backend.rest; 19 19 20 import eu.dasish.annotation.backend.AnnotationRooted; 20 21 import eu.dasish.annotation.backend.BackendConstants; 21 22 import eu.dasish.annotation.backend.dao.AnnotationDao; … … 24 25 import eu.dasish.annotation.schema.ObjectFactory; 25 26 import java.sql.SQLException; 26 import java.util.ArrayList;27 27 import javax.ws.rs.Consumes; 28 28 import javax.ws.rs.DELETE; … … 47 47 @Autowired 48 48 private AnnotationDao annotationDao; 49 50 final private int charBufferSize = 128;51 49 52 50 @GET … … 72 70 @Produces(MediaType.APPLICATION_XML) 73 71 @Path("") 74 public String createAnnotation(ArrayList<Annotation>annotation) {75 return "OK";76 / *AnnotationIdentifier newAnnotationIdentifier = annotationDao.addAnnotation(annotation);72 public JAXBElement<Annotation> createAnnotation(AnnotationRooted annotation) { 73 AnnotationIdentifier newAnnotationIdentifier = annotationDao.addAnnotation(annotation); 74 //return newAnnotationIdentifier.toString(); 77 75 if (newAnnotationIdentifier == null) { 78 76 return null; 79 77 } else { 80 return Response.status(Status.OK).entity(new ObjectFactory().createAnnotation(annotation)).build();81 } */78 return (new ObjectFactory().createAnnotation(annotation)); 79 } 82 80 } 83 81 84 85 /* helper: stolen from StackOverflow 86 private String getBody(HttpServletRequest request) throws IOException{ 87 String body = null; 88 StringBuilder stringBuilder = new StringBuilder(); 89 BufferedReader bufferedReader = null; 90 91 try { 92 InputStream inputStream = request.getInputStream(); 93 if (inputStream != null) { 94 bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); 95 char[] charBuffer = new char[charBufferSize]; 96 int bytesRead = -1; 97 while ((bytesRead = bufferedReader.read(charBuffer)) > 0) { 98 stringBuilder.append(charBuffer, 0, bytesRead); 99 } 100 } else { 101 stringBuilder.append(""); 102 } 103 } catch (IOException ex) { 104 throw ex; 105 } finally { 106 if (bufferedReader != null) { 107 try { 108 bufferedReader.close(); 109 } catch (IOException ex) { 110 throw ex; 111 } 112 } 113 } 114 115 body = stringBuilder.toString(); 116 return body; 117 118 }*/ 119 120 82 121 83 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java
r3180 r3186 19 19 20 20 import com.sun.jersey.api.client.GenericType; 21 import eu.dasish.annotation.backend.AnnotationRooted; 21 22 import eu.dasish.annotation.backend.TestBackendConstants; 22 23 import eu.dasish.annotation.backend.TestInstances; … … 24 25 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 25 26 import eu.dasish.annotation.schema.Annotation; 27 import eu.dasish.annotation.schema.ObjectFactory; 26 28 import java.sql.SQLException; 27 import javax.ws.rs.core.Response;28 29 import javax.xml.bind.JAXBElement; 29 30 import org.jmock.Expectations; … … 36 37 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 37 38 import java.lang.InstantiationException; 38 import java.util.ArrayList;39 import java.util.List;40 39 /** 41 40 * … … 123 122 public void testCreateAnnotation() throws SQLException, InstantiationException, IllegalAccessException { 124 123 System.out.println("test createAnnotation"); 125 final Annotation annotationToAdd = new GenericType<Annotation>(){}.getRawClass().newInstance();124 final AnnotationRooted annotationToAdd = new GenericType<AnnotationRooted>(){}.getRawClass().newInstance(); 126 125 final AnnotationIdentifier newAnnotationID = new GenericType<AnnotationIdentifier>(){}.getRawClass().newInstance(); 127 126 … … 133 132 }); 134 133 135 ArrayList<Annotation> parameter = new ArrayList<Annotation>();136 parameter.add(annotationToAdd);137 134 138 String result = annotationResource.createAnnotation(parameter); 139 assertTrue(result=="OK"); 140 //assertEquals(200, result.getStatus()); 141 //assertTrue(annotationToAdd.equals(result.getEntity())); 135 JAXBElement result = annotationResource.createAnnotation(annotationToAdd); 136 assertTrue(annotationToAdd.equals(result.getValue())); 142 137 } 143 138 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java
r3180 r3186 19 19 20 20 import com.sun.jersey.api.client.ClientResponse; 21 import com.sun.jersey.api.client.GenericType; 22 import eu.dasish.annotation.backend.AnnotationRooted; 21 23 import eu.dasish.annotation.backend.TestBackendConstants; 22 24 import eu.dasish.annotation.backend.dao.AnnotationDao; 23 25 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 24 26 import eu.dasish.annotation.schema.Annotation; 27 import eu.dasish.annotation.schema.Annotation; 25 28 import eu.dasish.annotation.schema.ObjectFactory; 26 29 import java.sql.SQLException; 27 import java.util.ArrayList; 28 import java.util.List; 30 import javax.ws.rs.core.GenericEntity; 29 31 import javax.ws.rs.core.MediaType; 32 import javax.xml.bind.JAXBElement; 30 33 import org.jmock.Expectations; 31 34 import org.junit.Test; 32 35 import static org.junit.Assert.*; 33 import org.junit.Ignore;34 36 /** 35 37 * … … 127 129 */ 128 130 @Test 129 @Ignore131 //@Ignore 130 132 public void testAddAnnotation() throws SQLException, InstantiationException, IllegalAccessException{ 131 System.out.println("testDeleteAnnotation");132 133 System.out.println("test createAnnotation"); 133 //final Annotation annotationToAdd = new GenericType<Annotation>(){}.getRawClass().newInstance();134 final Annotation annotationToAdd = new ObjectFactory().createAnnotation();135 ///final AnnotationIdentifier newAnnotationID = new GenericType<AnnotationIdentifier>(){}.getRawClass().newInstance();134 //final Annotation annotationToAdd = new ObjectFactory().createAnnotation(); 135 final AnnotationRooted annotationToAdd = new GenericType<AnnotationRooted>(){}.getRawClass().newInstance(); 136 final AnnotationIdentifier newAnnotationID = new GenericType<AnnotationIdentifier>(){}.getRawClass().newInstance(); 136 137 137 //mockery.checking(new Expectations() {138 //{139 // oneOf(annotationDao).addAnnotation(annotationToAdd);140 //will(returnValue(newAnnotationID));141 //}142 //});138 mockery.checking(new Expectations() { 139 { 140 oneOf(annotationDao).addAnnotation(with(aNonNull(AnnotationRooted.class))); 141 will(returnValue(newAnnotationID)); 142 } 143 }); 143 144 144 145 146 145 147 final String requestUrl = "annotations/"; 146 148 System.out.println("requestUrl: " + requestUrl); 147 149 148 List<Annotation> parameter = new ArrayList<Annotation>();149 parameter.add(annotationToAdd);150 ClientResponse response = resource().path(requestUrl).type(MediaType.APPLICATION_XML).post(ClientResponse.class, new GenericEntity<AnnotationRooted>(annotationToAdd){}); 151 assertEquals(200, response.getStatus()); 150 152 151 String response = resource().path(requestUrl).type(MediaType.APPLICATION_XML).post(String.class, parameter); 152 //assertEquals(200, response.getStatus()); 153 //assertEquals(annotationToAdd, response.getEntity(Annotation.class)); 154 155 153 Annotation entity = response.getEntity(Annotation.class); 154 assertEquals(annotationToAdd.getBody(), entity.getBody()); 155 assertEquals(annotationToAdd.getHeadline(), entity.getHeadline()); 156 assertEquals(annotationToAdd.getPermissions(), entity.getPermissions()); 157 assertEquals(annotationToAdd.getTargetSources(), entity.getTargetSources()); 158 assertEquals(annotationToAdd.getTimeStamp(), entity.getTimeStamp()); 159 assertEquals(annotationToAdd.getURI(), entity.getURI()); 156 160 } 157 161 }
Note: See TracChangeset
for help on using the changeset viewer.