use celltable for search results, add (InTrash) next to path for trashed files in...
[pithos] / test / gr / ebs / gss / server / ejb / ExternalAPITest.java
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 static gr.ebs.gss.server.configuration.GSSConfigurationFactory.getConfiguration;
22 import gr.ebs.gss.client.exceptions.DuplicateNameException;
23 import gr.ebs.gss.client.exceptions.InsufficientPermissionsException;
24 import gr.ebs.gss.client.exceptions.ObjectNotFoundException;
25 import gr.ebs.gss.server.domain.dto.FileHeaderDTO;
26 import gr.ebs.gss.server.domain.dto.FolderDTO;
27 import gr.ebs.gss.server.domain.dto.GroupDTO;
28 import gr.ebs.gss.server.domain.dto.UserDTO;
29
30 import java.util.Hashtable;
31 import java.util.Iterator;
32 import java.util.List;
33
34 import javax.naming.Context;
35 import javax.naming.InitialContext;
36 import javax.naming.NamingException;
37 import javax.persistence.NoResultException;
38 import javax.rmi.PortableRemoteObject;
39
40 import junit.framework.Assert;
41 import junit.framework.TestCase;
42
43 /**
44  * @author chstath
45  */
46 public class ExternalAPITest extends TestCase {
47
48         /**
49          * Utility method for creating and returning a NamingContext for looking
50          * EJBs up in the JNDI
51          *
52          * @return Context
53          * @throws NamingException
54          */
55         private Context getInitialContext() throws NamingException {
56                 final Hashtable<String, String> env = new Hashtable<String, String>();
57                 env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
58                 env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
59                 env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
60                 return new InitialContext(env);
61         }
62
63         /**
64          * Utility method for looking up the remote service to be tested
65          *
66          * @return ExternalAPIRemote
67          * @throws NamingException
68          */
69         private ExternalAPIRemote getService() throws NamingException {
70                 final Context ctx = getInitialContext();
71                 final Object ref = ctx.lookup(getConfiguration().getString("externalApiPath"));
72                 final ExternalAPIRemote service = (ExternalAPIRemote) PortableRemoteObject.narrow(ref, ExternalAPIRemote.class);
73                 return service;
74         }
75
76         /**
77          * Test method for
78          * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getRootFolder(java.lang.Long)}.
79          * Tests with normal userId, fails if null is returned
80          */
81         public final void testGetRootFolderNormal() {
82                 try {
83                         final ExternalAPIRemote service = getService();
84                         final FolderDTO f = service.getRootFolder(Long.valueOf(1));
85                         Assert.assertNotNull(f);
86                 } catch (final Exception e) {
87                         e.printStackTrace();
88                         Assert.fail();
89                 }
90         }
91
92         /**
93          * Test method for
94          * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getRootFolder(java.lang.Long)}.
95          * Tests with null userId, fails if {@link IllegalArgumentException} is not
96          * thrown
97          */
98         public final void testGetRootFolderWithNullUserId() {
99                 try {
100                         final ExternalAPIRemote service = getService();
101                         service.getRootFolder(null);
102                         Assert.fail();
103                 } catch (final Exception e) {
104                         if (!(e instanceof ObjectNotFoundException)) {
105                                 e.printStackTrace();
106                                 Assert.fail();
107                         }
108                 }
109         }
110
111         /**
112          * Test method for
113          * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getRootFolder(java.lang.Long)}.
114          * Tests with userId which has no folder, fails if {@link NoResultException}
115          * is not thrown
116          */
117         public final void testGetRootFolderWithUserWithoutFolder() {
118                 try {
119                         final ExternalAPIRemote service = getService();
120                         service.getRootFolder(Long.valueOf(2));
121                         Assert.fail();
122                 } catch (final ObjectNotFoundException e) {
123                 } catch (final Exception e) {
124                         e.printStackTrace();
125                         Assert.fail();
126                 }
127         }
128
129         /**
130          * Test method for
131          * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getRootFolder(java.lang.Long)}.
132          * Tests with non-existent userId, fails if {@link NoResultException} is not
133          * thrown
134          */
135         public final void testGetRootFolderWithNonExistentUserId() {
136                 try {
137                         final ExternalAPIRemote service = getService();
138                         service.getRootFolder(Long.valueOf(-1));
139                         Assert.fail();
140                 } catch (final ObjectNotFoundException e) {
141                 } catch (final Exception e) {
142                         e.printStackTrace();
143                         Assert.fail();
144                 }
145         }
146
147         /**
148          * Test method for
149          * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getFiles(java.lang.Long,java.lang.Long,boolean)}.
150          * Tests with normal folderId, fails if null or empty list is returned
151          */
152         public final void testGetFilesNormal() {
153                 try {
154                         final ExternalAPIRemote service = getService();
155                         final List<FileHeaderDTO> files = service.getFiles(new Long(1L), Long.valueOf(1), true);
156                         Assert.assertNotNull(files);
157                         Assert.assertFalse(files.isEmpty());
158                 } catch (final Exception e) {
159                         e.printStackTrace();
160                         Assert.fail();
161                 }
162         }
163
164         /**
165          * Test method for
166          * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getFiles(java.lang.Long,java.lang.Long,boolean)}.
167          * Tests with folderId of empty folder, fails if null or not empty list is
168          * returned
169          */
170         public final void testGetFilesWithEmptyFolder() {
171                 try {
172                         final ExternalAPIRemote service = getService();
173                         final List<FileHeaderDTO> files = service.getFiles(new Long(1L), Long.valueOf(2), true);
174                         Assert.assertNotNull(files);
175                         Assert.assertTrue(files.isEmpty());
176                 } catch (final Exception e) {
177                         e.printStackTrace();
178                         Assert.fail();
179                 }
180         }
181
182         /**
183          * Test method for
184          * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getFiles(java.lang.Long,java.lang.Long,boolean)}.
185          * Tests with null folderId, fails if {@link IllegalArgumentException} is
186          * not thrown
187          */
188         public final void testGetFilesWithNullFolderId() {
189                 try {
190                         final ExternalAPIRemote service = getService();
191                         service.getFiles(new Long(1L), null, true);
192                         Assert.fail();
193                 } catch (final Exception e) {
194                         if (!(e instanceof ObjectNotFoundException)) {
195                                 e.printStackTrace();
196                                 Assert.fail();
197                         }
198                 }
199         }
200
201         /**
202          * Test method for
203          * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getFiles(java.lang.Long,java.lang.Long,boolean)}.
204          * Tests with folderId of non-existent folder, fails if null or not empty
205          * list is returned
206          */
207         public final void testGetFilesWithNonExistentFolder() {
208                 try {
209                         final ExternalAPIRemote service = getService();
210                         final List<FileHeaderDTO> files = service.getFiles(new Long(1L), Long.valueOf(-1), true);
211                         Assert.assertNotNull(files);
212                         Assert.assertTrue(files.isEmpty());
213                 } catch (final Exception e) {
214                         e.printStackTrace();
215                         Assert.fail();
216                 }
217         }
218
219         /**
220          * Tests {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getGroups(Long)} for a
221          * normal user with groups
222          */
223         public final void testGetGroupsNormal() {
224                 try {
225                         final ExternalAPIRemote service = getService();
226                         final List<GroupDTO> groups = service.getGroups(Long.valueOf(1));
227                         Assert.assertNotNull(groups);
228                         Assert.assertFalse(groups.isEmpty());
229                 } catch (final Exception e) {
230                         e.printStackTrace();
231                         Assert.fail();
232                 }
233         }
234
235         /**
236          * Tests {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getGroups(Long)} for a
237          * normal user with no groups
238          */
239         public final void testGetGroupsForUserWithNoGroups() {
240                 try {
241                         final ExternalAPIRemote service = getService();
242                         final List<GroupDTO> groups = service.getGroups(Long.valueOf(2));
243                         Assert.assertNotNull(groups);
244                         Assert.assertTrue(groups.isEmpty());
245                 } catch (final Exception e) {
246                         e.printStackTrace();
247                         Assert.fail();
248                 }
249         }
250
251         /**
252          * Tests {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getGroups(Long)} for a
253          * null userId
254          */
255         public final void testGetGroupsForNullUserId() {
256                 try {
257                         final ExternalAPIRemote service = getService();
258                         service.getGroups(null);
259                         Assert.fail();
260                 } catch (final Exception e) {
261                         if (!(e instanceof ObjectNotFoundException)) {
262                                 e.printStackTrace();
263                                 Assert.fail();
264                         }
265                 }
266         }
267
268         /**
269          * Tests {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getGroups(Long)} for a
270          * non-existent user
271          */
272         public final void testGetGroupsForNonExistentUser() {
273                 try {
274                         final ExternalAPIRemote service = getService();
275                         final List<GroupDTO> groups = service.getGroups(Long.valueOf(-1));
276                         Assert.assertNotNull(groups);
277                         Assert.assertTrue(groups.isEmpty());
278                 } catch (final Exception e) {
279                         e.printStackTrace();
280                         Assert.fail();
281                 }
282         }
283
284         /**
285          * Tests {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getUsers(java.lang.Long,java.lang.Long)} for a
286          * normal group with users
287          */
288         public final void testGetUsersNormal() {
289                 try {
290                         final ExternalAPIRemote service = getService();
291                         final List<UserDTO> users = service.getUsers(Long.valueOf(1), Long.valueOf(1));
292                         Assert.assertNotNull(users);
293                         Assert.assertFalse(users.isEmpty());
294                 } catch (final Exception e) {
295                         e.printStackTrace();
296                         Assert.fail();
297                 }
298         }
299
300         /**
301          * Tests {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getUsers(java.lang.Long,java.lang.Long)}
302          * for an empty group.
303          */
304         public final void testGetUsersForEmptyGroup() {
305                 try {
306                         final ExternalAPIRemote service = getService();
307                         final List<UserDTO> users = service.getUsers(Long.valueOf(1L), Long.valueOf(2));
308                         Assert.assertNotNull(users);
309                         Assert.assertTrue(users.isEmpty());
310                 } catch (final Exception e) {
311                         e.printStackTrace();
312                         Assert.fail();
313                 }
314         }
315
316         /**
317          * Tests {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getUsers(java.lang.Long,java.lang.Long)}
318          * for a non-existent group.
319          */
320         public final void testGetUsersNonExistentGroup() {
321                 try {
322                         final ExternalAPIRemote service = getService();
323                         final List<UserDTO> users = service.getUsers(Long.valueOf(1L), Long.valueOf(-1));
324                         Assert.assertNotNull(users);
325                         Assert.assertTrue(users.isEmpty());
326                 } catch (final Exception e) {
327                         e.printStackTrace();
328                         Assert.fail();
329                 }
330         }
331
332         /**
333          * Tests {@link gr.ebs.gss.server.ejb.ExternalAPIBean#getUsers(java.lang.Long,java.lang.Long)}
334          * for a null groupId.
335          */
336         public final void testGetUsersWithNullGroupId() {
337                 try {
338                         final ExternalAPIRemote service = getService();
339                         service.getUsers(Long.valueOf(1L), null);
340                         Assert.fail();
341                 } catch (final Exception e) {
342                         if (!(e instanceof ObjectNotFoundException)) {
343                                 e.printStackTrace();
344                                 Assert.fail();
345                         }
346                 }
347         }
348
349         /**
350          * Tests
351          * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#createFolder(Long, Long, String)}
352          * with normal parameters
353          */
354         public final void testCreateFolderNormal() {
355                 String name = "junitTestFolder";
356                 try {
357                         final ExternalAPIRemote service = getService();
358                         final List rootSubfolders = service.getRootFolder(Long.valueOf(1)).getSubfolders();
359                         boolean ok = false;
360                         while (!ok) {
361                                 final Iterator i = rootSubfolders.iterator();
362                                 ok = true;
363                                 while (i.hasNext()) {
364                                         final FolderDTO f = (FolderDTO) i.next();
365                                         if (f.getName().equals(name)) {
366                                                 name = name + "!";
367                                                 ok = false;
368                                                 break;
369                                         }
370                                 }
371                         }
372                         service.createFolder(Long.valueOf(1), Long.valueOf(1), name);
373                         final Iterator i = service.getRootFolder(Long.valueOf(1)).getSubfolders().iterator();
374                         while (i.hasNext()) {
375                                 final FolderDTO f = (FolderDTO) i.next();
376                                 if (f.getName().equals(name))
377                                         return;
378                         }
379                         Assert.fail();
380                 } catch (final Exception e) {
381                         e.printStackTrace();
382                         Assert.fail();
383                 }
384         }
385
386         /**
387          * Tests
388          * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#createFolder(Long, Long, String)}
389          * with an existing folder name
390          */
391         public final void testCreateFolderWithExistingName() {
392                 try {
393                         final ExternalAPIRemote service = getService();
394                         final List rootSubfolders = service.getRootFolder(Long.valueOf(1)).getSubfolders();
395                         service.createFolder(Long.valueOf(1), Long.valueOf(1), ((FolderDTO) rootSubfolders.get(0)).getName());
396                         Assert.fail();
397                 } catch (final Exception e) {
398                         if (!(e instanceof DuplicateNameException)) {
399                                 e.printStackTrace();
400                                 Assert.fail();
401                         }
402                 }
403         }
404
405         /**
406          * Tests
407          * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#createFolder(Long, Long, String)}
408          * with an empty folder name
409          */
410         public final void testCreateFolderWithEmptyName() {
411                 try {
412                         final ExternalAPIRemote service = getService();
413                         service.createFolder(Long.valueOf(1), Long.valueOf(1), "");
414                         Assert.fail();
415                 } catch (final Exception e) {
416                         if (!(e instanceof ObjectNotFoundException)) {
417                                 e.printStackTrace();
418                                 Assert.fail();
419                         }
420                 }
421         }
422
423         /**
424          * Tests
425          * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#createFolder(Long, Long, String)}
426          * with a null owner
427          */
428         public final void testCreateFolderWithNullOwner() {
429                 try {
430                         final ExternalAPIRemote service = getService();
431                         service.createFolder(null, Long.valueOf(1), "test");
432                         Assert.fail();
433                 } catch (final Exception e) {
434                         if (!(e instanceof ObjectNotFoundException)) {
435                                 e.printStackTrace();
436                                 Assert.fail();
437                         }
438                 }
439         }
440
441         /**
442          * Tests
443          * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#createFolder(Long, Long, String)}
444          * with a non-existent owner
445          */
446         public final void testCreateFolderWithNonExistentOwner() {
447                 try {
448                         final ExternalAPIRemote service = getService();
449                         service.createFolder(Long.valueOf(-1), Long.valueOf(1), "test");
450                         Assert.fail();
451                 } catch (final Exception e) {
452                         if (!(e instanceof ObjectNotFoundException)) {
453                                 e.printStackTrace();
454                                 Assert.fail();
455                         }
456                 }
457         }
458
459         /**
460          * Tests
461          * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#createFolder(Long, Long, String)}
462          * with a null parent
463          */
464         public final void testCreateFolderWithNullParent() {
465                 try {
466                         final ExternalAPIRemote service = getService();
467                         service.createFolder(Long.valueOf(1), null, "test");
468                         Assert.fail();
469                 } catch (final Exception e) {
470                         if (!(e instanceof ObjectNotFoundException)) {
471                                 e.printStackTrace();
472                                 Assert.fail();
473                         }
474                 }
475         }
476
477         /**
478          * Tests
479          * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#createFolder(Long, Long, String)}
480          * with a non-existent parent
481          */
482         public final void testCreateFolderWithNonExistentParent() {
483                 try {
484                         final ExternalAPIRemote service = getService();
485                         service.createFolder(Long.valueOf(1), Long.valueOf(-1), "testFolder");
486                         Assert.fail();
487                 } catch (final Exception e) {
488                         if (!(e instanceof ObjectNotFoundException)) {
489                                 e.printStackTrace();
490                                 Assert.fail();
491                         }
492                 }
493         }
494
495         /**
496          * Tests
497          * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#deleteFolder(Long, Long)}
498          * with normal parameters
499          */
500         public final void testDeleteFolderNormal() {
501                 try {
502                         final String name = "junitTestFolder";
503                         final ExternalAPIRemote service = getService();
504                         final Iterator i = service.getRootFolder(Long.valueOf(1)).getSubfolders().iterator();
505                         while (i.hasNext()) {
506                                 final FolderDTO f = (FolderDTO) i.next();
507                                 if (f.getName().equals(name))
508                                         service.deleteFolder(Long.valueOf(1), f.getId());
509                         }
510                 } catch (final Exception e) {
511                         e.printStackTrace();
512                         Assert.fail();
513                 }
514         }
515
516         /**
517          * Tests
518          * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#deleteFolder(Long, Long)}
519          * with null userId
520          */
521         public final void testDeleteFolderWithNullUserId() {
522                 try {
523                         final String name = "deletedFolder";
524                         final ExternalAPIRemote service = getService();
525                         Long folderId = null;
526                         try {
527                                 service.createFolder(Long.valueOf(1), Long.valueOf(1), name);
528                                 final Iterator i = service.getRootFolder(Long.valueOf(1)).getSubfolders().iterator();
529                                 while (i.hasNext()) {
530                                         final FolderDTO f = (FolderDTO) i.next();
531                                         if (f.getName().equals(name)) {
532                                                 folderId = f.getId();
533                                                 service.deleteFolder(null, f.getId());
534                                                 Assert.fail();
535                                         }
536                                 }
537                         } catch (final Exception e) {
538                                 service.deleteFolder(Long.valueOf(1), folderId);
539                                 if (!(e instanceof ObjectNotFoundException)) {
540                                         e.printStackTrace();
541                                         Assert.fail();
542                                 }
543                         }
544                 } catch (final Exception e) {
545                         e.printStackTrace();
546                         Assert.fail();
547                 }
548         }
549
550         /**
551          * Tests
552          * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#deleteFolder(Long, Long)}
553          * with non-existent user
554          */
555         public final void testDeleteFolderWithNonExistentUser() {
556                 try {
557                         final String name = "deletedFolder";
558                         final ExternalAPIRemote service = getService();
559                         Long folderId = null;
560                         try {
561                                 service.createFolder(Long.valueOf(1), Long.valueOf(1), name);
562                                 final Iterator i = service.getRootFolder(Long.valueOf(1)).getSubfolders().iterator();
563                                 while (i.hasNext()) {
564                                         final FolderDTO f = (FolderDTO) i.next();
565                                         if (f.getName().equals(name)) {
566                                                 folderId = f.getId();
567                                                 service.deleteFolder(Long.valueOf(-1), f.getId());
568                                                 Assert.fail();
569                                         }
570                                 }
571                         } catch (final Exception e) {
572                                 service.deleteFolder(Long.valueOf(1), folderId);
573                                 if (!(e instanceof ObjectNotFoundException)) {
574                                         e.printStackTrace();
575                                         Assert.fail();
576                                 }
577                         }
578                 } catch (final Exception e) {
579                         e.printStackTrace();
580                         Assert.fail();
581                 }
582         }
583
584         /**
585          * Tests
586          * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#deleteFolder(Long, Long)}
587          * with null folderId
588          */
589         public final void testDeleteFolderWithNullFolderId() {
590                 try {
591                         final ExternalAPIRemote service = getService();
592                         service.deleteFolder(Long.valueOf(1), null);
593                         Assert.fail();
594                 } catch (final Exception e) {
595                         if (!(e instanceof ObjectNotFoundException)) {
596                                 e.printStackTrace();
597                                 Assert.fail();
598                         }
599                 }
600         }
601
602         /**
603          * Tests
604          * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#deleteFolder(Long, Long)}
605          * with null folderId
606          */
607         public final void testDeleteFolderWithNonExistentFolder() {
608                 try {
609                         final ExternalAPIRemote service = getService();
610                         service.deleteFolder(Long.valueOf(1), Long.valueOf(-1));
611                         Assert.fail();
612                 } catch (final Exception e) {
613                         if (!(e instanceof ObjectNotFoundException)) {
614                                 e.printStackTrace();
615                                 Assert.fail();
616                         }
617                 }
618         }
619
620         /**
621          * Tests
622          * {@link gr.ebs.gss.server.ejb.ExternalAPIBean#deleteFolder(Long, Long)}
623          * with no delete permission
624          */
625         public final void testDeleteFolderNoPermission() {
626                 try {
627                         final String name = "deletedFolder";
628                         final ExternalAPIRemote service = getService();
629                         Long folderId = null;
630                         try {
631                                 service.createFolder(Long.valueOf(1), Long.valueOf(1), name);
632                                 final Iterator i = service.getRootFolder(Long.valueOf(1)).getSubfolders().iterator();
633                                 while (i.hasNext()) {
634                                         final FolderDTO f = (FolderDTO) i.next();
635                                         if (f.getName().equals(name)) {
636                                                 folderId = f.getId();
637                                                 service.deleteFolder(Long.valueOf(2), f.getId());
638                                                 Assert.fail();
639                                         }
640                                 }
641                         } catch (final Exception e) {
642                                 service.deleteFolder(Long.valueOf(1), folderId);
643                                 if (!(e instanceof InsufficientPermissionsException)) {
644                                         e.printStackTrace();
645                                         Assert.fail();
646                                 }
647                         }
648                 } catch (final Exception e) {
649                         e.printStackTrace();
650                         Assert.fail();
651                 }
652         }
653
654         /**
655          * Tests {@link ExternalAPIBean#getUserDTO(Long)} with normal parameters
656          */
657         public final void testGetUserNormal() {
658                 try {
659                         final ExternalAPIRemote service = getService();
660                         final UserDTO user = service.getUserDTO(Long.valueOf(1));
661                         assertNotNull(user);
662                         assertNotNull(user.getId());
663                         assertEquals(user.getId().longValue(), 1L);
664                 } catch (final Exception e) {
665                         e.printStackTrace();
666                         Assert.fail();
667                 }
668         }
669
670         /**
671          * Tests {@link ExternalAPIBean#getUserDTO(Long)} with null userId
672          */
673         public final void testGetUserNullId() {
674                 try {
675                         final ExternalAPIRemote service = getService();
676                         service.getUserDTO(null);
677                         Assert.fail();
678                 } catch (final NamingException e) {
679                         e.printStackTrace();
680                         Assert.fail();
681                 } catch (final Exception e) {
682                         if (!(e instanceof ObjectNotFoundException)) {
683                                 e.printStackTrace();
684                                 Assert.fail();
685                         }
686                 }
687         }
688
689         /**
690          * Tests {@link ExternalAPIBean#getUserDTO(Long)} with non-existent userId
691          */
692         public final void testGetUserNonExistentId() {
693                 try {
694                         final ExternalAPIRemote service = getService();
695                         service.getUserDTO(Long.valueOf(-1));
696                         Assert.fail();
697                 } catch (final NamingException e) {
698                         e.printStackTrace();
699                         Assert.fail();
700                 } catch (final Exception e) {
701                         if (!(e instanceof ObjectNotFoundException)) {
702                                 e.printStackTrace();
703                                 Assert.fail();
704                         }
705                 }
706         }
707
708         /**
709          * Tests {@link ExternalAPIBean#createTag(Long, Long, String)} with normal
710          * parameters
711          */
712         public final void testCreateTagNormal() {
713                 try {
714                         final ExternalAPIRemote service = getService();
715                         service.createTag(Long.valueOf(1), Long.valueOf(165), "testTag");
716                 } catch (final Exception e) {
717                         e.printStackTrace();
718                         Assert.fail();
719                 }
720         }
721
722         /**
723          * Tests {@link ExternalAPIBean#createTag(Long, Long, String)} with null
724          * userId
725          */
726         public final void testCreateTagNullUser() {
727                 try {
728                         final ExternalAPIRemote service = getService();
729                         service.createTag(null, Long.valueOf(162), "testTag");
730                         Assert.fail();
731                 } catch (final Exception e) {
732                         if (!(e instanceof ObjectNotFoundException)) {
733                                 e.printStackTrace();
734                                 Assert.fail();
735                         }
736                 }
737         }
738
739         /**
740          * Tests {@link ExternalAPIBean#createTag(Long, Long, String)} with null
741          * file
742          */
743         public final void testCreateTagNullFile() {
744                 try {
745                         final ExternalAPIRemote service = getService();
746                         service.createTag(Long.valueOf(1), null, "testTag");
747                         Assert.fail();
748                 } catch (final Exception e) {
749                         if (!(e instanceof ObjectNotFoundException)) {
750                                 e.printStackTrace();
751                                 Assert.fail();
752                         }
753                 }
754         }
755
756         /**
757          * Tests {@link ExternalAPIBean#createTag(Long, Long, String)} with null tag
758          */
759         public final void testCreateTagNullTag() {
760                 try {
761                         final ExternalAPIRemote service = getService();
762                         service.createTag(Long.valueOf(1), Long.valueOf(162), null);
763                         Assert.fail();
764                 } catch (final Exception e) {
765                         if (!(e instanceof ObjectNotFoundException)) {
766                                 e.printStackTrace();
767                                 Assert.fail();
768                         }
769                 }
770         }
771
772         /**
773          * Tests {@link ExternalAPIBean#createTag(Long, Long, String)} with empty
774          * tag
775          */
776         public final void testCreateTagEmptyTag() {
777                 try {
778                         final ExternalAPIRemote service = getService();
779                         service.createTag(Long.valueOf(1), Long.valueOf(162), "");
780                         Assert.fail();
781                 } catch (final Exception e) {
782                         if (!(e instanceof ObjectNotFoundException)) {
783                                 e.printStackTrace();
784                                 Assert.fail();
785                         }
786                 }
787         }
788
789         /**
790          * Tests {@link ExternalAPIBean#createTag(Long, Long, String)} with non
791          * existing user
792          */
793         public final void testCreateTagNonExistingUser() {
794                 try {
795                         final ExternalAPIRemote service = getService();
796                         service.createTag(Long.valueOf(-1), Long.valueOf(162), "testTag");
797                         Assert.fail();
798                 } catch (final Exception e) {
799                         if (!(e instanceof ObjectNotFoundException)) {
800                                 e.printStackTrace();
801                                 Assert.fail();
802                         }
803                 }
804         }
805
806         /**
807          * Tests {@link ExternalAPIBean#createTag(Long, Long, String)} with non
808          * existing file
809          */
810         public final void testCreateTagNonExistingFile() {
811                 try {
812                         final ExternalAPIRemote service = getService();
813                         service.createTag(Long.valueOf(1), Long.valueOf(-1), "testTag");
814                         Assert.fail();
815                 } catch (final Exception e) {
816                         if (!(e instanceof ObjectNotFoundException)) {
817                                 e.printStackTrace();
818                                 Assert.fail();
819                         }
820                 }
821         }
822
823         /**
824          * Tests {@link ExternalAPIBean#copyFile}
825          *
826          */
827         public final void testCopyFile(){
828                 try {
829                         final ExternalAPIRemote service = getService();
830                         service.copyFile(Long.valueOf(1), Long.valueOf(14065), Long.valueOf(14067), "papa.txt");
831                 } catch (final Exception e) {
832                         if (!(e instanceof ObjectNotFoundException)) {
833                                 e.printStackTrace();
834                                 Assert.fail();
835                         }
836                 }
837         }
838
839         /**
840          * Tests {@link ExternalAPIBean#indexFile}
841          */
842         public final void testIndexFile() {
843                 try {
844                         final ExternalAPIRemote service = getService();
845                         service.indexFile(Long.valueOf(599), false);
846                 } catch (final Exception e) {
847                         e.printStackTrace();
848                         Assert.fail();
849                 }
850         }
851
852         /**
853          * Tests {@link ExternalAPIBean#indexFile} with delete
854          */
855         public final void testDeleteIndexedFile() {
856                 try {
857                         final ExternalAPIRemote service = getService();
858                         service.indexFile(Long.valueOf(14076), true);
859                 } catch (final Exception e) {
860                         e.printStackTrace();
861                         Assert.fail();
862                 }
863         }
864
865         /**
866          * Tests {@link ExternalAPIBean#searchFiles}
867          */
868         public final void testSearchFiles() {
869                 try {
870                         final ExternalAPIRemote service = getService();
871                         service.searchFiles(Long.valueOf(1), "κείμενο");
872                 } catch (final Exception e) {
873                         e.printStackTrace();
874                         Assert.fail();
875                 }
876         }
877 }