1 | package nl.tno.metagenomics.integration |
---|
2 | |
---|
3 | import nl.tno.metagenomics.* |
---|
4 | import nl.tno.metagenomics.auth.* |
---|
5 | import grails.converters.JSON |
---|
6 | import grails.test.* |
---|
7 | import org.junit.* |
---|
8 | import org.springframework.orm.hibernate3.SessionFactoryUtils; |
---|
9 | import org.hibernate.Session |
---|
10 | import org.hibernate.SessionFactory |
---|
11 | |
---|
12 | class SynchronizationServiceTests extends GroovyTestCase { |
---|
13 | MockGSCF gscf |
---|
14 | def synchronizationService |
---|
15 | SessionFactory sessionFactory |
---|
16 | |
---|
17 | @Before |
---|
18 | public void init() { |
---|
19 | // this makes our test URL http://localhost:9432/ |
---|
20 | gscf = new MockGSCF(9432); |
---|
21 | |
---|
22 | def user = new User( identifier: 1, username: 'test' ); |
---|
23 | if( !user.save(flush:true) ) { |
---|
24 | println "Error saving user: " + user.getErrors; |
---|
25 | assert false |
---|
26 | } |
---|
27 | synchronizationService.user = user; |
---|
28 | } |
---|
29 | |
---|
30 | @After |
---|
31 | public void cleanup() { |
---|
32 | gscf.stop() |
---|
33 | } |
---|
34 | |
---|
35 | void testConfig() { |
---|
36 | assert synchronizationService.performSynchronization(); |
---|
37 | } |
---|
38 | |
---|
39 | void testSynchronizeStudies() { |
---|
40 | println "Synchro user: " + synchronizationService.user; |
---|
41 | |
---|
42 | assert Study.count() == 1 // Trashcan study |
---|
43 | |
---|
44 | gscf.response = [] as JSON |
---|
45 | gscf.status = 200 |
---|
46 | |
---|
47 | // No studies have to be synchronized, since there are no studies in the database |
---|
48 | assert synchronizationService.synchronizeStudies().size() == 0 |
---|
49 | |
---|
50 | gscf.setRestResponse( "getStudies", "-", [ |
---|
51 | [ studyToken: "abc", title: "study 1", description: "test study" ], |
---|
52 | [ studyToken: "def", title: "study 2", description: "test study" ] |
---|
53 | ] as JSON ); |
---|
54 | |
---|
55 | gscf.setRestResponse( "getStudies", "abc", [ |
---|
56 | [ studyToken: "abc", title: "study 1", description: "test study" ] |
---|
57 | ] as JSON ); |
---|
58 | |
---|
59 | gscf.setRestResponse( "getStudies", "def", [ |
---|
60 | [ studyToken: "def", title: "study 2", description: "test study" ] |
---|
61 | ] as JSON ); |
---|
62 | |
---|
63 | gscf.setRestResponse( "getAssays", "abc", [ |
---|
64 | [ assayToken: "1a", name: "assay 1a", parentStudyToken: "abc" ], |
---|
65 | [ assayToken: "1b", name: "assay 1b", parentStudyToken: "abc" ] |
---|
66 | ] as JSON ); |
---|
67 | |
---|
68 | gscf.setRestResponse( "getAssays", "def", [ |
---|
69 | [ assayToken: "2a", name: "assay 2a", parentStudyToken: "def" ], |
---|
70 | [ assayToken: "2b", name: "assay 2b", parentStudyToken: "def" ] |
---|
71 | ] as JSON ); |
---|
72 | |
---|
73 | gscf.setRestResponse( "getSamples", "1a", [ |
---|
74 | [ sampleToken: "S1", name: "sample 1" ], |
---|
75 | [ sampleToken: "S2", name: "sample 2" ], |
---|
76 | [ sampleToken: "S3", name: "sample 3" ] |
---|
77 | ] as JSON ); |
---|
78 | |
---|
79 | gscf.setRestResponse( "getSamples", "1b", [ |
---|
80 | [ sampleToken: "S1", name: "sample 1" ], |
---|
81 | [ sampleToken: "S3", name: "sample 3" ] |
---|
82 | ] as JSON ); |
---|
83 | |
---|
84 | gscf.setRestResponse( "getSamples", "2a", [ |
---|
85 | [ sampleToken: "T1", name: "sample 1t" ], |
---|
86 | [ sampleToken: "T3", name: "sample 3t" ] |
---|
87 | ] as JSON ); |
---|
88 | |
---|
89 | gscf.setRestResponse( "getSamples", "2b", [] as JSON ); |
---|
90 | |
---|
91 | gscf.setRestResponse( "getAuthorizationLevel", "abc", [ isOwner: true, canRead: true, canWrite: true ] as JSON ); |
---|
92 | gscf.setRestResponse( "getAuthorizationLevel", "def", [ isOwner: false, canRead: true, canWrite: false ] as JSON ); |
---|
93 | |
---|
94 | synchronizationService.lastFullSynchronization = null |
---|
95 | synchronizationService.fullSynchronization() |
---|
96 | |
---|
97 | Session session = SessionFactoryUtils.getSession( sessionFactory, true ) |
---|
98 | session.flush() |
---|
99 | |
---|
100 | def studies = Study.list(); |
---|
101 | |
---|
102 | assert studies |
---|
103 | assert studies.size() == 3 |
---|
104 | assert studies*.name.contains( "study 1" ); |
---|
105 | assert studies*.name.contains( "study 2" ); |
---|
106 | |
---|
107 | def s1 = Study.findByName( "study 1" ) |
---|
108 | assert s1 |
---|
109 | |
---|
110 | assert s1.canWrite( synchronizationService.user ) |
---|
111 | |
---|
112 | assert s1.assays && s1.assays.size() == 2 |
---|
113 | assert s1.assays*.name.contains( "assay 1a" ) |
---|
114 | assert s1.assays*.name.contains( "assay 1b" ) |
---|
115 | |
---|
116 | assert s1.samples && s1.samples.size() == 3 |
---|
117 | assert s1.samples*.name.contains( "sample 1" ); |
---|
118 | assert s1.samples*.name.contains( "sample 2" ); |
---|
119 | assert s1.samples*.name.contains( "sample 3" ); |
---|
120 | |
---|
121 | def a1 = s1.assays.find { it.name == "assay 1a" } |
---|
122 | assert a1 |
---|
123 | assert a1.assaySamples && a1.assaySamples.size() == 3 |
---|
124 | a1.assaySamples*.sample.name.contains( "sample 1" ) |
---|
125 | |
---|
126 | def s2 = Study.findByName( "study 2" ) |
---|
127 | assert s2 |
---|
128 | |
---|
129 | assert s2.canRead( synchronizationService.user ) |
---|
130 | |
---|
131 | assert s2.assays && s2.assays.size() == 2 |
---|
132 | assert s2.assays*.name.contains( "assay 2a" ) |
---|
133 | assert s2.assays*.name.contains( "assay 2b" ) |
---|
134 | |
---|
135 | assert s2.samples && s2.samples.size() == 2 |
---|
136 | assert s2.samples*.name.contains( "sample 1t" ); |
---|
137 | assert s2.samples*.name.contains( "sample 3t" ); |
---|
138 | |
---|
139 | def a2 = s2.assays.find { it.name == "assay 2a" } |
---|
140 | assert a2 |
---|
141 | assert a2.assaySamples && a2.assaySamples.size() == 2 |
---|
142 | a2.assaySamples*.sample.name.contains( "sample 1t" ) |
---|
143 | |
---|
144 | def a2b = s2.assays.find { it.name == "assay 2b" } |
---|
145 | assert a2b |
---|
146 | assert !a2b.assaySamples || a2b.assaySamples.size() == 0 |
---|
147 | |
---|
148 | /********************************************* |
---|
149 | * |
---|
150 | * Now make a study unreadable |
---|
151 | * |
---|
152 | *********************************************/ |
---|
153 | println "NOW MAKE STUDY UNREADABLE" |
---|
154 | |
---|
155 | gscf.setRestStatus( "getStudies", "def", 401 ); |
---|
156 | gscf.setRestStatus( "getAssays", "def", 401 ); |
---|
157 | |
---|
158 | gscf.setRestResponse( "getAuthorizationLevel", "def", [ isOwner: false, canRead: false, canWrite: false ] as JSON ); |
---|
159 | |
---|
160 | synchronizationService.lastFullSynchronization = null |
---|
161 | synchronizationService.fullSynchronization() |
---|
162 | |
---|
163 | session.flush() |
---|
164 | |
---|
165 | // Now the study should be still available, but not be readable anymore by the logged in user |
---|
166 | studies = Study.list(); |
---|
167 | |
---|
168 | assert studies |
---|
169 | assert studies.size() == 3 |
---|
170 | assert studies*.name.contains( "study 2" ); |
---|
171 | |
---|
172 | s2 = Study.findByName( "study 2" ) |
---|
173 | assert s2 |
---|
174 | |
---|
175 | assert !s2.canRead( synchronizationService.user ) |
---|
176 | assert !s2.canWrite( synchronizationService.user ) |
---|
177 | assert !s2.isOwner( synchronizationService.user ) |
---|
178 | |
---|
179 | assert s2.assays && s2.assays.size() == 2 |
---|
180 | assert s2.assays*.name.contains( "assay 2a" ) |
---|
181 | assert s2.assays*.name.contains( "assay 2b" ) |
---|
182 | |
---|
183 | assert s2.samples && s2.samples.size() == 2 |
---|
184 | assert s2.samples*.name.contains( "sample 1t" ); |
---|
185 | assert s2.samples*.name.contains( "sample 3t" ); |
---|
186 | |
---|
187 | a2 = s2.assays.find { it.name == "assay 2a" } |
---|
188 | assert a2 |
---|
189 | assert a2.assaySamples && a2.assaySamples.size() == 2 |
---|
190 | a2.assaySamples*.sample.name.contains( "sample 1t" ) |
---|
191 | |
---|
192 | a2b = s2.assays.find { it.name == "assay 2b" } |
---|
193 | assert a2b |
---|
194 | assert !a2b.assaySamples || a2b.assaySamples.size() == 0 |
---|
195 | |
---|
196 | /********************************************* |
---|
197 | * |
---|
198 | * Now delete a study |
---|
199 | * |
---|
200 | * To make sure the assays and samples are moved to trash, we should give them some data |
---|
201 | * |
---|
202 | *********************************************/ |
---|
203 | println "NOW DELETE A STUDY" |
---|
204 | |
---|
205 | // Give the assay some data |
---|
206 | a2 = Assay.findByName( "assay 2a" ); |
---|
207 | assert a2 |
---|
208 | |
---|
209 | a2.assaySamples.each { |
---|
210 | it.tagSequence = "ABC"; |
---|
211 | it.save(); |
---|
212 | } |
---|
213 | |
---|
214 | gscf.setRestResponse( "getStudies", "-", [ |
---|
215 | [ studyToken: "abc", title: "study 1", description: "test study" ] |
---|
216 | ] as JSON ); |
---|
217 | |
---|
218 | gscf.setRestStatus( "getStudies", "def", 404 ); |
---|
219 | gscf.setRestStatus( "getAssays", "def", 404 ); |
---|
220 | gscf.setRestStatus( "getAuthorizationLevel", "def", 404 ); |
---|
221 | |
---|
222 | def s = Study.findByStudyToken( "def" ) |
---|
223 | s.isDirty = true |
---|
224 | s.save( flush: true ); |
---|
225 | synchronizationService.synchronizeStudies() |
---|
226 | |
---|
227 | session.flush() |
---|
228 | |
---|
229 | // Now the study should be still available, but not be readable anymore by the logged in user |
---|
230 | studies = Study.list(); |
---|
231 | |
---|
232 | assert studies |
---|
233 | |
---|
234 | studies.each { |
---|
235 | println " Study " + it.name + " - " + it.studyToken |
---|
236 | } |
---|
237 | assert studies.size() == 2 |
---|
238 | assert !studies*.name.contains( "study 2" ); |
---|
239 | |
---|
240 | // Check if data is moved to trash |
---|
241 | def trash = Study.findByTrashcan( true ) |
---|
242 | assert trash |
---|
243 | |
---|
244 | assert trash.assays && trash.assays.size() == 1 |
---|
245 | assert trash.assays*.name.contains( "assay 2a" ) |
---|
246 | assert !trash.assays*.name.contains( "assay 2b" ) |
---|
247 | |
---|
248 | assert trash.samples && trash.samples.size() == 2 |
---|
249 | assert trash.samples*.name.contains( "sample 1t" ); |
---|
250 | assert trash.samples*.name.contains( "sample 3t" ); |
---|
251 | |
---|
252 | a2 = trash.assays.find { it.name == "assay 2a" } |
---|
253 | assert a2 |
---|
254 | assert a2.assaySamples && a2.assaySamples.size() == 2 |
---|
255 | a2.assaySamples*.sample.name.contains( "sample 1t" ) |
---|
256 | |
---|
257 | /********************************************* |
---|
258 | * |
---|
259 | * Now rename a study |
---|
260 | * |
---|
261 | *********************************************/ |
---|
262 | println "NOW RENAME A STUDY" |
---|
263 | |
---|
264 | gscf.setRestResponse( "getStudies", "-", [ |
---|
265 | [ studyToken: "abc", title: "study 3", description: "test study" ] |
---|
266 | ] as JSON ); |
---|
267 | |
---|
268 | gscf.setRestResponse( "getStudies", "abc", [ |
---|
269 | [ studyToken: "abc", title: "study 3", description: "test study" ] |
---|
270 | ] as JSON ); |
---|
271 | |
---|
272 | s = Study.findByStudyToken( "abc" ) |
---|
273 | s.isDirty = true |
---|
274 | s.save( flush: true ); |
---|
275 | synchronizationService.synchronizeStudies() |
---|
276 | |
---|
277 | session.flush() |
---|
278 | |
---|
279 | // Now the study should be still available by the same token, but with a different name |
---|
280 | studies = Study.list(); |
---|
281 | |
---|
282 | assert studies |
---|
283 | |
---|
284 | assert studies.size() == 2 |
---|
285 | assert studies*.name.contains( "study 3" ); |
---|
286 | assert !studies*.name.contains( "study 1" ); |
---|
287 | |
---|
288 | // Check if data is moved to trash |
---|
289 | def newStudy = Study.findByStudyToken( "abc" ); |
---|
290 | |
---|
291 | assert newStudy |
---|
292 | assert newStudy.name == "study 3" |
---|
293 | } |
---|
294 | |
---|
295 | void testSynchronizeAssays() { |
---|
296 | Session session = SessionFactoryUtils.getSession( sessionFactory, true ) |
---|
297 | |
---|
298 | assert Study.count() == 1 // Trashcan study |
---|
299 | |
---|
300 | gscf.response = [] as JSON |
---|
301 | gscf.status = 200 |
---|
302 | |
---|
303 | // No studies have to be synchronized, since there are no studies in the database |
---|
304 | assert synchronizationService.synchronizeStudies().size() == 0 |
---|
305 | |
---|
306 | gscf.setRestResponse( "getStudies", "-", [ |
---|
307 | [ studyToken: "abc", title: "study 1", description: "test study" ], |
---|
308 | [ studyToken: "def", title: "study 2", description: "test study" ] |
---|
309 | ] as JSON ); |
---|
310 | |
---|
311 | gscf.setRestResponse( "getStudies", "abc", [ |
---|
312 | [ studyToken: "abc", title: "study 1", description: "test study" ] |
---|
313 | ] as JSON ); |
---|
314 | |
---|
315 | gscf.setRestResponse( "getStudies", "def", [ |
---|
316 | [ studyToken: "def", title: "study 2", description: "test study" ] |
---|
317 | ] as JSON ); |
---|
318 | |
---|
319 | gscf.setRestResponse( "getAssays", "abc", [ |
---|
320 | [ assayToken: "1a", name: "assay 1a", parentStudyToken: "abc" ], |
---|
321 | [ assayToken: "1b", name: "assay 1b", parentStudyToken: "abc" ] |
---|
322 | ] as JSON ); |
---|
323 | |
---|
324 | gscf.setRestResponse( "getAssays", "def", [ |
---|
325 | [ assayToken: "2a", name: "assay 2a", parentStudyToken: "def" ], |
---|
326 | [ assayToken: "2b", name: "assay 2b", parentStudyToken: "def" ] |
---|
327 | ] as JSON ); |
---|
328 | |
---|
329 | gscf.setRestResponse( "getSamples", "1a", [ |
---|
330 | [ sampleToken: "S1", name: "sample 1" ], |
---|
331 | [ sampleToken: "S2", name: "sample 2" ], |
---|
332 | [ sampleToken: "S3", name: "sample 3" ] |
---|
333 | ] as JSON ); |
---|
334 | |
---|
335 | gscf.setRestResponse( "getSamples", "1b", [ |
---|
336 | [ sampleToken: "S1", name: "sample 1" ], |
---|
337 | [ sampleToken: "S3", name: "sample 3" ] |
---|
338 | ] as JSON ); |
---|
339 | |
---|
340 | gscf.setRestResponse( "getSamples", "2a", [ |
---|
341 | [ sampleToken: "T1", name: "sample 1t" ], |
---|
342 | [ sampleToken: "T3", name: "sample 3t" ] |
---|
343 | ] as JSON ); |
---|
344 | |
---|
345 | gscf.setRestResponse( "getSamples", "2b", [] as JSON ); |
---|
346 | |
---|
347 | gscf.setRestResponse( "getAuthorizationLevel", "abc", [ isOwner: true, canRead: true, canWrite: true ] as JSON ); |
---|
348 | gscf.setRestResponse( "getAuthorizationLevel", "def", [ isOwner: false, canRead: true, canWrite: false ] as JSON ); |
---|
349 | |
---|
350 | synchronizationService.lastFullSynchronization = null |
---|
351 | synchronizationService.fullSynchronization() |
---|
352 | |
---|
353 | def assay1 = Assay.findByAssayToken( "1a" ); |
---|
354 | assert assay1 |
---|
355 | assert assay1.name == "assay 1a"; |
---|
356 | assert assay1.assaySamples?.size() == 3 |
---|
357 | |
---|
358 | def assay2 = Assay.findByAssayToken( "1b" ); |
---|
359 | assert assay2 |
---|
360 | assert assay2.name == "assay 1b"; |
---|
361 | assert assay2.assaySamples?.size() == 2 |
---|
362 | |
---|
363 | /********************************************* |
---|
364 | * |
---|
365 | * Now rename an assay |
---|
366 | * |
---|
367 | ********************************************/ |
---|
368 | println "NOW RENAME AN ASSAY"; |
---|
369 | |
---|
370 | gscf.setRestResponse( "getAssays", "abc", [ |
---|
371 | [ assayToken: "1a", name: "assay 6", parentStudyToken: "abc" ], |
---|
372 | [ assayToken: "1b", name: "assay 7", parentStudyToken: "abc" ] |
---|
373 | ] as JSON ); |
---|
374 | |
---|
375 | def s = Study.findByStudyToken( "abc" ) |
---|
376 | s.isDirty = true |
---|
377 | s.save( flush: true ); |
---|
378 | synchronizationService.synchronizeStudies() |
---|
379 | |
---|
380 | session.flush() |
---|
381 | |
---|
382 | // Now the study should be still available by the same token, but with a different name |
---|
383 | assay1 = Assay.findByAssayToken( "1a" ); |
---|
384 | assert assay1 |
---|
385 | assert assay1.name == "assay 6"; |
---|
386 | assert assay1.assaySamples?.size() == 3 |
---|
387 | |
---|
388 | assay2 = Assay.findByAssayToken( "1b" ); |
---|
389 | assert assay2 |
---|
390 | assert assay2.name == "assay 7"; |
---|
391 | assert assay2.assaySamples?.size() == 2 |
---|
392 | |
---|
393 | /********************************************* |
---|
394 | * |
---|
395 | * Now delete an assay. Put some data in to enforce saving in trashcan |
---|
396 | * |
---|
397 | ********************************************/ |
---|
398 | println "NOW DELETE AN ASSAY"; |
---|
399 | |
---|
400 | // Give the assay some data |
---|
401 | assay1 = Assay.findByAssayToken( "1a" ); |
---|
402 | assert assay1 |
---|
403 | |
---|
404 | assay1.assaySamples.each { |
---|
405 | it.tagSequence = "ABC"; |
---|
406 | it.save(); |
---|
407 | } |
---|
408 | |
---|
409 | gscf.setRestResponse( "getAssays", "abc", [ |
---|
410 | [ assayToken: "1b", name: "assay 9", parentStudyToken: "abc" ] |
---|
411 | ] as JSON ); |
---|
412 | |
---|
413 | s = Study.findByStudyToken( "abc" ) |
---|
414 | s.isDirty = true |
---|
415 | s.save( flush: true ); |
---|
416 | synchronizationService.synchronizeStudies() |
---|
417 | |
---|
418 | session.flush() |
---|
419 | |
---|
420 | // The study still remains |
---|
421 | assert Study.findByStudyToken( "abc" ) |
---|
422 | |
---|
423 | // The first assay should be moved to trash |
---|
424 | assay1 = Assay.findByAssayToken( "1a" ); |
---|
425 | assert !assay1 |
---|
426 | |
---|
427 | // Check if data is moved to trash |
---|
428 | def trash = Study.findByTrashcan( true ) |
---|
429 | assert trash |
---|
430 | |
---|
431 | assert trash.assays && trash.assays.size() == 1 |
---|
432 | assert trash.assays*.name.contains( "assay 6" ) |
---|
433 | |
---|
434 | assert trash.samples && trash.samples.size() == 3 |
---|
435 | assert trash.samples*.name.contains( "sample 1" ); |
---|
436 | assert trash.samples*.name.contains( "sample 2" ); |
---|
437 | assert trash.samples*.name.contains( "sample 3" ); |
---|
438 | |
---|
439 | // Now the assay (2) should be still available by the same token, but with a different name |
---|
440 | assay2 = Assay.findByAssayToken( "1b" ); |
---|
441 | assert assay2 |
---|
442 | assert assay2.name == "assay 9"; |
---|
443 | assert assay2.assaySamples?.size() == 2 |
---|
444 | } |
---|
445 | |
---|
446 | void testSynchronizeSamples() { |
---|
447 | Session session = SessionFactoryUtils.getSession( sessionFactory, true ) |
---|
448 | |
---|
449 | assert Study.count() == 1 // Trashcan study |
---|
450 | |
---|
451 | gscf.response = [] as JSON |
---|
452 | gscf.status = 200 |
---|
453 | |
---|
454 | // No studies have to be synchronized, since there are no studies in the database |
---|
455 | assert synchronizationService.synchronizeStudies().size() == 0 |
---|
456 | |
---|
457 | gscf.setRestResponse( "getStudies", "-", [ |
---|
458 | [ studyToken: "abc", title: "study 1", description: "test study" ], |
---|
459 | [ studyToken: "def", title: "study 2", description: "test study" ] |
---|
460 | ] as JSON ); |
---|
461 | |
---|
462 | gscf.setRestResponse( "getStudies", "abc", [ |
---|
463 | [ studyToken: "abc", title: "study 1", description: "test study" ] |
---|
464 | ] as JSON ); |
---|
465 | |
---|
466 | gscf.setRestResponse( "getStudies", "def", [ |
---|
467 | [ studyToken: "def", title: "study 2", description: "test study" ] |
---|
468 | ] as JSON ); |
---|
469 | |
---|
470 | gscf.setRestResponse( "getAssays", "abc", [ |
---|
471 | [ assayToken: "1a", name: "assay 1a", parentStudyToken: "abc" ], |
---|
472 | [ assayToken: "1b", name: "assay 1b", parentStudyToken: "abc" ] |
---|
473 | ] as JSON ); |
---|
474 | |
---|
475 | gscf.setRestResponse( "getAssays", "def", [ |
---|
476 | [ assayToken: "2a", name: "assay 2a", parentStudyToken: "def" ], |
---|
477 | [ assayToken: "2b", name: "assay 2b", parentStudyToken: "def" ] |
---|
478 | ] as JSON ); |
---|
479 | |
---|
480 | gscf.setRestResponse( "getSamples", "1a", [ |
---|
481 | [ sampleToken: "S1", name: "sample 1" ], |
---|
482 | [ sampleToken: "S2", name: "sample 2" ], |
---|
483 | [ sampleToken: "S3", name: "sample 3" ] |
---|
484 | ] as JSON ); |
---|
485 | |
---|
486 | gscf.setRestResponse( "getSamples", "1b", [ |
---|
487 | [ sampleToken: "S1", name: "sample 1" ], |
---|
488 | [ sampleToken: "S3", name: "sample 3" ] |
---|
489 | ] as JSON ); |
---|
490 | |
---|
491 | gscf.setRestResponse( "getSamples", "2a", [ |
---|
492 | [ sampleToken: "T1", name: "sample 1t" ], |
---|
493 | [ sampleToken: "T3", name: "sample 3t" ] |
---|
494 | ] as JSON ); |
---|
495 | |
---|
496 | gscf.setRestResponse( "getSamples", "2b", [] as JSON ); |
---|
497 | |
---|
498 | gscf.setRestResponse( "getAuthorizationLevel", "abc", [ isOwner: true, canRead: true, canWrite: true ] as JSON ); |
---|
499 | gscf.setRestResponse( "getAuthorizationLevel", "def", [ isOwner: false, canRead: true, canWrite: false ] as JSON ); |
---|
500 | |
---|
501 | synchronizationService.lastFullSynchronization = null |
---|
502 | synchronizationService.fullSynchronization() |
---|
503 | |
---|
504 | def sample1 = Sample.findBySampleToken( "S1" ); |
---|
505 | assert sample1 |
---|
506 | assert sample1.name == "sample 1"; |
---|
507 | assert sample1.assaySamples?.size() == 2 |
---|
508 | |
---|
509 | def sample2 = Sample.findBySampleToken( "S2" ); |
---|
510 | assert sample2 |
---|
511 | assert sample2.name == "sample 2"; |
---|
512 | assert sample2.assaySamples?.size() == 1 |
---|
513 | |
---|
514 | /********************************************* |
---|
515 | * |
---|
516 | * Now rename a sample |
---|
517 | * |
---|
518 | ********************************************/ |
---|
519 | println "NOW RENAME A SAMPLE"; |
---|
520 | |
---|
521 | gscf.setRestResponse( "getSamples", "1a", [ |
---|
522 | [ sampleToken: "S1", name: "sample 6" ], |
---|
523 | [ sampleToken: "S2", name: "sample 2" ], |
---|
524 | [ sampleToken: "S3", name: "sample 8" ] |
---|
525 | ] as JSON ); |
---|
526 | |
---|
527 | gscf.setRestResponse( "getSamples", "1b", [ |
---|
528 | [ sampleToken: "S1", name: "sample 6" ], |
---|
529 | [ sampleToken: "S3", name: "sample 8" ] |
---|
530 | ] as JSON ); |
---|
531 | |
---|
532 | def s = Study.findByStudyToken( "abc" ) |
---|
533 | s.isDirty = true |
---|
534 | s.save( flush: true ); |
---|
535 | synchronizationService.synchronizeStudies() |
---|
536 | |
---|
537 | session.flush() |
---|
538 | |
---|
539 | // Now the sample should be still available by the same token, but with a different name |
---|
540 | sample1 = Sample.findBySampleToken( "S1" ); |
---|
541 | assert sample1 |
---|
542 | assert sample1.name == "sample 6"; |
---|
543 | assert sample1.assaySamples?.size() == 2 |
---|
544 | |
---|
545 | sample2 = Sample.findBySampleToken( "S2" ); |
---|
546 | assert sample2 |
---|
547 | assert sample2.name == "sample 2"; |
---|
548 | assert sample2.assaySamples?.size() == 1 |
---|
549 | |
---|
550 | /********************************************* |
---|
551 | * |
---|
552 | * Now delete a sample. Put some data in to enforce saving in trashcan |
---|
553 | * |
---|
554 | ********************************************/ |
---|
555 | println "NOW DELETE A SAMPLE"; |
---|
556 | |
---|
557 | // Give the assay some data |
---|
558 | def assay1 = Assay.findByAssayToken( "1a" ); |
---|
559 | assert assay1 |
---|
560 | |
---|
561 | assay1.assaySamples.each { |
---|
562 | it.tagSequence = "ABC"; |
---|
563 | it.save(); |
---|
564 | } |
---|
565 | |
---|
566 | gscf.setRestResponse( "getSamples", "1a", [ |
---|
567 | [ sampleToken: "S1", name: "sample 6" ], |
---|
568 | [ sampleToken: "S3", name: "sample 8" ] |
---|
569 | ] as JSON ); |
---|
570 | |
---|
571 | s = Study.findByStudyToken( "abc" ) |
---|
572 | s.isDirty = true |
---|
573 | s.save( flush: true ); |
---|
574 | synchronizationService.synchronizeStudies() |
---|
575 | |
---|
576 | session.flush() |
---|
577 | |
---|
578 | // The study still remains |
---|
579 | assert Study.findByStudyToken( "abc" ) |
---|
580 | assert Assay.findByAssayToken( "1a" ); |
---|
581 | |
---|
582 | // The first sample should be moved to trash |
---|
583 | sample1 = Sample.findBySampleToken( "S2" ); |
---|
584 | assert sample1 |
---|
585 | assert !sample1.assaySamples || sample1.assaySamples.size() == 0 |
---|
586 | |
---|
587 | // Check if data is moved to trash |
---|
588 | def trash = Study.findByTrashcan( true ) |
---|
589 | assert trash |
---|
590 | |
---|
591 | assert trash.assays && trash.assays.size() == 1 |
---|
592 | assert trash.assays*.name.contains( "assay 1a" ) |
---|
593 | |
---|
594 | assert trash.samples && trash.samples.size() == 1 |
---|
595 | assert trash.samples*.name.contains( "sample 2" ); |
---|
596 | } |
---|
597 | |
---|
598 | } |
---|