Statistics
| Branch: | Tag: | Revision:

root / test / gr / ebs / gss / server / ejb / ExternalAPITest.java @ 672:163de098320c

History | View | Annotate | Download (22.5 kB)

1
/*
2
 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
3
 *
4
 * This file is part of GSS.
5
 *
6
 * GSS is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * GSS is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
package gr.ebs.gss.server.ejb;
20

    
21
import gr.ebs.gss.client.exceptions.DuplicateNameException;
22
import gr.ebs.gss.client.exceptions.InsufficientPermissionsException;
23
import gr.ebs.gss.client.exceptions.ObjectNotFoundException;
24
import gr.ebs.gss.server.domain.dto.FileHeaderDTO;
25
import gr.ebs.gss.server.domain.dto.FolderDTO;
26
import gr.ebs.gss.server.domain.dto.GroupDTO;
27
import gr.ebs.gss.server.domain.dto.UserDTO;
28

    
29
import java.util.Iterator;
30
import java.util.List;
31

    
32
import javax.naming.NamingException;
33
import javax.persistence.NoResultException;
34

    
35
import junit.framework.Assert;
36
import junit.framework.TestCase;
37

    
38
/**
39
 * @author chstath
40
 */
41
public class ExternalAPITest extends TestCase {
42

    
43
        /**
44
         * Utility method for looking up the remote service to be tested
45
         *
46
         * @return ExternalAPI
47
         * @throws NamingException
48
         */
49
        private ExternalAPI getService() throws NamingException {
50
                return new ExternalAPIBean();
51
        }
52

    
53
        /**
54
         * Test method for
55
         * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getRootFolder(java.lang.Long)}.
56
         * Tests with normal userId, fails if null is returned
57
         */
58
        public final void testGetRootFolderNormal() {
59
                try {
60
                        final ExternalAPI service = getService();
61
                        final FolderDTO f = service.getRootFolder(Long.valueOf(1));
62
                        Assert.assertNotNull(f);
63
                } catch (final Exception e) {
64
                        e.printStackTrace();
65
                        Assert.fail();
66
                }
67
        }
68

    
69
        /**
70
         * Test method for
71
         * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getRootFolder(java.lang.Long)}.
72
         * Tests with null userId, fails if {@link IllegalArgumentException} is not
73
         * thrown
74
         */
75
        public final void testGetRootFolderWithNullUserId() {
76
                try {
77
                        final ExternalAPI service = getService();
78
                        service.getRootFolder(null);
79
                        Assert.fail();
80
                } catch (final Exception e) {
81
                        if (!(e instanceof ObjectNotFoundException)) {
82
                                e.printStackTrace();
83
                                Assert.fail();
84
                        }
85
                }
86
        }
87

    
88
        /**
89
         * Test method for
90
         * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getRootFolder(java.lang.Long)}.
91
         * Tests with userId which has no folder, fails if {@link NoResultException}
92
         * is not thrown
93
         */
94
        public final void testGetRootFolderWithUserWithoutFolder() {
95
                try {
96
                        final ExternalAPI service = getService();
97
                        service.getRootFolder(Long.valueOf(2));
98
                        Assert.fail();
99
                } catch (final ObjectNotFoundException e) {
100
                } catch (final Exception e) {
101
                        e.printStackTrace();
102
                        Assert.fail();
103
                }
104
        }
105

    
106
        /**
107
         * Test method for
108
         * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getRootFolder(java.lang.Long)}.
109
         * Tests with non-existent userId, fails if {@link NoResultException} is not
110
         * thrown
111
         */
112
        public final void testGetRootFolderWithNonExistentUserId() {
113
                try {
114
                        final ExternalAPI service = getService();
115
                        service.getRootFolder(Long.valueOf(-1));
116
                        Assert.fail();
117
                } catch (final ObjectNotFoundException e) {
118
                } catch (final Exception e) {
119
                        e.printStackTrace();
120
                        Assert.fail();
121
                }
122
        }
123

    
124
        /**
125
         * Test method for
126
         * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getFiles(java.lang.Long,java.lang.Long,boolean)}.
127
         * Tests with normal folderId, fails if null or empty list is returned
128
         */
129
        public final void testGetFilesNormal() {
130
                try {
131
                        final ExternalAPI service = getService();
132
                        final List<FileHeaderDTO> files = service.getFiles(new Long(1L), Long.valueOf(1), true);
133
                        Assert.assertNotNull(files);
134
                        Assert.assertFalse(files.isEmpty());
135
                } catch (final Exception e) {
136
                        e.printStackTrace();
137
                        Assert.fail();
138
                }
139
        }
140

    
141
        /**
142
         * Test method for
143
         * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getFiles(java.lang.Long,java.lang.Long,boolean)}.
144
         * Tests with folderId of empty folder, fails if null or not empty list is
145
         * returned
146
         */
147
        public final void testGetFilesWithEmptyFolder() {
148
                try {
149
                        final ExternalAPI service = getService();
150
                        final List<FileHeaderDTO> files = service.getFiles(new Long(1L), Long.valueOf(2), true);
151
                        Assert.assertNotNull(files);
152
                        Assert.assertTrue(files.isEmpty());
153
                } catch (final Exception e) {
154
                        e.printStackTrace();
155
                        Assert.fail();
156
                }
157
        }
158

    
159
        /**
160
         * Test method for
161
         * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getFiles(java.lang.Long,java.lang.Long,boolean)}.
162
         * Tests with null folderId, fails if {@link IllegalArgumentException} is
163
         * not thrown
164
         */
165
        public final void testGetFilesWithNullFolderId() {
166
                try {
167
                        final ExternalAPI service = getService();
168
                        service.getFiles(new Long(1L), null, true);
169
                        Assert.fail();
170
                } catch (final Exception e) {
171
                        if (!(e instanceof ObjectNotFoundException)) {
172
                                e.printStackTrace();
173
                                Assert.fail();
174
                        }
175
                }
176
        }
177

    
178
        /**
179
         * Test method for
180
         * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getFiles(java.lang.Long,java.lang.Long,boolean)}.
181
         * Tests with folderId of non-existent folder, fails if null or not empty
182
         * list is returned
183
         */
184
        public final void testGetFilesWithNonExistentFolder() {
185
                try {
186
                        final ExternalAPI service = getService();
187
                        final List<FileHeaderDTO> files = service.getFiles(new Long(1L), Long.valueOf(-1), true);
188
                        Assert.assertNotNull(files);
189
                        Assert.assertTrue(files.isEmpty());
190
                } catch (final Exception e) {
191
                        e.printStackTrace();
192
                        Assert.fail();
193
                }
194
        }
195

    
196
        /**
197
         * Tests {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getGroups(Long)} for a
198
         * normal user with groups
199
         */
200
        public final void testGetGroupsNormal() {
201
                try {
202
                        final ExternalAPI service = getService();
203
                        final List<GroupDTO> groups = service.getGroups(Long.valueOf(1));
204
                        Assert.assertNotNull(groups);
205
                        Assert.assertFalse(groups.isEmpty());
206
                } catch (final Exception e) {
207
                        e.printStackTrace();
208
                        Assert.fail();
209
                }
210
        }
211

    
212
        /**
213
         * Tests {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getGroups(Long)} for a
214
         * normal user with no groups
215
         */
216
        public final void testGetGroupsForUserWithNoGroups() {
217
                try {
218
                        final ExternalAPI service = getService();
219
                        final List<GroupDTO> groups = service.getGroups(Long.valueOf(2));
220
                        Assert.assertNotNull(groups);
221
                        Assert.assertTrue(groups.isEmpty());
222
                } catch (final Exception e) {
223
                        e.printStackTrace();
224
                        Assert.fail();
225
                }
226
        }
227

    
228
        /**
229
         * Tests {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getGroups(Long)} for a
230
         * null userId
231
         */
232
        public final void testGetGroupsForNullUserId() {
233
                try {
234
                        final ExternalAPI service = getService();
235
                        service.getGroups(null);
236
                        Assert.fail();
237
                } catch (final Exception e) {
238
                        if (!(e instanceof ObjectNotFoundException)) {
239
                                e.printStackTrace();
240
                                Assert.fail();
241
                        }
242
                }
243
        }
244

    
245
        /**
246
         * Tests {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getGroups(Long)} for a
247
         * non-existent user
248
         */
249
        public final void testGetGroupsForNonExistentUser() {
250
                try {
251
                        final ExternalAPI service = getService();
252
                        final List<GroupDTO> groups = service.getGroups(Long.valueOf(-1));
253
                        Assert.assertNotNull(groups);
254
                        Assert.assertTrue(groups.isEmpty());
255
                } catch (final Exception e) {
256
                        e.printStackTrace();
257
                        Assert.fail();
258
                }
259
        }
260

    
261
        /**
262
         * Tests {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getUsers(java.lang.Long,java.lang.Long)} for a
263
         * normal group with users
264
         */
265
        public final void testGetUsersNormal() {
266
                try {
267
                        final ExternalAPI service = getService();
268
                        final List<UserDTO> users = service.getUsers(Long.valueOf(1), Long.valueOf(1));
269
                        Assert.assertNotNull(users);
270
                        Assert.assertFalse(users.isEmpty());
271
                } catch (final Exception e) {
272
                        e.printStackTrace();
273
                        Assert.fail();
274
                }
275
        }
276

    
277
        /**
278
         * Tests {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getUsers(java.lang.Long,java.lang.Long)}
279
         * for an empty group.
280
         */
281
        public final void testGetUsersForEmptyGroup() {
282
                try {
283
                        final ExternalAPI service = getService();
284
                        final List<UserDTO> users = service.getUsers(Long.valueOf(1L), Long.valueOf(2));
285
                        Assert.assertNotNull(users);
286
                        Assert.assertTrue(users.isEmpty());
287
                } catch (final Exception e) {
288
                        e.printStackTrace();
289
                        Assert.fail();
290
                }
291
        }
292

    
293
        /**
294
         * Tests {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getUsers(java.lang.Long,java.lang.Long)}
295
         * for a non-existent group.
296
         */
297
        public final void testGetUsersNonExistentGroup() {
298
                try {
299
                        final ExternalAPI service = getService();
300
                        final List<UserDTO> users = service.getUsers(Long.valueOf(1L), Long.valueOf(-1));
301
                        Assert.assertNotNull(users);
302
                        Assert.assertTrue(users.isEmpty());
303
                } catch (final Exception e) {
304
                        e.printStackTrace();
305
                        Assert.fail();
306
                }
307
        }
308

    
309
        /**
310
         * Tests {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getUsers(java.lang.Long,java.lang.Long)}
311
         * for a null groupId.
312
         */
313
        public final void testGetUsersWithNullGroupId() {
314
                try {
315
                        final ExternalAPI service = getService();
316
                        service.getUsers(Long.valueOf(1L), null);
317
                        Assert.fail();
318
                } catch (final Exception e) {
319
                        if (!(e instanceof ObjectNotFoundException)) {
320
                                e.printStackTrace();
321
                                Assert.fail();
322
                        }
323
                }
324
        }
325

    
326
        /**
327
         * Tests
328
         * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#createFolder(Long, Long, String)}
329
         * with normal parameters
330
         */
331
        public final void testCreateFolderNormal() {
332
                String name = "junitTestFolder";
333
                try {
334
                        final ExternalAPI service = getService();
335
                        final List rootSubfolders = service.getRootFolder(Long.valueOf(1)).getSubfolders();
336
                        boolean ok = false;
337
                        while (!ok) {
338
                                final Iterator i = rootSubfolders.iterator();
339
                                ok = true;
340
                                while (i.hasNext()) {
341
                                        final FolderDTO f = (FolderDTO) i.next();
342
                                        if (f.getName().equals(name)) {
343
                                                name = name + "!";
344
                                                ok = false;
345
                                                break;
346
                                        }
347
                                }
348
                        }
349
                        service.createFolder(Long.valueOf(1), Long.valueOf(1), name);
350
                        final Iterator i = service.getRootFolder(Long.valueOf(1)).getSubfolders().iterator();
351
                        while (i.hasNext()) {
352
                                final FolderDTO f = (FolderDTO) i.next();
353
                                if (f.getName().equals(name))
354
                                        return;
355
                        }
356
                        Assert.fail();
357
                } catch (final Exception e) {
358
                        e.printStackTrace();
359
                        Assert.fail();
360
                }
361
        }
362

    
363
        /**
364
         * Tests
365
         * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#createFolder(Long, Long, String)}
366
         * with an existing folder name
367
         */
368
        public final void testCreateFolderWithExistingName() {
369
                try {
370
                        final ExternalAPI service = getService();
371
                        final List rootSubfolders = service.getRootFolder(Long.valueOf(1)).getSubfolders();
372
                        service.createFolder(Long.valueOf(1), Long.valueOf(1), ((FolderDTO) rootSubfolders.get(0)).getName());
373
                        Assert.fail();
374
                } catch (final Exception e) {
375
                        if (!(e instanceof DuplicateNameException)) {
376
                                e.printStackTrace();
377
                                Assert.fail();
378
                        }
379
                }
380
        }
381

    
382
        /**
383
         * Tests
384
         * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#createFolder(Long, Long, String)}
385
         * with an empty folder name
386
         */
387
        public final void testCreateFolderWithEmptyName() {
388
                try {
389
                        final ExternalAPI service = getService();
390
                        service.createFolder(Long.valueOf(1), Long.valueOf(1), "");
391
                        Assert.fail();
392
                } catch (final Exception e) {
393
                        if (!(e instanceof ObjectNotFoundException)) {
394
                                e.printStackTrace();
395
                                Assert.fail();
396
                        }
397
                }
398
        }
399

    
400
        /**
401
         * Tests
402
         * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#createFolder(Long, Long, String)}
403
         * with a null owner
404
         */
405
        public final void testCreateFolderWithNullOwner() {
406
                try {
407
                        final ExternalAPI service = getService();
408
                        service.createFolder(null, Long.valueOf(1), "test");
409
                        Assert.fail();
410
                } catch (final Exception e) {
411
                        if (!(e instanceof ObjectNotFoundException)) {
412
                                e.printStackTrace();
413
                                Assert.fail();
414
                        }
415
                }
416
        }
417

    
418
        /**
419
         * Tests
420
         * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#createFolder(Long, Long, String)}
421
         * with a non-existent owner
422
         */
423
        public final void testCreateFolderWithNonExistentOwner() {
424
                try {
425
                        final ExternalAPI service = getService();
426
                        service.createFolder(Long.valueOf(-1), Long.valueOf(1), "test");
427
                        Assert.fail();
428
                } catch (final Exception e) {
429
                        if (!(e instanceof ObjectNotFoundException)) {
430
                                e.printStackTrace();
431
                                Assert.fail();
432
                        }
433
                }
434
        }
435

    
436
        /**
437
         * Tests
438
         * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#createFolder(Long, Long, String)}
439
         * with a null parent
440
         */
441
        public final void testCreateFolderWithNullParent() {
442
                try {
443
                        final ExternalAPI service = getService();
444
                        service.createFolder(Long.valueOf(1), null, "test");
445
                        Assert.fail();
446
                } catch (final Exception e) {
447
                        if (!(e instanceof ObjectNotFoundException)) {
448
                                e.printStackTrace();
449
                                Assert.fail();
450
                        }
451
                }
452
        }
453

    
454
        /**
455
         * Tests
456
         * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#createFolder(Long, Long, String)}
457
         * with a non-existent parent
458
         */
459
        public final void testCreateFolderWithNonExistentParent() {
460
                try {
461
                        final ExternalAPI service = getService();
462
                        service.createFolder(Long.valueOf(1), Long.valueOf(-1), "testFolder");
463
                        Assert.fail();
464
                } catch (final Exception e) {
465
                        if (!(e instanceof ObjectNotFoundException)) {
466
                                e.printStackTrace();
467
                                Assert.fail();
468
                        }
469
                }
470
        }
471

    
472
        /**
473
         * Tests
474
         * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#deleteFolder(Long, Long)}
475
         * with normal parameters
476
         */
477
        public final void testDeleteFolderNormal() {
478
                try {
479
                        final String name = "junitTestFolder";
480
                        final ExternalAPI service = getService();
481
                        final Iterator i = service.getRootFolder(Long.valueOf(1)).getSubfolders().iterator();
482
                        while (i.hasNext()) {
483
                                final FolderDTO f = (FolderDTO) i.next();
484
                                if (f.getName().equals(name))
485
                                        service.deleteFolder(Long.valueOf(1), f.getId());
486
                        }
487
                } catch (final Exception e) {
488
                        e.printStackTrace();
489
                        Assert.fail();
490
                }
491
        }
492

    
493
        /**
494
         * Tests
495
         * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#deleteFolder(Long, Long)}
496
         * with null userId
497
         */
498
        public final void testDeleteFolderWithNullUserId() {
499
                try {
500
                        final String name = "deletedFolder";
501
                        final ExternalAPI service = getService();
502
                        Long folderId = null;
503
                        try {
504
                                service.createFolder(Long.valueOf(1), Long.valueOf(1), name);
505
                                final Iterator i = service.getRootFolder(Long.valueOf(1)).getSubfolders().iterator();
506
                                while (i.hasNext()) {
507
                                        final FolderDTO f = (FolderDTO) i.next();
508
                                        if (f.getName().equals(name)) {
509
                                                folderId = f.getId();
510
                                                service.deleteFolder(null, f.getId());
511
                                                Assert.fail();
512
                                        }
513
                                }
514
                        } catch (final Exception e) {
515
                                service.deleteFolder(Long.valueOf(1), folderId);
516
                                if (!(e instanceof ObjectNotFoundException)) {
517
                                        e.printStackTrace();
518
                                        Assert.fail();
519
                                }
520
                        }
521
                } catch (final Exception e) {
522
                        e.printStackTrace();
523
                        Assert.fail();
524
                }
525
        }
526

    
527
        /**
528
         * Tests
529
         * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#deleteFolder(Long, Long)}
530
         * with non-existent user
531
         */
532
        public final void testDeleteFolderWithNonExistentUser() {
533
                try {
534
                        final String name = "deletedFolder";
535
                        final ExternalAPI service = getService();
536
                        Long folderId = null;
537
                        try {
538
                                service.createFolder(Long.valueOf(1), Long.valueOf(1), name);
539
                                final Iterator i = service.getRootFolder(Long.valueOf(1)).getSubfolders().iterator();
540
                                while (i.hasNext()) {
541
                                        final FolderDTO f = (FolderDTO) i.next();
542
                                        if (f.getName().equals(name)) {
543
                                                folderId = f.getId();
544
                                                service.deleteFolder(Long.valueOf(-1), f.getId());
545
                                                Assert.fail();
546
                                        }
547
                                }
548
                        } catch (final Exception e) {
549
                                service.deleteFolder(Long.valueOf(1), folderId);
550
                                if (!(e instanceof ObjectNotFoundException)) {
551
                                        e.printStackTrace();
552
                                        Assert.fail();
553
                                }
554
                        }
555
                } catch (final Exception e) {
556
                        e.printStackTrace();
557
                        Assert.fail();
558
                }
559
        }
560

    
561
        /**
562
         * Tests
563
         * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#deleteFolder(Long, Long)}
564
         * with null folderId
565
         */
566
        public final void testDeleteFolderWithNullFolderId() {
567
                try {
568
                        final ExternalAPI service = getService();
569
                        service.deleteFolder(Long.valueOf(1), null);
570
                        Assert.fail();
571
                } catch (final Exception e) {
572
                        if (!(e instanceof ObjectNotFoundException)) {
573
                                e.printStackTrace();
574
                                Assert.fail();
575
                        }
576
                }
577
        }
578

    
579
        /**
580
         * Tests
581
         * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#deleteFolder(Long, Long)}
582
         * with null folderId
583
         */
584
        public final void testDeleteFolderWithNonExistentFolder() {
585
                try {
586
                        final ExternalAPI service = getService();
587
                        service.deleteFolder(Long.valueOf(1), Long.valueOf(-1));
588
                        Assert.fail();
589
                } catch (final Exception e) {
590
                        if (!(e instanceof ObjectNotFoundException)) {
591
                                e.printStackTrace();
592
                                Assert.fail();
593
                        }
594
                }
595
        }
596

    
597
        /**
598
         * Tests
599
         * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#deleteFolder(Long, Long)}
600
         * with no delete permission
601
         */
602
        public final void testDeleteFolderNoPermission() {
603
                try {
604
                        final String name = "deletedFolder";
605
                        final ExternalAPI service = getService();
606
                        Long folderId = null;
607
                        try {
608
                                service.createFolder(Long.valueOf(1), Long.valueOf(1), name);
609
                                final Iterator i = service.getRootFolder(Long.valueOf(1)).getSubfolders().iterator();
610
                                while (i.hasNext()) {
611
                                        final FolderDTO f = (FolderDTO) i.next();
612
                                        if (f.getName().equals(name)) {
613
                                                folderId = f.getId();
614
                                                service.deleteFolder(Long.valueOf(2), f.getId());
615
                                                Assert.fail();
616
                                        }
617
                                }
618
                        } catch (final Exception e) {
619
                                service.deleteFolder(Long.valueOf(1), folderId);
620
                                if (!(e instanceof InsufficientPermissionsException)) {
621
                                        e.printStackTrace();
622
                                        Assert.fail();
623
                                }
624
                        }
625
                } catch (final Exception e) {
626
                        e.printStackTrace();
627
                        Assert.fail();
628
                }
629
        }
630

    
631
        /**
632
         * Tests {@link ExternalAPIBean#getUserDTO(Long)} with normal parameters
633
         */
634
        public final void testGetUserNormal() {
635
                try {
636
                        final ExternalAPI service = getService();
637
                        final UserDTO user = service.getUserDTO(Long.valueOf(1));
638
                        assertNotNull(user);
639
                        assertNotNull(user.getId());
640
                        assertEquals(user.getId().longValue(), 1L);
641
                } catch (final Exception e) {
642
                        e.printStackTrace();
643
                        Assert.fail();
644
                }
645
        }
646

    
647
        /**
648
         * Tests {@link ExternalAPIBean#getUserDTO(Long)} with null userId
649
         */
650
        public final void testGetUserNullId() {
651
                try {
652
                        final ExternalAPI service = getService();
653
                        service.getUserDTO(null);
654
                        Assert.fail();
655
                } catch (final NamingException e) {
656
                        e.printStackTrace();
657
                        Assert.fail();
658
                } catch (final Exception e) {
659
                        if (!(e instanceof ObjectNotFoundException)) {
660
                                e.printStackTrace();
661
                                Assert.fail();
662
                        }
663
                }
664
        }
665

    
666
        /**
667
         * Tests {@link ExternalAPIBean#getUserDTO(Long)} with non-existent userId
668
         */
669
        public final void testGetUserNonExistentId() {
670
                try {
671
                        final ExternalAPI service = getService();
672
                        service.getUserDTO(Long.valueOf(-1));
673
                        Assert.fail();
674
                } catch (final NamingException e) {
675
                        e.printStackTrace();
676
                        Assert.fail();
677
                } catch (final Exception e) {
678
                        if (!(e instanceof ObjectNotFoundException)) {
679
                                e.printStackTrace();
680
                                Assert.fail();
681
                        }
682
                }
683
        }
684

    
685
        /**
686
         * Tests {@link ExternalAPIBean#createTag(Long, Long, String)} with normal
687
         * parameters
688
         */
689
        public final void testCreateTagNormal() {
690
                try {
691
                        final ExternalAPI service = getService();
692
                        service.createTag(Long.valueOf(1), Long.valueOf(165), "testTag");
693
                } catch (final Exception e) {
694
                        e.printStackTrace();
695
                        Assert.fail();
696
                }
697
        }
698

    
699
        /**
700
         * Tests {@link ExternalAPIBean#createTag(Long, Long, String)} with null
701
         * userId
702
         */
703
        public final void testCreateTagNullUser() {
704
                try {
705
                        final ExternalAPI service = getService();
706
                        service.createTag(null, Long.valueOf(162), "testTag");
707
                        Assert.fail();
708
                } catch (final Exception e) {
709
                        if (!(e instanceof ObjectNotFoundException)) {
710
                                e.printStackTrace();
711
                                Assert.fail();
712
                        }
713
                }
714
        }
715

    
716
        /**
717
         * Tests {@link ExternalAPIBean#createTag(Long, Long, String)} with null
718
         * file
719
         */
720
        public final void testCreateTagNullFile() {
721
                try {
722
                        final ExternalAPI service = getService();
723
                        service.createTag(Long.valueOf(1), null, "testTag");
724
                        Assert.fail();
725
                } catch (final Exception e) {
726
                        if (!(e instanceof ObjectNotFoundException)) {
727
                                e.printStackTrace();
728
                                Assert.fail();
729
                        }
730
                }
731
        }
732

    
733
        /**
734
         * Tests {@link ExternalAPIBean#createTag(Long, Long, String)} with null tag
735
         */
736
        public final void testCreateTagNullTag() {
737
                try {
738
                        final ExternalAPI service = getService();
739
                        service.createTag(Long.valueOf(1), Long.valueOf(162), null);
740
                        Assert.fail();
741
                } catch (final Exception e) {
742
                        if (!(e instanceof ObjectNotFoundException)) {
743
                                e.printStackTrace();
744
                                Assert.fail();
745
                        }
746
                }
747
        }
748

    
749
        /**
750
         * Tests {@link ExternalAPIBean#createTag(Long, Long, String)} with empty
751
         * tag
752
         */
753
        public final void testCreateTagEmptyTag() {
754
                try {
755
                        final ExternalAPI service = getService();
756
                        service.createTag(Long.valueOf(1), Long.valueOf(162), "");
757
                        Assert.fail();
758
                } catch (final Exception e) {
759
                        if (!(e instanceof ObjectNotFoundException)) {
760
                                e.printStackTrace();
761
                                Assert.fail();
762
                        }
763
                }
764
        }
765

    
766
        /**
767
         * Tests {@link ExternalAPIBean#createTag(Long, Long, String)} with non
768
         * existing user
769
         */
770
        public final void testCreateTagNonExistingUser() {
771
                try {
772
                        final ExternalAPI service = getService();
773
                        service.createTag(Long.valueOf(-1), Long.valueOf(162), "testTag");
774
                        Assert.fail();
775
                } catch (final Exception e) {
776
                        if (!(e instanceof ObjectNotFoundException)) {
777
                                e.printStackTrace();
778
                                Assert.fail();
779
                        }
780
                }
781
        }
782

    
783
        /**
784
         * Tests {@link ExternalAPIBean#createTag(Long, Long, String)} with non
785
         * existing file
786
         */
787
        public final void testCreateTagNonExistingFile() {
788
                try {
789
                        final ExternalAPI service = getService();
790
                        service.createTag(Long.valueOf(1), Long.valueOf(-1), "testTag");
791
                        Assert.fail();
792
                } catch (final Exception e) {
793
                        if (!(e instanceof ObjectNotFoundException)) {
794
                                e.printStackTrace();
795
                                Assert.fail();
796
                        }
797
                }
798
        }
799

    
800
        /**
801
         * Tests {@link ExternalAPIBean#copyFile}
802
         *
803
         */
804
        public final void testCopyFile(){
805
                try {
806
                        final ExternalAPI service = getService();
807
                        service.copyFile(Long.valueOf(1), Long.valueOf(14065), Long.valueOf(14067), "papa.txt");
808
                } catch (final Exception e) {
809
                        if (!(e instanceof ObjectNotFoundException)) {
810
                                e.printStackTrace();
811
                                Assert.fail();
812
                        }
813
                }
814
        }
815

    
816
        /**
817
         * Tests {@link ExternalAPIBean#indexFile}
818
         */
819
        public final void testIndexFile() {
820
                try {
821
                        final ExternalAPI service = getService();
822
                        service.indexFile(Long.valueOf(599), false);
823
                } catch (final Exception e) {
824
                        e.printStackTrace();
825
                        Assert.fail();
826
                }
827
        }
828

    
829
        /**
830
         * Tests {@link ExternalAPIBean#indexFile} with delete
831
         */
832
        public final void testDeleteIndexedFile() {
833
                try {
834
                        final ExternalAPI service = getService();
835
                        service.indexFile(Long.valueOf(14076), true);
836
                } catch (final Exception e) {
837
                        e.printStackTrace();
838
                        Assert.fail();
839
                }
840
        }
841

    
842
        /**
843
         * Tests {@link ExternalAPIBean#searchFiles}
844
         */
845
        public final void testSearchFiles() {
846
                try {
847
                        final ExternalAPI service = getService();
848
                        service.searchFiles(Long.valueOf(1), "κείμενο");
849
                } catch (final Exception e) {
850
                        e.printStackTrace();
851
                        Assert.fail();
852
                }
853
        }
854
}