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", subject: "subject 1", event: "blood extraction", startTime: "0s" ], |
---|
75 | [ sampleToken: "S2", name: "sample 2", subject: "subject 2", event: "blood extraction" ], |
---|
76 | [ sampleToken: "S3", name: "sample 3", subject: "subject 3", event: "blood extraction" ] |
---|
77 | ] as JSON ); |
---|
78 | |
---|
79 | gscf.setRestResponse( "getSamples", "1b", [ |
---|
80 | [ sampleToken: "S1", name: "sample 1", subject: "subject 1", event: "blood extraction", startTime: "0s" ], |
---|
81 | [ sampleToken: "S3", name: "sample 3", subject: "subject 3", event: "blood extraction" ] |
---|
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 testsample = s1.samples.find { it.name == "sample 1" } |
---|
122 | assert testsample.subject == "subject 1"; |
---|
123 | assert testsample.event == "blood extraction (0s)" |
---|
124 | |
---|
125 | testsample = s1.samples.find { it.name == "sample 2" } |
---|
126 | assert testsample.subject == "subject 2"; |
---|
127 | assert testsample.event == "blood extraction" |
---|
128 | |
---|
129 | def a1 = s1.assays.find { it.name == "assay 1a" } |
---|
130 | assert a1 |
---|
131 | assert a1.assaySamples && a1.assaySamples.size() == 3 |
---|
132 | a1.assaySamples*.sample.name.contains( "sample 1" ) |
---|
133 | |
---|
134 | def s2 = Study.findByName( "study 2" ) |
---|
135 | assert s2 |
---|
136 | |
---|
137 | assert s2.canRead( synchronizationService.user ) |
---|
138 | |
---|
139 | assert s2.assays && s2.assays.size() == 2 |
---|
140 | assert s2.assays*.name.contains( "assay 2a" ) |
---|
141 | assert s2.assays*.name.contains( "assay 2b" ) |
---|
142 | |
---|
143 | assert s2.samples && s2.samples.size() == 2 |
---|
144 | assert s2.samples*.name.contains( "sample 1t" ); |
---|
145 | assert s2.samples*.name.contains( "sample 3t" ); |
---|
146 | |
---|
147 | def a2 = s2.assays.find { it.name == "assay 2a" } |
---|
148 | assert a2 |
---|
149 | assert a2.assaySamples && a2.assaySamples.size() == 2 |
---|
150 | a2.assaySamples*.sample.name.contains( "sample 1t" ) |
---|
151 | |
---|
152 | def a2b = s2.assays.find { it.name == "assay 2b" } |
---|
153 | assert a2b |
---|
154 | assert !a2b.assaySamples || a2b.assaySamples.size() == 0 |
---|
155 | |
---|
156 | /********************************************* |
---|
157 | * |
---|
158 | * Now make a study unreadable |
---|
159 | * |
---|
160 | *********************************************/ |
---|
161 | println "NOW MAKE STUDY UNREADABLE" |
---|
162 | |
---|
163 | gscf.setRestStatus( "getStudies", "def", 401 ); |
---|
164 | gscf.setRestStatus( "getAssays", "def", 401 ); |
---|
165 | |
---|
166 | gscf.setRestResponse( "getAuthorizationLevel", "def", [ isOwner: false, canRead: false, canWrite: false ] as JSON ); |
---|
167 | |
---|
168 | synchronizationService.lastFullSynchronization = null |
---|
169 | synchronizationService.fullSynchronization() |
---|
170 | |
---|
171 | session.flush() |
---|
172 | |
---|
173 | // Now the study should be still available, but not be readable anymore by the logged in user |
---|
174 | studies = Study.list(); |
---|
175 | |
---|
176 | assert studies |
---|
177 | assert studies.size() == 3 |
---|
178 | assert studies*.name.contains( "study 2" ); |
---|
179 | |
---|
180 | s2 = Study.findByName( "study 2" ) |
---|
181 | assert s2 |
---|
182 | |
---|
183 | assert !s2.canRead( synchronizationService.user ) |
---|
184 | assert !s2.canWrite( synchronizationService.user ) |
---|
185 | assert !s2.isOwner( synchronizationService.user ) |
---|
186 | |
---|
187 | assert s2.assays && s2.assays.size() == 2 |
---|
188 | assert s2.assays*.name.contains( "assay 2a" ) |
---|
189 | assert s2.assays*.name.contains( "assay 2b" ) |
---|
190 | |
---|
191 | assert s2.samples && s2.samples.size() == 2 |
---|
192 | assert s2.samples*.name.contains( "sample 1t" ); |
---|
193 | assert s2.samples*.name.contains( "sample 3t" ); |
---|
194 | |
---|
195 | a2 = s2.assays.find { it.name == "assay 2a" } |
---|
196 | assert a2 |
---|
197 | assert a2.assaySamples && a2.assaySamples.size() == 2 |
---|
198 | a2.assaySamples*.sample.name.contains( "sample 1t" ) |
---|
199 | |
---|
200 | a2b = s2.assays.find { it.name == "assay 2b" } |
---|
201 | assert a2b |
---|
202 | assert !a2b.assaySamples || a2b.assaySamples.size() == 0 |
---|
203 | |
---|
204 | /********************************************* |
---|
205 | * |
---|
206 | * Now delete a study |
---|
207 | * |
---|
208 | * To make sure the assays and samples are moved to trash, we should give them some data |
---|
209 | * |
---|
210 | *********************************************/ |
---|
211 | println "NOW DELETE A STUDY" |
---|
212 | |
---|
213 | // Give the assay some data |
---|
214 | a2 = Assay.findByName( "assay 2a" ); |
---|
215 | assert a2 |
---|
216 | |
---|
217 | a2.assaySamples.each { |
---|
218 | it.tagSequence = "ABC"; |
---|
219 | it.save(); |
---|
220 | } |
---|
221 | |
---|
222 | gscf.setRestResponse( "getStudies", "-", [ |
---|
223 | [ studyToken: "abc", title: "study 1", description: "test study" ] |
---|
224 | ] as JSON ); |
---|
225 | |
---|
226 | gscf.setRestStatus( "getStudies", "def", 404 ); |
---|
227 | gscf.setRestStatus( "getAssays", "def", 404 ); |
---|
228 | gscf.setRestStatus( "getAuthorizationLevel", "def", 404 ); |
---|
229 | |
---|
230 | def s = Study.findByStudyToken( "def" ) |
---|
231 | s.isDirty = true |
---|
232 | s.save( flush: true ); |
---|
233 | synchronizationService.synchronizeStudies() |
---|
234 | |
---|
235 | session.flush() |
---|
236 | |
---|
237 | // Now the study should be still available, but not be readable anymore by the logged in user |
---|
238 | studies = Study.list(); |
---|
239 | |
---|
240 | assert studies |
---|
241 | |
---|
242 | studies.each { |
---|
243 | println " Study " + it.name + " - " + it.studyToken |
---|
244 | } |
---|
245 | assert studies.size() == 2 |
---|
246 | assert !studies*.name.contains( "study 2" ); |
---|
247 | |
---|
248 | // Check if data is moved to trash |
---|
249 | def trash = Study.findByTrashcan( true ) |
---|
250 | assert trash |
---|
251 | |
---|
252 | assert trash.assays && trash.assays.size() == 1 |
---|
253 | assert trash.assays*.name.contains( "assay 2a" ) |
---|
254 | assert !trash.assays*.name.contains( "assay 2b" ) |
---|
255 | |
---|
256 | assert trash.samples && trash.samples.size() == 2 |
---|
257 | assert trash.samples*.name.contains( "sample 1t" ); |
---|
258 | assert trash.samples*.name.contains( "sample 3t" ); |
---|
259 | |
---|
260 | a2 = trash.assays.find { it.name == "assay 2a" } |
---|
261 | assert a2 |
---|
262 | assert a2.assaySamples && a2.assaySamples.size() == 2 |
---|
263 | a2.assaySamples*.sample.name.contains( "sample 1t" ) |
---|
264 | |
---|
265 | /********************************************* |
---|
266 | * |
---|
267 | * Now rename a study |
---|
268 | * |
---|
269 | *********************************************/ |
---|
270 | println "NOW RENAME A STUDY" |
---|
271 | |
---|
272 | gscf.setRestResponse( "getStudies", "-", [ |
---|
273 | [ studyToken: "abc", title: "study 3", description: "test study" ] |
---|
274 | ] as JSON ); |
---|
275 | |
---|
276 | gscf.setRestResponse( "getStudies", "abc", [ |
---|
277 | [ studyToken: "abc", title: "study 3", description: "test study" ] |
---|
278 | ] as JSON ); |
---|
279 | |
---|
280 | s = Study.findByStudyToken( "abc" ) |
---|
281 | s.isDirty = true |
---|
282 | s.save( flush: true ); |
---|
283 | synchronizationService.synchronizeStudies() |
---|
284 | |
---|
285 | session.flush() |
---|
286 | |
---|
287 | // Now the study should be still available by the same token, but with a different name |
---|
288 | studies = Study.list(); |
---|
289 | |
---|
290 | assert studies |
---|
291 | |
---|
292 | assert studies.size() == 2 |
---|
293 | assert studies*.name.contains( "study 3" ); |
---|
294 | assert !studies*.name.contains( "study 1" ); |
---|
295 | |
---|
296 | // Check if data is moved to trash |
---|
297 | def newStudy = Study.findByStudyToken( "abc" ); |
---|
298 | |
---|
299 | assert newStudy |
---|
300 | assert newStudy.name == "study 3" |
---|
301 | } |
---|
302 | |
---|
303 | void testSynchronizeAssays() { |
---|
304 | Session session = SessionFactoryUtils.getSession( sessionFactory, true ) |
---|
305 | |
---|
306 | assert Study.count() == 1 // Trashcan study |
---|
307 | |
---|
308 | gscf.response = [] as JSON |
---|
309 | gscf.status = 200 |
---|
310 | |
---|
311 | // No studies have to be synchronized, since there are no studies in the database |
---|
312 | assert synchronizationService.synchronizeStudies().size() == 0 |
---|
313 | |
---|
314 | gscf.setRestResponse( "getStudies", "-", [ |
---|
315 | [ studyToken: "abc", title: "study 1", description: "test study" ], |
---|
316 | [ studyToken: "def", title: "study 2", description: "test study" ] |
---|
317 | ] as JSON ); |
---|
318 | |
---|
319 | gscf.setRestResponse( "getStudies", "abc", [ |
---|
320 | [ studyToken: "abc", title: "study 1", description: "test study" ] |
---|
321 | ] as JSON ); |
---|
322 | |
---|
323 | gscf.setRestResponse( "getStudies", "def", [ |
---|
324 | [ studyToken: "def", title: "study 2", description: "test study" ] |
---|
325 | ] as JSON ); |
---|
326 | |
---|
327 | gscf.setRestResponse( "getAssays", "abc", [ |
---|
328 | [ assayToken: "1a", name: "assay 1a", parentStudyToken: "abc" ], |
---|
329 | [ assayToken: "1b", name: "assay 1b", parentStudyToken: "abc" ] |
---|
330 | ] as JSON ); |
---|
331 | |
---|
332 | gscf.setRestResponse( "getAssays", "def", [ |
---|
333 | [ assayToken: "2a", name: "assay 2a", parentStudyToken: "def" ], |
---|
334 | [ assayToken: "2b", name: "assay 2b", parentStudyToken: "def" ] |
---|
335 | ] as JSON ); |
---|
336 | |
---|
337 | gscf.setRestResponse( "getSamples", "1a", [ |
---|
338 | [ sampleToken: "S1", name: "sample 1" ], |
---|
339 | [ sampleToken: "S2", name: "sample 2" ], |
---|
340 | [ sampleToken: "S3", name: "sample 3" ] |
---|
341 | ] as JSON ); |
---|
342 | |
---|
343 | gscf.setRestResponse( "getSamples", "1b", [ |
---|
344 | [ sampleToken: "S1", name: "sample 1" ], |
---|
345 | [ sampleToken: "S3", name: "sample 3" ] |
---|
346 | ] as JSON ); |
---|
347 | |
---|
348 | gscf.setRestResponse( "getSamples", "2a", [ |
---|
349 | [ sampleToken: "T1", name: "sample 1t" ], |
---|
350 | [ sampleToken: "T3", name: "sample 3t" ] |
---|
351 | ] as JSON ); |
---|
352 | |
---|
353 | gscf.setRestResponse( "getSamples", "2b", [] as JSON ); |
---|
354 | |
---|
355 | gscf.setRestResponse( "getAuthorizationLevel", "abc", [ isOwner: true, canRead: true, canWrite: true ] as JSON ); |
---|
356 | gscf.setRestResponse( "getAuthorizationLevel", "def", [ isOwner: false, canRead: true, canWrite: false ] as JSON ); |
---|
357 | |
---|
358 | synchronizationService.lastFullSynchronization = null |
---|
359 | synchronizationService.fullSynchronization() |
---|
360 | |
---|
361 | def assay1 = Assay.findByAssayToken( "1a" ); |
---|
362 | assert assay1 |
---|
363 | assert assay1.name == "assay 1a"; |
---|
364 | assert assay1.assaySamples?.size() == 3 |
---|
365 | |
---|
366 | def assay2 = Assay.findByAssayToken( "1b" ); |
---|
367 | assert assay2 |
---|
368 | assert assay2.name == "assay 1b"; |
---|
369 | assert assay2.assaySamples?.size() == 2 |
---|
370 | |
---|
371 | /********************************************* |
---|
372 | * |
---|
373 | * Now rename an assay |
---|
374 | * |
---|
375 | ********************************************/ |
---|
376 | println "NOW RENAME AN ASSAY"; |
---|
377 | |
---|
378 | gscf.setRestResponse( "getAssays", "abc", [ |
---|
379 | [ assayToken: "1a", name: "assay 6", parentStudyToken: "abc" ], |
---|
380 | [ assayToken: "1b", name: "assay 7", parentStudyToken: "abc" ] |
---|
381 | ] as JSON ); |
---|
382 | |
---|
383 | def s = Study.findByStudyToken( "abc" ) |
---|
384 | s.isDirty = true |
---|
385 | s.save( flush: true ); |
---|
386 | synchronizationService.synchronizeStudies() |
---|
387 | |
---|
388 | session.flush() |
---|
389 | |
---|
390 | // Now the study should be still available by the same token, but with a different name |
---|
391 | assay1 = Assay.findByAssayToken( "1a" ); |
---|
392 | assert assay1 |
---|
393 | assert assay1.name == "assay 6"; |
---|
394 | assert assay1.assaySamples?.size() == 3 |
---|
395 | |
---|
396 | assay2 = Assay.findByAssayToken( "1b" ); |
---|
397 | assert assay2 |
---|
398 | assert assay2.name == "assay 7"; |
---|
399 | assert assay2.assaySamples?.size() == 2 |
---|
400 | |
---|
401 | /********************************************* |
---|
402 | * |
---|
403 | * Now delete an assay. Put some data in to enforce saving in trashcan |
---|
404 | * |
---|
405 | ********************************************/ |
---|
406 | println "NOW DELETE AN ASSAY"; |
---|
407 | |
---|
408 | // Give the assay some data |
---|
409 | assay1 = Assay.findByAssayToken( "1a" ); |
---|
410 | assert assay1 |
---|
411 | |
---|
412 | assay1.assaySamples.each { |
---|
413 | it.tagSequence = "ABC"; |
---|
414 | it.save(); |
---|
415 | } |
---|
416 | |
---|
417 | gscf.setRestResponse( "getAssays", "abc", [ |
---|
418 | [ assayToken: "1b", name: "assay 9", parentStudyToken: "abc" ] |
---|
419 | ] as JSON ); |
---|
420 | |
---|
421 | s = Study.findByStudyToken( "abc" ) |
---|
422 | s.isDirty = true |
---|
423 | s.save( flush: true ); |
---|
424 | synchronizationService.synchronizeStudies() |
---|
425 | |
---|
426 | session.flush() |
---|
427 | |
---|
428 | // The study still remains |
---|
429 | assert Study.findByStudyToken( "abc" ) |
---|
430 | |
---|
431 | // The first assay should be moved to trash |
---|
432 | assay1 = Assay.findByAssayToken( "1a" ); |
---|
433 | assert !assay1 |
---|
434 | |
---|
435 | // Check if data is moved to trash |
---|
436 | def trash = Study.findByTrashcan( true ) |
---|
437 | assert trash |
---|
438 | |
---|
439 | assert trash.assays && trash.assays.size() == 1 |
---|
440 | assert trash.assays*.name.contains( "assay 6" ) |
---|
441 | |
---|
442 | assert trash.samples && trash.samples.size() == 3 |
---|
443 | assert trash.samples*.name.contains( "sample 1" ); |
---|
444 | assert trash.samples*.name.contains( "sample 2" ); |
---|
445 | assert trash.samples*.name.contains( "sample 3" ); |
---|
446 | |
---|
447 | // Now the assay (2) should be still available by the same token, but with a different name |
---|
448 | assay2 = Assay.findByAssayToken( "1b" ); |
---|
449 | assert assay2 |
---|
450 | assert assay2.name == "assay 9"; |
---|
451 | assert assay2.assaySamples?.size() == 2 |
---|
452 | } |
---|
453 | |
---|
454 | void testSynchronizeSamples() { |
---|
455 | Session session = SessionFactoryUtils.getSession( sessionFactory, true ) |
---|
456 | |
---|
457 | assert Study.count() == 1 // Trashcan study |
---|
458 | |
---|
459 | gscf.response = [] as JSON |
---|
460 | gscf.status = 200 |
---|
461 | |
---|
462 | // No studies have to be synchronized, since there are no studies in the database |
---|
463 | assert synchronizationService.synchronizeStudies().size() == 0 |
---|
464 | |
---|
465 | gscf.setRestResponse( "getStudies", "-", [ |
---|
466 | [ studyToken: "abc", title: "study 1", description: "test study" ], |
---|
467 | [ studyToken: "def", title: "study 2", description: "test study" ] |
---|
468 | ] as JSON ); |
---|
469 | |
---|
470 | gscf.setRestResponse( "getStudies", "abc", [ |
---|
471 | [ studyToken: "abc", title: "study 1", description: "test study" ] |
---|
472 | ] as JSON ); |
---|
473 | |
---|
474 | gscf.setRestResponse( "getStudies", "def", [ |
---|
475 | [ studyToken: "def", title: "study 2", description: "test study" ] |
---|
476 | ] as JSON ); |
---|
477 | |
---|
478 | gscf.setRestResponse( "getAssays", "abc", [ |
---|
479 | [ assayToken: "1a", name: "assay 1a", parentStudyToken: "abc" ], |
---|
480 | [ assayToken: "1b", name: "assay 1b", parentStudyToken: "abc" ] |
---|
481 | ] as JSON ); |
---|
482 | |
---|
483 | gscf.setRestResponse( "getAssays", "def", [ |
---|
484 | [ assayToken: "2a", name: "assay 2a", parentStudyToken: "def" ], |
---|
485 | [ assayToken: "2b", name: "assay 2b", parentStudyToken: "def" ] |
---|
486 | ] as JSON ); |
---|
487 | |
---|
488 | gscf.setRestResponse( "getSamples", "1a", [ |
---|
489 | [ sampleToken: "S1", name: "sample 1" ], |
---|
490 | [ sampleToken: "S2", name: "sample 2" ], |
---|
491 | [ sampleToken: "S3", name: "sample 3" ] |
---|
492 | ] as JSON ); |
---|
493 | |
---|
494 | gscf.setRestResponse( "getSamples", "1b", [ |
---|
495 | [ sampleToken: "S1", name: "sample 1" ], |
---|
496 | [ sampleToken: "S3", name: "sample 3" ] |
---|
497 | ] as JSON ); |
---|
498 | |
---|
499 | gscf.setRestResponse( "getSamples", "2a", [ |
---|
500 | [ sampleToken: "T1", name: "sample 1t" ], |
---|
501 | [ sampleToken: "T3", name: "sample 3t" ] |
---|
502 | ] as JSON ); |
---|
503 | |
---|
504 | gscf.setRestResponse( "getSamples", "2b", [] as JSON ); |
---|
505 | |
---|
506 | gscf.setRestResponse( "getAuthorizationLevel", "abc", [ isOwner: true, canRead: true, canWrite: true ] as JSON ); |
---|
507 | gscf.setRestResponse( "getAuthorizationLevel", "def", [ isOwner: false, canRead: true, canWrite: false ] as JSON ); |
---|
508 | |
---|
509 | synchronizationService.lastFullSynchronization = null |
---|
510 | synchronizationService.fullSynchronization() |
---|
511 | |
---|
512 | def sample1 = Sample.findBySampleToken( "S1" ); |
---|
513 | assert sample1 |
---|
514 | assert sample1.name == "sample 1"; |
---|
515 | assert sample1.assaySamples?.size() == 2 |
---|
516 | |
---|
517 | def sample2 = Sample.findBySampleToken( "S2" ); |
---|
518 | assert sample2 |
---|
519 | assert sample2.name == "sample 2"; |
---|
520 | assert sample2.assaySamples?.size() == 1 |
---|
521 | |
---|
522 | /********************************************* |
---|
523 | * |
---|
524 | * Now rename a sample |
---|
525 | * |
---|
526 | ********************************************/ |
---|
527 | println "NOW RENAME A SAMPLE"; |
---|
528 | |
---|
529 | gscf.setRestResponse( "getSamples", "1a", [ |
---|
530 | [ sampleToken: "S1", name: "sample 6" ], |
---|
531 | [ sampleToken: "S2", name: "sample 2" ], |
---|
532 | [ sampleToken: "S3", name: "sample 8" ] |
---|
533 | ] as JSON ); |
---|
534 | |
---|
535 | gscf.setRestResponse( "getSamples", "1b", [ |
---|
536 | [ sampleToken: "S1", name: "sample 6" ], |
---|
537 | [ sampleToken: "S3", name: "sample 8" ] |
---|
538 | ] as JSON ); |
---|
539 | |
---|
540 | def s = Study.findByStudyToken( "abc" ) |
---|
541 | s.isDirty = true |
---|
542 | s.save( flush: true ); |
---|
543 | synchronizationService.synchronizeStudies() |
---|
544 | |
---|
545 | session.flush() |
---|
546 | |
---|
547 | // Now the sample should be still available by the same token, but with a different name |
---|
548 | sample1 = Sample.findBySampleToken( "S1" ); |
---|
549 | assert sample1 |
---|
550 | assert sample1.name == "sample 6"; |
---|
551 | assert sample1.assaySamples?.size() == 2 |
---|
552 | |
---|
553 | sample2 = Sample.findBySampleToken( "S2" ); |
---|
554 | assert sample2 |
---|
555 | assert sample2.name == "sample 2"; |
---|
556 | assert sample2.assaySamples?.size() == 1 |
---|
557 | |
---|
558 | /********************************************* |
---|
559 | * |
---|
560 | * Now delete a sample. Put some data in to enforce saving in trashcan |
---|
561 | * |
---|
562 | ********************************************/ |
---|
563 | println "NOW DELETE A SAMPLE"; |
---|
564 | |
---|
565 | // Give the assay some data |
---|
566 | def assay1 = Assay.findByAssayToken( "1a" ); |
---|
567 | assert assay1 |
---|
568 | |
---|
569 | assay1.assaySamples.each { |
---|
570 | it.tagSequence = "ABC"; |
---|
571 | it.save(); |
---|
572 | } |
---|
573 | |
---|
574 | gscf.setRestResponse( "getSamples", "1a", [ |
---|
575 | [ sampleToken: "S1", name: "sample 6" ], |
---|
576 | [ sampleToken: "S3", name: "sample 8" ] |
---|
577 | ] as JSON ); |
---|
578 | |
---|
579 | s = Study.findByStudyToken( "abc" ) |
---|
580 | s.isDirty = true |
---|
581 | s.save( flush: true ); |
---|
582 | synchronizationService.synchronizeStudies() |
---|
583 | |
---|
584 | session.flush() |
---|
585 | |
---|
586 | // The study still remains |
---|
587 | assert Study.findByStudyToken( "abc" ) |
---|
588 | assert Assay.findByAssayToken( "1a" ); |
---|
589 | |
---|
590 | // The first sample should be moved to trash |
---|
591 | sample1 = Sample.findBySampleToken( "S2" ); |
---|
592 | assert sample1 |
---|
593 | assert !sample1.assaySamples || sample1.assaySamples.size() == 0 |
---|
594 | |
---|
595 | // Check if data is moved to trash |
---|
596 | def trash = Study.findByTrashcan( true ) |
---|
597 | assert trash |
---|
598 | |
---|
599 | assert trash.assays && trash.assays.size() == 1 |
---|
600 | assert trash.assays*.name.contains( "assay 1a" ) |
---|
601 | |
---|
602 | assert trash.samples && trash.samples.size() == 1 |
---|
603 | assert trash.samples*.name.contains( "sample 2" ); |
---|
604 | } |
---|
605 | |
---|
606 | } |
---|