1 | /* |
---|
2 | * Copyright (C) 2013 DASISH |
---|
3 | * |
---|
4 | * This program is free software; you can redistribute it and/or |
---|
5 | * modify it under the terms of the GNU General Public License |
---|
6 | * as published by the Free Software Foundation; either version 2 |
---|
7 | * of the License, or (at your option) any later version. |
---|
8 | * |
---|
9 | * This program is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | * GNU General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public License |
---|
15 | * along with this program; if not, write to the Free Software |
---|
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
17 | */ |
---|
18 | package eu.dasish.annotation.backend.rest; |
---|
19 | |
---|
20 | import eu.dasish.annotation.backend.dao.DBIntegrityService; |
---|
21 | import javax.ws.rs.core.UriInfo; |
---|
22 | |
---|
23 | /** |
---|
24 | * Created on : Jun 12, 2013, 11:31 AM |
---|
25 | * |
---|
26 | * @author Peter Withers <peter.withers@mpi.nl> |
---|
27 | */ |
---|
28 | public class NotebooksTest extends ResourcesTest { |
---|
29 | |
---|
30 | private DBIntegrityService daoDispatcher; |
---|
31 | |
---|
32 | private UriInfo uriInfo; |
---|
33 | |
---|
34 | public NotebooksTest() { |
---|
35 | super(AnnotationResource.class.getPackage().getName()); |
---|
36 | daoDispatcher = webAppContext.getBean(DBIntegrityService.class); |
---|
37 | uriInfo = webAppContext.getBean(UriInfo.class); |
---|
38 | } |
---|
39 | |
---|
40 | // |
---|
41 | // /** |
---|
42 | // * Test of getNotebookInfo method, of class NotebookResource. Returns |
---|
43 | // * notebook-infos for the notebooks accessible to the current user. GET |
---|
44 | // * api/notebooks |
---|
45 | // */ |
---|
46 | // @Test |
---|
47 | // public void testGetNotebookInfo() { |
---|
48 | // System.out.println("testGetNotebookInfo"); |
---|
49 | // mockeryRest.checking(new Expectations() { |
---|
50 | // { |
---|
51 | // oneOf(notebookDao).getNotebookInfos(with(any(UUID.class))); |
---|
52 | // will(returnValue(new ArrayList<NotebookInfo>())); |
---|
53 | // } |
---|
54 | // }); |
---|
55 | // client().addFilter(new HTTPBasicAuthFilter("userid", "userpass")); |
---|
56 | // ClientResponse response = Resource().path("notebooks").accept(MediaType.TEXT_XML).get(ClientResponse.class); |
---|
57 | // assertEquals(200, response.getStatus()); |
---|
58 | // assertEquals(0, response.getEntity(new GenericType<NotebookInfoList>() { |
---|
59 | // }).getNotebook().size()); |
---|
60 | // } |
---|
61 | // |
---|
62 | // /** |
---|
63 | // * Test of getUsersNotebooks method, of class NotebookResource. Returns the |
---|
64 | // * list of all notebooks owned by the current logged user. GET |
---|
65 | // * api/notebooks/owned |
---|
66 | // */ |
---|
67 | // @Test |
---|
68 | // public void testGetUsersNotebooks() { |
---|
69 | // System.out.println("testGetUsersNotebooks"); |
---|
70 | // mockeryRest.checking(new Expectations() { |
---|
71 | // { |
---|
72 | // oneOf(notebookDao).getUsersNotebooks(with(any(UUID.class))); |
---|
73 | // will(returnValue(new ArrayList<Notebook>())); |
---|
74 | // } |
---|
75 | // }); |
---|
76 | // client().addFilter(new HTTPBasicAuthFilter("userid", "userpass")); |
---|
77 | // ClientResponse response = Resource().path("notebooks/owned").accept(MediaType.TEXT_XML).get(ClientResponse.class); |
---|
78 | // assertEquals(200, response.getStatus()); |
---|
79 | // assertEquals(0, response.getEntity(new GenericType<List<Notebook>>() { |
---|
80 | // }).size()); |
---|
81 | // } |
---|
82 | // |
---|
83 | // /** |
---|
84 | // * Test of getReaders method, of class NotebookResource. Returns the list of |
---|
85 | // * <uid> |
---|
86 | // * who allowed to read the annotations from notebook. GET |
---|
87 | // * api/notebooks/<nid>/readers |
---|
88 | // */ |
---|
89 | // @Test |
---|
90 | // public void testGetReaders() { |
---|
91 | // System.out.println("testGetReaders"); |
---|
92 | // ClientResponse response = Resource().path("notebooks/_nid_/readers").get(ClientResponse.class); |
---|
93 | // assertEquals(200, response.getStatus()); |
---|
94 | // assertEquals("readers for _nid_", response.getEntity(String.class)); |
---|
95 | // } |
---|
96 | // |
---|
97 | // /** |
---|
98 | // * Test of getWriters method, of class NotebookResource. Returns the list of |
---|
99 | // * <uid> |
---|
100 | // * that can add annotations to the notebook. GET api/notebooks/<nid>/writers |
---|
101 | // */ |
---|
102 | // @Test |
---|
103 | // public void testGetWriters() { |
---|
104 | // System.out.println("testGetWriters"); |
---|
105 | // ClientResponse response = Resource().path("notebooks/_nid_/writers").get(ClientResponse.class); |
---|
106 | // assertEquals(200, response.getStatus()); |
---|
107 | // assertEquals("writers for _nid_", response.getEntity(String.class)); |
---|
108 | // } |
---|
109 | // |
---|
110 | // /** |
---|
111 | // * Test of getMetadata method, of class NotebookResource. Get all metadata |
---|
112 | // * about a specified notebook <nid>, including the information if it is |
---|
113 | // * private or not. GET api/notebooks/<nid>/metadata |
---|
114 | // */ |
---|
115 | // @Test |
---|
116 | // public void testGetMetadata() { |
---|
117 | // System.out.println("test GetMetadata"); |
---|
118 | // |
---|
119 | // final String externalIDstring= TestBackendConstants._TEST_NOTEBOOK_3_EXT; |
---|
120 | // final int notebookID = 3; |
---|
121 | // final NotebookInfo testInfo = new ObjectFactory().createNotebookInfo(); |
---|
122 | // |
---|
123 | // mockeryRest.checking(new Expectations() { |
---|
124 | // { |
---|
125 | // oneOf(notebookDao).getInternalID(UUID.fromString(externalIDstring)); |
---|
126 | // will(returnValue(notebookID)); |
---|
127 | // |
---|
128 | // oneOf(notebookDao).getNotebookInfo(notebookID); |
---|
129 | // will(returnValue(testInfo)); |
---|
130 | // } |
---|
131 | // }); |
---|
132 | // |
---|
133 | // final String requestUrl = "notebooks/" + externalIDstring+"/metadata"; |
---|
134 | // System.out.println("requestUrl: " + requestUrl); |
---|
135 | // ClientResponse response = Resource().path(requestUrl).type(MediaType.TEXT_XML).get(ClientResponse.class); |
---|
136 | // assertEquals(200, response.getStatus()); |
---|
137 | // NotebookInfo entity = response.getEntity(NotebookInfo.class); |
---|
138 | // assertEquals(testInfo.getRef(), entity.getRef()); |
---|
139 | // assertEquals(testInfo.getTitle(), entity.getTitle()); |
---|
140 | // } |
---|
141 | // |
---|
142 | // /** |
---|
143 | // * Test of getAllAnnotations method, of class NotebookResource. Get the list |
---|
144 | // * of all annotations <aid>-s contained within a Notebook with related |
---|
145 | // * metadata. Parameters: <nid>, optional maximumAnnotations specifies the |
---|
146 | // * maximum number of annotations to retrieve (default -1, all annotations), |
---|
147 | // * optional startAnnotation specifies the starting point from which the |
---|
148 | // * annotations will be retrieved (default: -1, start from the first |
---|
149 | // * annotation), optional orderby, specifies the RDF property used to order |
---|
150 | // * the annotations (default: dc:created ), optional orderingMode specifies |
---|
151 | // * if the results should be sorted using a descending order desc=1 or an |
---|
152 | // * ascending order desc=0 (default: 0 ). GET |
---|
153 | // * api/notebooks/<nid>?maximumAnnotations=limit&startAnnotation=offset&orderby=orderby&orderingMode=1|0 |
---|
154 | // */ |
---|
155 | // @Test |
---|
156 | // public void testGetAllAnnotations() { |
---|
157 | // System.out.println("test GetMetadata"); |
---|
158 | // final String externalIDstring= TestBackendConstants._TEST_NOTEBOOK_3_EXT; |
---|
159 | // final UUID aIdOne= UUID.fromString(TestBackendConstants._TEST_ANNOT_2_EXT); |
---|
160 | // final UUID aIdTwo= UUID.fromString(TestBackendConstants._TEST_ANNOT_3_EXT); |
---|
161 | // final List<UUID> annotationIds = new ArrayList<UUID>(); |
---|
162 | // annotationIds.add(aIdOne); |
---|
163 | // annotationIds.add(aIdTwo); |
---|
164 | // |
---|
165 | // mockeryRest.checking(new Expectations() { |
---|
166 | // { |
---|
167 | // oneOf(notebookDao).getAnnotationExternalIDs(with(aNonNull(UUID.class))); |
---|
168 | // will(returnValue(annotationIds)); |
---|
169 | // |
---|
170 | // } |
---|
171 | // }); |
---|
172 | // |
---|
173 | // final String requestUrl = "notebooks/"+externalIDstring; |
---|
174 | // ClientResponse response = Resource().path(requestUrl) |
---|
175 | // .queryParam("maximumAnnotations", "123") |
---|
176 | // .queryParam("startAnnotation", "456") |
---|
177 | // .queryParam("orderby", "dc:789") |
---|
178 | // .queryParam("orderingMode", "1") |
---|
179 | // .get(ClientResponse.class); |
---|
180 | // System.out.println("requestUrl: " + requestUrl); |
---|
181 | // assertEquals(200, response.getStatus()); |
---|
182 | // List<JAXBElement<UUID>> result = response.getEntity(new GenericType<List<JAXBElement<UUID>>>() {}); |
---|
183 | // assertEquals(aIdOne, result.get(0).getValue()); |
---|
184 | // assertEquals(aIdTwo, result.get(1).getValue()); |
---|
185 | // } |
---|
186 | // |
---|
187 | // /** |
---|
188 | // * Test of modifyNotebook method, of class NotebookResource. Modify metadata |
---|
189 | // * of |
---|
190 | // * <nid>. The new notebookâs name must be sent in requestâs body. PUT |
---|
191 | // * /notebooks/<nid> |
---|
192 | // */ |
---|
193 | // @Test |
---|
194 | // @Ignore |
---|
195 | // public void testModifyNotebook_String() { |
---|
196 | // System.out.println("testModifyNotebook_String"); |
---|
197 | // final Notebook notebook = new Notebook(); |
---|
198 | // notebook.setTitle("a title"); |
---|
199 | // /* |
---|
200 | // // this JAXBElement should be returned by the generated ObjectFactory, however it is not. This could be due to name space polution in the schema? |
---|
201 | // // todo: this JAXBElement should be removed and replaced by the same as returned by the ObjectFactory when cause of it not being auto generated is resolved, in the mean time this line below makes it clear where the issue starts from. |
---|
202 | // // see ticket #348 |
---|
203 | // final JAXBElement<Notebook> jaxbElement = new JAXBElement<Notebook>(new QName("http://www.dasish.eu/ns/addit", "notebook"), Notebook.class, null, notebook); |
---|
204 | // */ |
---|
205 | // |
---|
206 | // final JAXBElement<Notebook> notebookJAXB = (new ObjectFactory()).createNotebook(notebook); |
---|
207 | // ClientResponse response = Resource().path("notebooks/_nid_").type(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML).put(ClientResponse.class, notebookJAXB); |
---|
208 | // assertEquals(200, response.getStatus()); |
---|
209 | // assertEquals("modifyNotebook _nid_a title", response.getEntity(String.class)); |
---|
210 | // } |
---|
211 | // |
---|
212 | // /** |
---|
213 | // * Test of modifyNotebook method, of class NotebookResource. Adds an |
---|
214 | // * annotation |
---|
215 | // * <aid> to the list of annotations of <nid>. PUT /notebooks/<nid>/<aid> |
---|
216 | // */ |
---|
217 | // @Test |
---|
218 | // public void testAddAnnotation_String_String() { |
---|
219 | // System.out.println("testAddAnnotation_String_String"); |
---|
220 | // ClientResponse response = Resource().path("notebooks/_nid_/_aid_").put(ClientResponse.class); |
---|
221 | // assertEquals(200, response.getStatus()); |
---|
222 | // assertEquals("addAnnotation _nid_ : _aid_", response.getEntity(String.class)); |
---|
223 | // } |
---|
224 | // |
---|
225 | // /** |
---|
226 | // * Test of createNotebook method, of class NotebookResource. Creates a new |
---|
227 | // * notebook. This API returns the <nid> of the created Notebook in |
---|
228 | // * responseâs payload and the full URL of the notebook adding a Location |
---|
229 | // * header into the HTTP response. The name of the new notebook can be |
---|
230 | // * specified sending a specific payload. POST api/notebooks/ |
---|
231 | // */ |
---|
232 | // @Test |
---|
233 | // public void testCreateNotebook() throws URISyntaxException { |
---|
234 | // System.out.println("testCreateNotebook"); |
---|
235 | // mockeryRest.checking(new Expectations() { |
---|
236 | // { |
---|
237 | // oneOf(notebookDao).addNotebook(with(any(UUID.class)), with(any(String.class))); |
---|
238 | // will(returnValue(UUID.fromString(TestBackendConstants._TEST_NOTEBOOK_1_EXT_ID))); |
---|
239 | // } |
---|
240 | // }); |
---|
241 | // ClientResponse response = Resource().path("notebooks").post(ClientResponse.class); |
---|
242 | // assertEquals(200, response.getStatus()); |
---|
243 | // assertEquals("/api/notebooks/00000000-0000-0000-0000-000000000001", new URI(response.getEntity(String.class)).getPath()); |
---|
244 | // } |
---|
245 | // |
---|
246 | // /** |
---|
247 | // * Test of createAnnotation method, of class NotebookResource. Creates a new |
---|
248 | // * annotation in <nid>. The content of an annotation is given in the request |
---|
249 | // * body. In fact this is a short cut of two actions: POST |
---|
250 | // * api/notebooks/<nid> |
---|
251 | // */ |
---|
252 | // @Test |
---|
253 | // public void testCreateAnnotation() { |
---|
254 | // System.out.println("testCreateAnnotation"); |
---|
255 | // ClientResponse response = Resource().path("notebooks/_nid_").post(ClientResponse.class); |
---|
256 | // assertEquals(200, response.getStatus()); |
---|
257 | // assertEquals("annotation _nid_ : api/notebooks/_nid_", response.getEntity(String.class)); |
---|
258 | // } |
---|
259 | // |
---|
260 | // /** |
---|
261 | // * Test of deleteNotebook method, of class NotebookResource. Delete <nid>. |
---|
262 | // * Annotations stay, they just lose connection to <nid>. DELETE |
---|
263 | // * api/notebooks/<nid> |
---|
264 | // */ |
---|
265 | // @Test |
---|
266 | // public void testDeleteNotebook() { |
---|
267 | // System.out.println("testModifyNotebook_String"); |
---|
268 | // mockeryRest.checking(new Expectations() { |
---|
269 | // { |
---|
270 | // oneOf(notebookDao).deleteNotebook(UUID.fromString(TestBackendConstants._TEST_NOTEBOOK_2_EXT_ID)); |
---|
271 | // will(returnValue(1)); |
---|
272 | // } |
---|
273 | // }); |
---|
274 | // final String requestUrl = "notebooks/" + TestBackendConstants._TEST_NOTEBOOK_2_EXT_ID; |
---|
275 | // System.out.println("requestUrl: " + requestUrl); |
---|
276 | // ClientResponse response = Resource().path(requestUrl).delete(ClientResponse.class); |
---|
277 | // assertEquals(200, response.getStatus()); |
---|
278 | // assertEquals("1", response.getEntity(String.class)); |
---|
279 | // } |
---|
280 | } |
---|