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.dao.impl; |
---|
19 | |
---|
20 | import org.junit.Test; |
---|
21 | import org.junit.runner.RunWith; |
---|
22 | import org.springframework.beans.factory.annotation.Autowired; |
---|
23 | import org.springframework.test.context.ContextConfiguration; |
---|
24 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
---|
25 | |
---|
26 | /** |
---|
27 | * |
---|
28 | * @author Peter Withers <peter.withers@mpi.nl> |
---|
29 | */ |
---|
30 | // TODO: Move integrating methods from JdbcNotebookDao to DaoDispatcher, and move corresponding tests to DaoDistatcherTest.class, |
---|
31 | //remove from here all the mockery and retest. |
---|
32 | @RunWith(SpringJUnit4ClassRunner.class) |
---|
33 | @ContextConfiguration({"/spring-test-config/dataSource.xml","/spring-config/notebookDao.xml"}) |
---|
34 | public class JdbcNotebookDaoTest extends JdbcResourceDaoTest{ |
---|
35 | |
---|
36 | @Autowired |
---|
37 | JdbcNotebookDao jdbcNotebookDao; |
---|
38 | |
---|
39 | @Test |
---|
40 | public void Dummy() { |
---|
41 | } |
---|
42 | |
---|
43 | /** |
---|
44 | * Test of stringURItoExternalID method |
---|
45 | * public String stringURItoExternalID(String uri); |
---|
46 | */ |
---|
47 | // @Test |
---|
48 | // @Ignore |
---|
49 | // public void testStringURItoExternalID() { |
---|
50 | // System.out.println("test stringURItoExternalID"); |
---|
51 | // jdbcNotebookDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI_notebooks); |
---|
52 | // String randomUUID = UUID.randomUUID().toString(); |
---|
53 | // String uri = TestBackendConstants._TEST_SERVLET_URI_notebooks + randomUUID; |
---|
54 | // String externalID = jdbcNotebookDao.stringURItoExternalID(uri); |
---|
55 | // assertEquals(randomUUID, externalID); |
---|
56 | // } |
---|
57 | // |
---|
58 | // /** |
---|
59 | // * Test of externalIDtoURI method |
---|
60 | // * public String externalIDtoURI(String externalID); |
---|
61 | // */ |
---|
62 | // @Test |
---|
63 | // @Ignore |
---|
64 | // public void testExternalIDtoURI() { |
---|
65 | // System.out.println("test stringURItoExternalID"); |
---|
66 | // jdbcNotebookDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI_notebooks); |
---|
67 | // String randomUUID = UUID.randomUUID().toString(); |
---|
68 | // String uri = TestBackendConstants._TEST_SERVLET_URI_notebooks+randomUUID; |
---|
69 | // String uriResult = jdbcNotebookDao.externalIDtoURI(randomUUID); |
---|
70 | // assertEquals(uri, uriResult); |
---|
71 | // } |
---|
72 | // |
---|
73 | // /** |
---|
74 | // * Test of getNotebookInfos method, of class JdbcNotebookDao. |
---|
75 | // */ |
---|
76 | // @Test |
---|
77 | // @Ignore |
---|
78 | // public void testGetNotebookInfos() { |
---|
79 | // final List<NotebookInfo> notebookInfoList = jdbcNotebookDao.getNotebookInfos(UUID.fromString(TestBackendConstants._TEST_UID_2_)); |
---|
80 | // assertEquals(2, notebookInfoList.size()); |
---|
81 | // assertEquals("a notebook", notebookInfoList.get(0).getTitle()); |
---|
82 | // } |
---|
83 | // |
---|
84 | // /** |
---|
85 | // * Test of getUsersNotebooks method, of class JdbcNotebookDao. |
---|
86 | // */ |
---|
87 | // @Test |
---|
88 | // @Ignore |
---|
89 | // public void testGetUsersNotebooks() { |
---|
90 | // int year = Calendar.getInstance().get(Calendar.YEAR); |
---|
91 | // int month = Calendar.getInstance().get(Calendar.MONTH); |
---|
92 | // int day = Calendar.getInstance().get(Calendar.DAY_OF_MONTH); |
---|
93 | // |
---|
94 | // ReTargetREF testRef = new ReTargetREF(); |
---|
95 | // testRef.setRef(TestBackendConstants._TEST_SERVLET_URI_notebooks+TestBackendConstants._TEST_AID_1_); |
---|
96 | // final List<ReTargetREF> testResult = Arrays.asList(new ReTargetREF[] {testRef}); |
---|
97 | // |
---|
98 | // mockery.checking(new Expectations() { |
---|
99 | // { |
---|
100 | // exactly(2).of(annotationDao).getAnnotationREFs(Arrays.asList(new Number[] {1}));// exactly 2 notebooks (their id-s 1 and 2) contain the annotation 1 |
---|
101 | // will(returnValue(testResult)); |
---|
102 | // // necessary to set annotations reference lists in the notebook |
---|
103 | // } |
---|
104 | // }); |
---|
105 | // |
---|
106 | // jdbcNotebookDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI_notebooks); |
---|
107 | // final List<Notebook> notebooks = jdbcNotebookDao.getUsersNotebooks(UUID.fromString(TestBackendConstants._TEST_UID_2_)); |
---|
108 | // |
---|
109 | // |
---|
110 | // assertEquals(2, notebooks.size()); |
---|
111 | // assertEquals("a notebook", notebooks.get(0).getTitle()); |
---|
112 | // assertEquals(TestBackendConstants._TEST_SERVLET_URI_notebooks+TestBackendConstants._TEST_NOTEBOOK_1_EXT_ID, notebooks.get(0).getURI()); |
---|
113 | // assertNotNull(notebooks.get(0).getTimeStamp()); |
---|
114 | // assertEquals(year, notebooks.get(0).getTimeStamp().getYear()); |
---|
115 | // assertEquals(month + 1, notebooks.get(0).getTimeStamp().getMonth()); |
---|
116 | // assertEquals(day, notebooks.get(0).getTimeStamp().getDay()); |
---|
117 | // |
---|
118 | // |
---|
119 | // mockery.checking(new Expectations() { |
---|
120 | // { |
---|
121 | // oneOf(annotationDao).getAnnotationREFs(new ArrayList<Number>()); |
---|
122 | // will(returnValue(new ArrayList<ReTargetREF>())); |
---|
123 | // } |
---|
124 | // }); |
---|
125 | // |
---|
126 | // final List<Notebook> notebooksEmpty = jdbcNotebookDao.getUsersNotebooks(UUID.fromString(TestBackendConstants._TEST_UID_1_)); |
---|
127 | // assertEquals(0, notebooksEmpty.size()); |
---|
128 | // } |
---|
129 | // |
---|
130 | // /** |
---|
131 | // * Test of addNotebook method, of class JdbcNotebookDao. |
---|
132 | // */ |
---|
133 | // @Test |
---|
134 | // @Ignore |
---|
135 | // public void testAddNotebook() throws URISyntaxException { |
---|
136 | // final UUID addedNotebookId = jdbcNotebookDao.addNotebook(UUID.fromString(TestBackendConstants._TEST_UID_2_), "a title"); |
---|
137 | // assertEquals(36, addedNotebookId.toString().length()); |
---|
138 | // } |
---|
139 | // |
---|
140 | // /** |
---|
141 | // * Test of deleteNotebook method, of class JdbcNotebookDao. |
---|
142 | // */ |
---|
143 | // @Test |
---|
144 | // @Ignore |
---|
145 | // public void testDeleteNotebook() { |
---|
146 | // System.out.println("deleteNotebook"); |
---|
147 | // UUID notebookId = UUID.fromString(TestBackendConstants._TEST_NOTEBOOK_2_EXT_ID); |
---|
148 | // int result = jdbcNotebookDao.deleteNotebook(notebookId); |
---|
149 | // assertEquals(1, result); |
---|
150 | // } |
---|
151 | // |
---|
152 | // /** |
---|
153 | // * Test of getAnnotationIDs method, of class JdbcAnnotationDao. |
---|
154 | // * List<Number> getAnnotationIDs(Number notebookID) |
---|
155 | // */ |
---|
156 | // @Test |
---|
157 | // @Ignore |
---|
158 | // public void testGetAnnotationIDs() { |
---|
159 | // System.out.println("getAnnotationIDs"); |
---|
160 | // |
---|
161 | // // test one, 2-element notebook |
---|
162 | // final List<Number> annotationIDs = jdbcNotebookDao.getAnnotationIDs(3); |
---|
163 | // assertEquals(2, annotationIDs.size()); |
---|
164 | // assertEquals(2, annotationIDs.get(0).intValue()); |
---|
165 | // assertEquals(3, annotationIDs.get(1).intValue()); |
---|
166 | // |
---|
167 | // // test two, 1-element notebook |
---|
168 | // final List<Number> annotationIDsTwo = jdbcNotebookDao.getAnnotationIDs(4); |
---|
169 | // assertEquals(1, annotationIDsTwo.size()); |
---|
170 | // assertEquals(4, annotationIDsTwo.get(0).intValue()); |
---|
171 | // |
---|
172 | // // test three, empty notebook |
---|
173 | // final List<Number> annotationIDsThree = jdbcNotebookDao.getAnnotationIDs(6); |
---|
174 | // assertEquals(0, annotationIDsThree.size()); |
---|
175 | // |
---|
176 | // // test four, null-notebook |
---|
177 | // final List<Number> annotationIDsFour = jdbcNotebookDao.getAnnotationIDs(null); |
---|
178 | // assertEquals(0, annotationIDsFour.size()); |
---|
179 | // |
---|
180 | // |
---|
181 | // } |
---|
182 | // |
---|
183 | // |
---|
184 | // |
---|
185 | // /** |
---|
186 | // * Test of getAnnotationREFsOfNotebook method, of class JdbcAnnotationDao. |
---|
187 | // * List<ReTargetREF> getAnnotationREFsOfNotebook(Number notebookID) |
---|
188 | // */ |
---|
189 | // @Test |
---|
190 | // @Ignore |
---|
191 | // public void testGetAnnotationREFsOfNotebook() { |
---|
192 | // System.out.println("getAnnotationREFsOfNotebook"); |
---|
193 | // |
---|
194 | // jdbcNotebookDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI_notebooks); |
---|
195 | // annotationDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI_annotations); |
---|
196 | // // test One |
---|
197 | // setMockeryNotebookOne(); |
---|
198 | // List<ReTargetREF> testList = jdbcNotebookDao.getAnnotationREFsOfNotebook(3); |
---|
199 | // assertEquals(2, testList.size()); |
---|
200 | // assertEquals(TestBackendConstants._TEST_SERVLET_URI_annotations+"00000000-0000-0000-0000-000000000021", testList.get(0).getRef()); |
---|
201 | // assertEquals(TestBackendConstants._TEST_SERVLET_URI_annotations+"00000000-0000-0000-0000-000000000022", testList.get(1).getRef()); |
---|
202 | // |
---|
203 | // // test Two |
---|
204 | // setMockeryNotebookTwo(); |
---|
205 | // List<ReTargetREF> testListTwo = jdbcNotebookDao.getAnnotationREFsOfNotebook(4); |
---|
206 | // assertEquals(1, testListTwo.size()); |
---|
207 | // assertEquals(TestBackendConstants._TEST_SERVLET_URI_annotations+"00000000-0000-0000-0000-000000000023", testListTwo.get(0).getRef()); |
---|
208 | // |
---|
209 | // // test Three "empty" |
---|
210 | // setMockeryNotebookThreeEmpty(); |
---|
211 | // List<ReTargetREF> testListThree = jdbcNotebookDao.getAnnotationREFsOfNotebook(6); |
---|
212 | // assertEquals(0, testListThree.size()); |
---|
213 | // |
---|
214 | // // test Five Null-notebook |
---|
215 | // setMockeryNotebookNonExisting(); |
---|
216 | // List<ReTargetREF> testListFive = jdbcNotebookDao.getAnnotationREFsOfNotebook(null); |
---|
217 | // assertEquals(0, testListFive.size()); |
---|
218 | // } |
---|
219 | // |
---|
220 | // /** |
---|
221 | // * Test of getAnnotations method, of class JdbcNotebookDao. |
---|
222 | // * Annotations getAnnotations(Number notebookID) |
---|
223 | // */ |
---|
224 | // @Test |
---|
225 | // @Ignore |
---|
226 | // public void testGetAnnotations() { |
---|
227 | // System.out.println("getAnnotations"); |
---|
228 | // |
---|
229 | // jdbcNotebookDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI_notebooks); |
---|
230 | // |
---|
231 | // // test One |
---|
232 | // setMockeryNotebookOne(); |
---|
233 | // AnnotationList annotations = jdbcNotebookDao.getAnnotations(3); |
---|
234 | // assertEquals(2, annotations.getAnnotation().size()); |
---|
235 | // assertEquals(TestBackendConstants._TEST_SERVLET_URI_annotations+"00000000-0000-0000-0000-000000000021", annotations.getAnnotation().get(0).getRef()); |
---|
236 | // assertEquals(TestBackendConstants._TEST_SERVLET_URI_annotations+"00000000-0000-0000-0000-000000000022", annotations.getAnnotation().get(1).getRef()); |
---|
237 | // |
---|
238 | // // test Two |
---|
239 | // setMockeryNotebookTwo(); |
---|
240 | // AnnotationList annotationsTwo = jdbcNotebookDao.getAnnotations(4); |
---|
241 | // assertEquals(1, annotationsTwo.getAnnotation().size()); |
---|
242 | // assertEquals(TestBackendConstants._TEST_SERVLET_URI_annotations+"00000000-0000-0000-0000-000000000023", annotationsTwo.getAnnotation().get(0).getRef()); |
---|
243 | // |
---|
244 | // // test Three "empty" list of annotations |
---|
245 | // // according to dasish.xsd if an Annotation is created then its list of annotations must contain at least one element! |
---|
246 | // // therefore: no annotations in the notebook ==> Annotations-pbject must be null :( |
---|
247 | // setMockeryNotebookThreeEmpty(); |
---|
248 | // AnnotationList annotationsThree = jdbcNotebookDao.getAnnotations(6); |
---|
249 | // assertEquals(null, annotationsThree); |
---|
250 | // |
---|
251 | // |
---|
252 | // // test Five Null-notebook |
---|
253 | // setMockeryNotebookNonExisting(); |
---|
254 | // AnnotationList annotationsFive = jdbcNotebookDao.getAnnotations(null); |
---|
255 | // assertEquals(null, annotationsFive); |
---|
256 | // } |
---|
257 | // |
---|
258 | // /** Test of getNotebookInfo method, of class JdbcNotebookDao. |
---|
259 | // * |
---|
260 | // */ |
---|
261 | // @Test |
---|
262 | // @Ignore |
---|
263 | // public void testGetNotebookInfo() { |
---|
264 | // System.out.println("test getNotebookInfo"); |
---|
265 | // |
---|
266 | // jdbcNotebookDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI_notebooks); |
---|
267 | // |
---|
268 | // // test One |
---|
269 | // NotebookInfo info = jdbcNotebookDao.getNotebookInfo(3); |
---|
270 | // assertEquals(TestBackendConstants._TEST_SERVLET_URI_notebooks+"/"+TestBackendConstants._TEST_NOTEBOOK_3_EXT, info.getRef()); |
---|
271 | // assertEquals(TestBackendConstants._TEST_NOTEBOOK_3_TITLE, info.getTitle()); |
---|
272 | // |
---|
273 | // |
---|
274 | // // test Three Null-notebook |
---|
275 | // NotebookInfo infoThree = jdbcNotebookDao.getNotebookInfo(null); |
---|
276 | // assertEquals(null, infoThree); |
---|
277 | // } |
---|
278 | // |
---|
279 | // /** Test of getNotebookID method, of class JdbcNotebookDao. |
---|
280 | // * |
---|
281 | // */ |
---|
282 | // @Test |
---|
283 | // @Ignore |
---|
284 | // public void testGetNotebookID() { |
---|
285 | // System.out.println("test getNotebookID"); |
---|
286 | // |
---|
287 | // // test One |
---|
288 | // Number resultOne= jdbcNotebookDao.getInternalID(UUID.fromString(TestBackendConstants._TEST_NOTEBOOK_3_EXT)); |
---|
289 | // assertEquals(3, resultOne.intValue()); |
---|
290 | // |
---|
291 | // |
---|
292 | // // test Three Null-notebook |
---|
293 | // Number resultThree= jdbcNotebookDao.getInternalID(null); |
---|
294 | // assertEquals(null, resultThree); |
---|
295 | // } |
---|
296 | // |
---|
297 | // |
---|
298 | // @Test |
---|
299 | // @Ignore |
---|
300 | // public void testGetAnnotationExternalIDs() { |
---|
301 | // System.out.println("test getExternalAnnotationIds"); |
---|
302 | // |
---|
303 | // // test One |
---|
304 | // mockery.checking(new Expectations() { |
---|
305 | // { |
---|
306 | // oneOf(annotationDao).getExternalID(2); |
---|
307 | // will(returnValue(UUID.fromString("00000000-0000-0000-0000-000000000021"))); |
---|
308 | // |
---|
309 | // oneOf(annotationDao).getExternalID(3); |
---|
310 | // will(returnValue(UUID.fromString("00000000-0000-0000-0000-000000000022"))); |
---|
311 | // } |
---|
312 | // }); |
---|
313 | // |
---|
314 | // List<UUID> resultOne= jdbcNotebookDao.getAnnotationExternalIDs(UUID.fromString(TestBackendConstants._TEST_NOTEBOOK_3_EXT)); |
---|
315 | // assertEquals("00000000-0000-0000-0000-000000000021", resultOne.get(0).toString()); |
---|
316 | // assertEquals("00000000-0000-0000-0000-000000000022", resultOne.get(1).toString()); |
---|
317 | // |
---|
318 | // |
---|
319 | // |
---|
320 | // // test Two, non-existing notebook |
---|
321 | // List<UUID> resultThree= jdbcNotebookDao.getAnnotationExternalIDs(null); |
---|
322 | // assertEquals(0, resultThree.size()); |
---|
323 | // |
---|
324 | // } |
---|
325 | // |
---|
326 | // |
---|
327 | // //////////////////////////////////////////////////////////////////// |
---|
328 | // //////// Setting Mockeries ///////////////////////////////////////// |
---|
329 | // /////////////////////////////////////////////////////////////////// |
---|
330 | // |
---|
331 | // private void setMockeryNotebookOne(){ |
---|
332 | // ReTargetREF testRefOne = new ReTargetREF(); |
---|
333 | // testRefOne.setRef(TestBackendConstants._TEST_SERVLET_URI_annotations+"00000000-0000-0000-0000-000000000021"); |
---|
334 | // ReTargetREF testRefTwo = new ReTargetREF(); |
---|
335 | // testRefTwo.setRef(TestBackendConstants._TEST_SERVLET_URI_annotations+"00000000-0000-0000-0000-000000000022"); |
---|
336 | // final List<ReTargetREF> testResult = Arrays.asList(new ReTargetREF[] {testRefOne, testRefTwo}); |
---|
337 | // |
---|
338 | // mockery.checking(new Expectations() { |
---|
339 | // { |
---|
340 | // oneOf(annotationDao).getAnnotationREFs(Arrays.asList(new Number[] {2, 3})); |
---|
341 | // will(returnValue(testResult)); |
---|
342 | // } |
---|
343 | // }); |
---|
344 | // } |
---|
345 | // |
---|
346 | // private void setMockeryNotebookTwo(){ |
---|
347 | // ReTargetREF testRef = new ReTargetREF(); |
---|
348 | // testRef.setRef(String.valueOf(TestBackendConstants._TEST_SERVLET_URI_annotations+"00000000-0000-0000-0000-000000000023")); |
---|
349 | // final List<ReTargetREF> testResultTwo = Arrays.asList(new ReTargetREF[] {testRef}); |
---|
350 | // |
---|
351 | // mockery.checking(new Expectations() { |
---|
352 | // { |
---|
353 | // oneOf(annotationDao).getAnnotationREFs(Arrays.asList(new Number[] {4})); |
---|
354 | // will(returnValue(testResultTwo)); |
---|
355 | // } |
---|
356 | // }); |
---|
357 | // } |
---|
358 | // |
---|
359 | // private void setMockeryNotebookThreeEmpty(){ |
---|
360 | // mockery.checking(new Expectations() { |
---|
361 | // { |
---|
362 | // oneOf(annotationDao).getAnnotationREFs(new ArrayList<Number>()); |
---|
363 | // will(returnValue(new ArrayList<ReTargetREF>())); |
---|
364 | // } |
---|
365 | // }); |
---|
366 | // } |
---|
367 | // |
---|
368 | // private void setMockeryNotebookNonExisting() { |
---|
369 | // mockery.checking(new Expectations() { |
---|
370 | // { |
---|
371 | // oneOf(annotationDao).getAnnotationREFs(null); |
---|
372 | // will(returnValue(null)); |
---|
373 | // } |
---|
374 | // }); |
---|
375 | // } |
---|
376 | // |
---|
377 | |
---|
378 | } |
---|