View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/filemanager/common/src/java/org/astrogrid/filemanager/common/FileManagerTest.java,v $</cvs:source>
3    * <cvs:author>$Author: clq2 $</cvs:author>
4    * <cvs:date>$Date: 2005/01/28 10:43:58 $</cvs:date>
5    * <cvs:version>$Revision: 1.5 $</cvs:version>
6    * <cvs:log>
7    *   $Log: FileManagerTest.java,v $
8    *   Revision 1.5  2005/01/28 10:43:58  clq2
9    *   dave_dev_200501141257 (filemanager)
10   *
11   *   Revision 1.4.2.4  2005/01/25 11:16:00  dave
12   *   Fixed NullPointer bug in manager.
13   *   Refactored client test case ...
14   *
15   *   Revision 1.4.2.3  2005/01/20 07:17:17  dave
16   *   Added import data from URL to server side logic ....
17   *   Tidied up tabs in some files.
18   *
19   *   Revision 1.4.2.2  2005/01/19 12:55:36  dave
20   *   Added sleep to date tests to avoid race condition ...
21   *
22   *   Revision 1.4.2.1  2005/01/15 08:25:20  dave
23   *   Added file create and modify dates to manager and client API ...
24   *
25   *   Revision 1.4  2005/01/13 17:23:15  jdt
26   *   merges from dave-dev-200412201250
27   *
28   *   Revision 1.3.4.6  2005/01/12 14:58:18  dave
29   *   Removed delete test ..
30   *
31   *   Revision 1.3.4.5  2005/01/12 14:33:48  dave
32   *   Removed System.out.println debug ...
33   *
34   *   Revision 1.3.4.4  2005/01/12 13:16:27  dave
35   *   Changed tabs to spaces ...
36   *
37   *   Revision 1.3.4.3  2005/01/07 12:18:00  dave
38   *   Added StoreClientWrapperTest
39   *   Added StoreFileWrapper
40   *
41   *   Revision 1.3.4.2  2004/12/24 02:42:45  dave
42   *   Changed delete to use ivorn ...
43   *
44   *   Revision 1.3.4.1  2004/12/24 02:05:05  dave
45   *   Refactored exception handling, removing IdentifierException from the public API ...
46   *
47   *   Revision 1.3  2004/12/16 17:25:49  jdt
48   *   merge from dave-dev-200410061224-200412161312
49   *
50   *   Revision 1.1.2.40  2004/12/16 13:12:12  dave
51   *   Comment for the delete test ...
52   *
53   *   Revision 1.1.2.39  2004/12/14 17:29:40  dave
54   *   Added delete from filemanager ....
55   *
56   *   Revision 1.1.2.38  2004/12/14 17:23:36  dave
57   *   Added delete from filemanager ....
58   *
59   *   Revision 1.1.2.37  2004/12/14 16:36:54  dave
60   *   Added delete from filemanager ....
61   *
62   *   Revision 1.1.2.36  2004/12/14 16:25:44  dave
63   *   Added delete from filemanager ....
64   *
65   *   Revision 1.1.2.35  2004/12/14 16:02:10  dave
66   *   Added delete from filemanager ....
67   *
68   *   Revision 1.1.2.34  2004/12/14 15:34:46  dave
69   *   Added 'not there' test for delete ....
70   *
71   *   Revision 1.1.2.33  2004/12/14 14:44:46  dave
72   *   Added test for copy empty location ...
73   *
74   *   Revision 1.1.2.32  2004/12/14 14:26:16  dave
75   *   Added delete to the server API ....
76   *
77   *   Revision 1.1.2.31  2004/12/14 14:21:58  dave
78   *   Added delete to the server API ....
79   *
80   *   Revision 1.1.2.30  2004/12/11 21:19:53  dave
81   *   Added copy accross remote filestore(s) ...
82   *
83   *   Revision 1.1.2.29  2004/12/11 05:59:18  dave
84   *   Added internal copy for nodes ...
85   *   Added local copy for data ...
86   *
87   *   Revision 1.1.2.28  2004/12/10 05:21:25  dave
88   *   Added node and iterator to client API ...
89   *
90   *   Revision 1.1.2.27  2004/12/08 17:54:55  dave
91   *   Added update to FileManager client and server side ...
92   *
93   *   Revision 1.1.2.26  2004/12/08 01:56:04  dave
94   *   Added filestore location to move ...
95   *
96   *   Revision 1.1.2.25  2004/12/06 13:29:02  dave
97   *   Added initial code for move location ....
98   *
99   *   Revision 1.1.2.24  2004/12/04 05:22:21  dave
100  *   Fixed null parent mistake ...
101  *
102  *   Revision 1.1.2.23  2004/12/02 19:11:54  dave
103  *   Added move name and parent to manager ...
104  *
105  *   Revision 1.1.2.22  2004/11/26 05:07:17  dave
106  *   Fixed node tests for integration ...
107  *
108  *   Revision 1.1.2.21  2004/11/24 16:15:08  dave
109  *   Added node functions to client ...
110  *
111  *   Revision 1.1.2.20  2004/11/17 07:56:33  dave
112  *   Added server mock and webapp build scripts ...
113  *
114  *   Revision 1.1.2.19  2004/11/16 03:25:37  dave
115  *   Updated API to use full ivorn rather than ident ...
116  *
117  *   Revision 1.1.2.18  2004/11/13 01:39:03  dave
118  *   Modifications to support the new client API ...
119  *
120  *   Revision 1.1.2.17  2004/11/11 17:53:10  dave
121  *   Removed Node interface from the server side ....
122  *
123  *   Revision 1.1.2.16  2004/11/11 16:36:19  dave
124  *   Changed getChildren to retunr array of names ...
125  *
126  *   Revision 1.1.2.15  2004/11/11 15:41:44  dave
127  *   Renamed importInitEx and exportInitEx back to the original names ...
128  *
129  *   Revision 1.1.2.14  2004/11/11 15:30:37  dave
130  *   Moving manager API to property[] rather than Node.
131  *
132  *   Revision 1.1.2.13  2004/11/10 18:32:57  dave
133  *   Moved getAccount API to use properties ...
134  *
135  *   Revision 1.1.2.12  2004/11/10 17:00:11  dave
136  *   Moving the manager API towards property based rather than node based ...
137  *
138  *   Revision 1.1.2.11  2004/11/06 20:03:17  dave
139  *   Implemented ImportInit and ExportInit using properties
140  *
141  *   Revision 1.1.2.10  2004/11/05 05:58:31  dave
142  *   Refactored the properties handling in importInitEx() ..
143  *
144  *   Revision 1.1.2.9  2004/11/05 02:23:45  dave
145  *   Refactored identifiers are properties ...
146  *
147  *   Revision 1.1.2.8  2004/11/04 02:33:38  dave
148  *   Refactored test to include multiple filestores ...
149  *
150  *   Revision 1.1.2.7  2004/11/02 15:05:13  dave
151  *   Added old path tests back in ...
152  *
153  *   Revision 1.1.2.6  2004/11/01 16:23:22  dave
154  *   Started integrating import and export with FileStore ...
155  *
156  *   Revision 1.1.2.5  2004/10/19 14:52:36  dave
157  *   Refactored container and file into just node.
158  *
159  * </cvs:log>
160  *
161  */
162 package org.astrogrid.filemanager.common ;
163 
164 import java.net.URL ;
165 
166 import java.util.Date ;
167 
168 import java.io.InputStream ;
169 import java.io.OutputStream ;
170 import java.io.ByteArrayOutputStream ;
171 import java.io.FileNotFoundException ;
172 
173 import org.astrogrid.store.Ivorn ;
174 
175 import org.astrogrid.filestore.common.file.FileProperties ;
176 import org.astrogrid.filestore.common.FileStoreInputStream ;
177 import org.astrogrid.filestore.common.FileStoreOutputStream ;
178 import org.astrogrid.filestore.common.transfer.TransferProperties ;
179 import org.astrogrid.filestore.common.transfer.UrlGetTransfer ;
180 
181 import org.astrogrid.filestore.common.transfer.TransferUtil ;
182 
183 import org.astrogrid.filemanager.common.ivorn.FileManagerIvornFactory ;
184 
185 import org.astrogrid.filemanager.common.exception.NodeNotFoundException ;
186 import org.astrogrid.filemanager.common.exception.DuplicateNodeException ;
187 import org.astrogrid.filemanager.common.exception.FileManagerServiceException ;
188 import org.astrogrid.filemanager.common.exception.FileManagerPropertiesException ;
189 
190 /***
191  * A JUnit test case for the file manager service.
192  *
193  */
194 public class FileManagerTest
195     extends BaseTest
196     {
197     /***
198      * A set of ivorn identifiers for our target file stores.
199      *
200      */
201     protected Ivorn[] filestores ;
202 
203     /***
204      * Internal reference to our target service.
205      *
206      */
207     protected FileManager target ;
208 
209     /***
210      * Check that we can create our target service.
211      *
212      */
213     public void testTargetNotNull()
214         throws Exception
215         {
216         assertNotNull(
217             target
218             ) ;
219         }
220 
221     /***
222      * Check that we get the right exception for a null account name.
223      *
224      */
225     public void testAddAccountNull()
226         throws Exception
227         {
228         try {
229             target.addAccount(
230                 null
231                 ) ;
232             }
233         catch (IllegalArgumentException ouch)
234             {
235             return ;
236             }
237         fail("Expected IllegalArgumentException") ;
238         }
239 
240     /***
241      * Check that we can create an account node.
242      *
243      */
244     public void testAddAccount()
245         throws Exception
246         {
247         assertNotNull(
248             target.addAccount(
249                 accountName
250                 )
251             ) ;
252         }
253 
254     /***
255      * Check that we can't create a duplicate account.
256      *
257      */
258     public void testAddAccountDuplicate()
259         throws Exception
260         {
261         assertNotNull(
262             target.addAccount(
263                 accountName
264                 )
265             ) ;
266         try {
267             target.addAccount(
268                 accountName
269                 ) ;
270             }
271         catch (DuplicateNodeException ouch)
272             {
273             return ;
274             }
275         fail("Expected DuplicateNodeException") ;
276         }
277 
278     /***
279      * Check that an account node has an ivorn.
280      *
281      */
282     public void testAddAccountIvorn()
283         throws Exception
284         {
285         //
286         // Create the account home.
287         FileManagerProperties home = new FileManagerProperties(
288             target.addAccount(
289                 accountName
290                 )
291             );
292         //
293         // Check the node ivorn.
294         assertNotNull(
295             home.getManagerResourceIvorn()
296             ) ;
297         }
298 
299     /***
300      * Check that an account node has an ident.
301      *
302      */
303     public void testAddAccountIdent()
304         throws Exception
305         {
306         //
307         // Create the account home.
308         FileManagerProperties home = new FileManagerProperties(
309             target.addAccount(
310                 accountName
311                 )
312             );
313         //
314         // Check the node ident.
315         assertNotNull(
316             home.getManagerResourceIdent()
317             ) ;
318         }
319 
320     /***
321      * Check that an account node has a service Ivorn.
322      *
323      */
324     public void testAddAccountService()
325         throws Exception
326         {
327         //
328         // Create the account home.
329         FileManagerProperties home = new FileManagerProperties(
330             target.addAccount(
331                 accountName
332                 )
333             );
334         //
335         // Check the node ivorn.
336         assertNotNull(
337             home.getManagerServiceIvorn()
338             ) ;
339         }
340 
341     /***
342      * Check that an account node has the right name.
343      *
344      */
345     public void testAddAccountName()
346         throws Exception
347         {
348         //
349         // Create the account home.
350         FileManagerProperties home = new FileManagerProperties(
351             target.addAccount(
352                 accountName
353                 )
354             );
355         //
356         // Check the node name.
357         assertEquals(
358             "home",
359             home.getManagerResourceName()
360             ) ;
361         }
362 
363     /***
364      * Check that we get the right Exception for a null account.
365      *
366      */
367     public void testGetAccountNull()
368         throws Exception
369         {
370         try {
371             target.getAccount(
372                 null
373                 ) ;
374             }
375         catch (IllegalArgumentException ouch)
376             {
377             return ;
378             }
379         fail("Expected IllegalArgumentException") ;
380         }
381 
382     /***
383      * Check that we get the right Exception for an unknown account.
384      *
385      */
386     public void testGetAccountUnknown()
387         throws Exception
388         {
389         try {
390             target.getAccount(
391                 unknownName
392                 ) ;
393             }
394         catch (NodeNotFoundException ouch)
395             {
396             return ;
397             }
398         fail("Expected NodeNotFoundException") ;
399         }
400 
401     /***
402      * Check that we can find an account node.
403      *
404      */
405     public void testGetAccount()
406         throws Exception
407         {
408         //
409         // Create the account home.
410         FileManagerProperties home = new FileManagerProperties(
411             target.addAccount(
412                 accountName
413                 )
414             );
415         //
416         // Get the account home.
417         FileManagerProperties test = new FileManagerProperties(
418             target.getAccount(
419                 accountName
420                 )
421             );
422         //
423         // Check we got the properties back.
424         assertNotNull(
425             test
426             ) ;
427         }
428 
429     /***
430      * Check that an account node has the right name.
431      *
432      */
433     public void testGetAccountName()
434         throws Exception
435         {
436         //
437         // Create the account home.
438         FileManagerProperties home = new FileManagerProperties(
439             target.addAccount(
440                 accountName
441                 )
442             );
443         //
444         // Get the account home.
445         FileManagerProperties test = new FileManagerProperties(
446             target.getAccount(
447                 accountName
448                 )
449             );
450         //
451         // Check the node names are the same.
452         assertEquals(
453             home.getManagerResourceName(),
454             test.getManagerResourceName()
455             ) ;
456         }
457 
458     /***
459      * Check that an account node has the right ivorn.
460      *
461      */
462     public void testGetAccountIvorn()
463         throws Exception
464         {
465         //
466         // Create the account home.
467         FileManagerProperties home = new FileManagerProperties(
468             target.addAccount(
469                 accountName
470                 )
471             );
472         //
473         // Get the account home.
474         FileManagerProperties test = new FileManagerProperties(
475             target.getAccount(
476                 accountName
477                 )
478             );
479         //
480         // Check the node ivorns are the same.
481         assertEquals(
482             home.getManagerResourceIvorn(),
483             test.getManagerResourceIvorn()
484             ) ;
485         }
486 
487     /***
488      * Check that an account node has the right ident.
489      *
490      */
491     public void testGetAccountIdent()
492         throws Exception
493         {
494         //
495         // Create the account home.
496         FileManagerProperties home = new FileManagerProperties(
497             target.addAccount(
498                 accountName
499                 )
500             );
501         //
502         // Get the account home.
503         FileManagerProperties test = new FileManagerProperties(
504             target.getAccount(
505                 accountName
506                 )
507             );
508         //
509         // Check the node idents are the same.
510         assertEquals(
511             home.getManagerResourceIdent(),
512             test.getManagerResourceIdent()
513             ) ;
514         }
515 
516     /***
517      * Check that an account node has the right type.
518      *
519      */
520     public void testGetAccountType()
521         throws Exception
522         {
523         //
524         // Create the account home.
525         FileManagerProperties home = new FileManagerProperties(
526             target.addAccount(
527                 accountName
528                 )
529             );
530         //
531         // Get the account home.
532         FileManagerProperties test = new FileManagerProperties(
533             target.getAccount(
534                 accountName
535                 )
536             );
537         //
538         // Check the node type.
539         assertEquals(
540             FileManagerProperties.CONTAINER_NODE_TYPE,
541             test.getManagerResourceType()
542             ) ;
543         }
544 
545     /***
546      * Check that we get the right exception for a null parent.
547      *
548      */
549     public void testAddNodeNullParent()
550         throws Exception
551         {
552         //
553         // Try adding a node with no parent.
554         try {
555             target.addNode(
556                 null,
557                 "name",
558                 FileManagerProperties.CONTAINER_NODE_TYPE
559                 ) ;
560             }
561         catch (IllegalArgumentException ouch)
562             {
563             return ;
564             }
565         fail("Expected IllegalArgumentException") ;
566         }
567 
568     /***
569      * Check that we get the right exception for a null name.
570      *
571      */
572     public void testAddNodeNullName()
573         throws Exception
574         {
575         //
576         // Create the account home.
577         FileManagerProperties home = new FileManagerProperties(
578             target.addAccount(
579                 accountName
580                 )
581             );
582         //
583         // Try adding a node with no name.
584         try {
585             target.addNode(
586                 home.getManagerResourceIvorn().toString(),
587                 null,
588                 FileManagerProperties.CONTAINER_NODE_TYPE
589                 ) ;
590             }
591         catch (IllegalArgumentException ouch)
592             {
593             return ;
594             }
595         fail("Expected IllegalArgumentException") ;
596         }
597 
598     /***
599      * Check that we get the right exception for a null type.
600      *
601      */
602     public void testAddNodeNullType()
603         throws Exception
604         {
605         //
606         // Create the account home.
607         FileManagerProperties home = new FileManagerProperties(
608             target.addAccount(
609                 accountName
610                 )
611             );
612         //
613         // Try adding a node with no type.
614         try {
615             target.addNode(
616                 home.getManagerResourceIvorn().toString(),
617                 "frog",
618                 null
619                 ) ;
620             }
621         catch (IllegalArgumentException ouch)
622             {
623             return ;
624             }
625         fail("Expected IllegalArgumentException") ;
626         }
627 
628     /***
629      * Check that we get the right exception for an unknown parent.
630      *
631      */
632     public void testAddNodeUnknownParent()
633         throws Exception
634         {
635         try {
636             target.addNode(
637                 "ivo://unknown#unknown",
638                 "name",
639                 FileManagerProperties.CONTAINER_NODE_TYPE
640                 ) ;
641             }
642         catch (NodeNotFoundException ouch)
643             {
644             return ;
645             }
646         fail("Expected NodeNotFoundException") ;
647         }
648 
649     /***
650      * Check that we can add a child node.
651      *
652      */
653     public void testAddContainerChild()
654         throws Exception
655         {
656         //
657         // Create the account home.
658         FileManagerProperties home = new FileManagerProperties(
659             target.addAccount(
660                 accountName
661                 )
662             );
663         //
664         // Add a container node.
665         FileManagerProperties frog = new FileManagerProperties(
666             target.addNode(
667                 home.getManagerResourceIvorn().toString(),
668                 "frog",
669                 FileManagerProperties.CONTAINER_NODE_TYPE
670                 )
671             );
672         //
673         // Check we got a new node.
674         assertNotNull(
675             frog
676             ) ;
677         }
678 
679     /***
680      * Check that a new container has the right name.
681      *
682      */
683     public void testAddContainerName()
684         throws Exception
685         {
686         //
687         // Create the account home.
688         FileManagerProperties home = new FileManagerProperties(
689             target.addAccount(
690                 accountName
691                 )
692             );
693         //
694         // Add a container node.
695         FileManagerProperties frog = new FileManagerProperties(
696             target.addNode(
697                 home.getManagerResourceIvorn().toString(),
698                 "frog",
699                 FileManagerProperties.CONTAINER_NODE_TYPE
700                 )
701             );
702         //
703         // Check it has the right name.
704         assertEquals(
705             "frog",
706             frog.getManagerResourceName()
707             ) ;
708         }
709 
710     /***
711      * Check that a new container has the right type.
712      *
713      */
714     public void testAddContainerType()
715         throws Exception
716         {
717         //
718         // Create the account home.
719         FileManagerProperties home = new FileManagerProperties(
720             target.addAccount(
721                 accountName
722                 )
723             );
724         //
725         // Add a container node.
726         FileManagerProperties frog = new FileManagerProperties(
727             target.addNode(
728                 home.getManagerResourceIvorn().toString(),
729                 "frog",
730                 FileManagerProperties.CONTAINER_NODE_TYPE
731                 )
732             );
733         //
734         // Check it has the right type.
735         assertEquals(
736             FileManagerProperties.CONTAINER_NODE_TYPE,
737             frog.getManagerResourceType()
738             ) ;
739         }
740 
741     /***
742      * Check that a new container has the right parent.
743      *
744      */
745     public void testAddContainerParent()
746         throws Exception
747         {
748         //
749         // Create the account home.
750         FileManagerProperties home = new FileManagerProperties(
751             target.addAccount(
752                 accountName
753                 )
754             );
755         //
756         // Add a container node.
757         FileManagerProperties frog = new FileManagerProperties(
758             target.addNode(
759                 home.getManagerResourceIvorn().toString(),
760                 "frog",
761                 FileManagerProperties.CONTAINER_NODE_TYPE
762                 )
763             );
764         //
765         // Check it has the right type.
766         assertEquals(
767             home.getManagerResourceIvorn(),
768             frog.getManagerParentIvorn()
769             ) ;
770         }
771 
772     /***
773      * Check that we can add a data node.
774      *
775      */
776     public void testAddData()
777         throws Exception
778         {
779         //
780         // Create the account home.
781         FileManagerProperties home = new FileManagerProperties(
782             target.addAccount(
783                 accountName
784                 )
785             );
786         //
787         // Add a data node.
788         FileManagerProperties frog = new FileManagerProperties(
789             target.addNode(
790                 home.getManagerResourceIvorn().toString(),
791                 "frog",
792                 FileManagerProperties.DATA_NODE_TYPE
793                 )
794             );
795         //
796         // Check we got a new node.
797         assertNotNull(
798             frog
799             ) ;
800         }
801 
802     /***
803      * Check that a new data node has the right name.
804      *
805      */
806     public void testAddDataName()
807         throws Exception
808         {
809         //
810         // Create the account home.
811         FileManagerProperties home = new FileManagerProperties(
812             target.addAccount(
813                 accountName
814                 )
815             );
816         //
817         // Add a container node.
818         FileManagerProperties frog = new FileManagerProperties(
819             target.addNode(
820                 home.getManagerResourceIvorn().toString(),
821                 "frog",
822                 FileManagerProperties.DATA_NODE_TYPE
823                 )
824             );
825         //
826         // Check it has the right name.
827         assertEquals(
828             "frog",
829             frog.getManagerResourceName()
830             ) ;
831         }
832 
833     /***
834      * Check that a new data node has the right type.
835      *
836      */
837     public void testAddDataType()
838         throws Exception
839         {
840         //
841         // Create the account home.
842         FileManagerProperties home = new FileManagerProperties(
843             target.addAccount(
844                 accountName
845                 )
846             );
847         //
848         // Add a container node.
849         FileManagerProperties frog = new FileManagerProperties(
850             target.addNode(
851                 home.getManagerResourceIvorn().toString(),
852                 "frog",
853                 FileManagerProperties.DATA_NODE_TYPE
854                 )
855             );
856         //
857         // Check it has the right type.
858         assertEquals(
859             FileManagerProperties.DATA_NODE_TYPE,
860             frog.getManagerResourceType()
861             ) ;
862         }
863 
864     /***
865      * Check that a new data node has the right parent.
866      *
867      */
868     public void testAddDataParent()
869         throws Exception
870         {
871         //
872         // Create the account home.
873         FileManagerProperties home = new FileManagerProperties(
874             target.addAccount(
875                 accountName
876                 )
877             );
878         //
879         // Add a container node.
880         FileManagerProperties frog = new FileManagerProperties(
881             target.addNode(
882                 home.getManagerResourceIvorn().toString(),
883                 "frog",
884                 FileManagerProperties.DATA_NODE_TYPE
885                 )
886             );
887         //
888         // Check it has the right type.
889         assertEquals(
890             home.getManagerResourceIvorn(),
891             frog.getManagerParentIvorn()
892             ) ;
893         }
894 
895     /***
896      * Check that a new data node has the right location.
897      *
898      */
899     public void testAddDataLocation()
900         throws Exception
901         {
902         //
903         // Create the account home.
904         FileManagerProperties home = new FileManagerProperties(
905             target.addAccount(
906                 accountName
907                 )
908             );
909         //
910         // Add a container node.
911         FileManagerProperties frog = new FileManagerProperties(
912             target.addNode(
913                 home.getManagerResourceIvorn().toString(),
914                 "frog",
915                 FileManagerProperties.DATA_NODE_TYPE
916                 )
917             );
918         //
919         // Check the node location.
920         assertNotNull(
921             frog.getManagerLocationIvorn()
922             );
923         assertEquals(
924             filestores[0],
925             frog.getManagerLocationIvorn()
926             );
927         }
928 
929     /***
930      * Check that we can't add a child to a data node.
931      *
932      */
933     public void testAddChildToData()
934         throws Exception
935         {
936         //
937         // Create the account home.
938         FileManagerProperties home = new FileManagerProperties(
939             target.addAccount(
940                 accountName
941                 )
942             );
943         //
944         // Add a data node.
945         FileManagerProperties frog = new FileManagerProperties(
946             target.addNode(
947                 home.getManagerResourceIvorn().toString(),
948                 "frog",
949                 FileManagerProperties.DATA_NODE_TYPE
950                 )
951             );
952         //
953         // Try adding a child node.
954         try {
955             target.addNode(
956                 frog.getManagerResourceIvorn().toString(),
957                 "toad",
958                 FileManagerProperties.DATA_NODE_TYPE
959                 );
960             }
961         catch (UnsupportedOperationException ouch)
962             {
963             return ;
964             }
965         fail("Expected UnsupportedOperationException") ;
966         }
967 
968     /***
969      * Check that we get the right exception for a null ident.
970      *
971      */
972     public void testGetNodeNull()
973         throws Exception
974         {
975         try {
976             target.getNode(
977                 null
978                 ) ;
979             }
980         catch (NodeNotFoundException ouch)
981             {
982             return ;
983             }
984         fail("Expected NodeNotFoundException") ;
985         }
986 
987     /***
988      * Check that we get the right exception for an empty ident.
989      *
990      */
991     public void testGetNodeNone()
992         throws Exception
993         {
994         try {
995             target.getNode(
996                 "ivo://unknown"
997                 ) ;
998             }
999         catch (NodeNotFoundException ouch)
1000             {
1001             return ;
1002             }
1003         fail("Expected NodeNotFoundException") ;
1004         }
1005 
1006     /***
1007      * Check that we get the right exception for an unknown node.
1008      *
1009      */
1010     public void testGetNodeUnknown()
1011         throws Exception
1012         {
1013         try {
1014             target.getNode(
1015                 "ivo://unknown#unknown"
1016                 ) ;
1017             }
1018         catch (NodeNotFoundException ouch)
1019             {
1020             return ;
1021             }
1022         fail("Expected NodeNotFoundException") ;
1023         }
1024 
1025     /***
1026      * Check that we can get a node by identifier.
1027      *
1028      */
1029     public void testGetNodeIvorn()
1030         throws Exception
1031         {
1032         //
1033         // Create the account home.
1034         FileManagerProperties home = new FileManagerProperties(
1035             target.addAccount(
1036                 accountName
1037                 )
1038             );
1039         //
1040         // Add a data node.
1041         FileManagerProperties frog = new FileManagerProperties(
1042             target.addNode(
1043                 home.getManagerResourceIvorn().toString(),
1044                 "frog",
1045                 FileManagerProperties.DATA_NODE_TYPE
1046                 )
1047             );
1048         //
1049         // Get the node properties.
1050         FileManagerProperties toad = new FileManagerProperties(
1051             target.getNode(
1052                 frog.getManagerResourceIvorn().toString()
1053                 )
1054             );
1055         //
1056         // Check the node ivorn.
1057         assertEquals(
1058             frog.getManagerResourceIvorn().toString(),
1059             toad.getManagerResourceIvorn().toString()
1060             ) ;
1061         }
1062 
1063     /***
1064      * Check that a node has the right name.
1065      *
1066      */
1067     public void testGetNodeName()
1068         throws Exception
1069         {
1070         //
1071         // Create the account home.
1072         FileManagerProperties home = new FileManagerProperties(
1073             target.addAccount(
1074                 accountName
1075                 )
1076             );
1077         //
1078         // Add a data node.
1079         FileManagerProperties frog = new FileManagerProperties(
1080             target.addNode(
1081                 home.getManagerResourceIvorn().toString(),
1082                 "frog",
1083                 FileManagerProperties.DATA_NODE_TYPE
1084                 )
1085             );
1086         //
1087         // Get the node properties.
1088         FileManagerProperties toad = new FileManagerProperties(
1089             target.getNode(
1090                 frog.getManagerResourceIvorn().toString()
1091                 )
1092             );
1093         //
1094         // Check the node names are the same.
1095         assertEquals(
1096             frog.getManagerResourceName(),
1097             toad.getManagerResourceName()
1098             ) ;
1099         }
1100 
1101     /***
1102      * Check that a node has the right identifier.
1103      *
1104      */
1105     public void testGetNodeIdent()
1106         throws Exception
1107         {
1108         //
1109         // Create the account home.
1110         FileManagerProperties home = new FileManagerProperties(
1111             target.addAccount(
1112                 accountName
1113                 )
1114             );
1115         //
1116         // Add a data node.
1117         FileManagerProperties frog = new FileManagerProperties(
1118             target.addNode(
1119                 home.getManagerResourceIvorn().toString(),
1120                 "frog",
1121                 FileManagerProperties.DATA_NODE_TYPE
1122                 )
1123             );
1124         //
1125         // Get the node properties.
1126         FileManagerProperties toad = new FileManagerProperties(
1127             target.getNode(
1128                 frog.getManagerResourceIvorn().toString()
1129                 )
1130             );
1131         //
1132         // Check the node idents are the same.
1133         assertEquals(
1134             frog.getManagerResourceIdent(),
1135             toad.getManagerResourceIdent()
1136             ) ;
1137         }
1138 
1139     /***
1140      * Check that a node has the right type.
1141      *
1142      */
1143     public void testGetNodeType()
1144         throws Exception
1145         {
1146         //
1147         // Create the account home.
1148         FileManagerProperties home = new FileManagerProperties(
1149             target.addAccount(
1150                 accountName
1151                 )
1152             );
1153         //
1154         // Add a data node.
1155         FileManagerProperties frog = new FileManagerProperties(
1156             target.addNode(
1157                 home.getManagerResourceIvorn().toString(),
1158                 "frog",
1159                 FileManagerProperties.DATA_NODE_TYPE
1160                 )
1161             );
1162         //
1163         // Get the node properties.
1164         FileManagerProperties toad = new FileManagerProperties(
1165             target.getNode(
1166                 frog.getManagerResourceIvorn().toString()
1167                 )
1168             );
1169         assertEquals(
1170             FileManagerProperties.DATA_NODE_TYPE,
1171             toad.getManagerResourceType()
1172             ) ;
1173         }
1174 
1175     /***
1176      * Check that a node has the right parent.
1177      *
1178      */
1179     public void testGetNodeParent()
1180         throws Exception
1181         {
1182         //
1183         // Create the account home.
1184         FileManagerProperties home = new FileManagerProperties(
1185             target.addAccount(
1186                 accountName
1187                 )
1188             );
1189         //
1190         // Add a data node.
1191         FileManagerProperties frog = new FileManagerProperties(
1192             target.addNode(
1193                 home.getManagerResourceIvorn().toString(),
1194                 "frog",
1195                 FileManagerProperties.DATA_NODE_TYPE
1196                 )
1197             );
1198         //
1199         // Get the node properties.
1200         FileManagerProperties toad = new FileManagerProperties(
1201             target.getNode(
1202                 frog.getManagerResourceIvorn().toString()
1203                 )
1204             );
1205         assertEquals(
1206             home.getManagerResourceIvorn(),
1207             toad.getManagerParentIvorn()
1208             ) ;
1209         }
1210 
1211     /***
1212      * Check that we get the right exception for a null root.
1213      *
1214      */
1215     public void testGetPathNullRoot()
1216         throws Exception
1217         {
1218         //
1219         // Try getting a node with no parent.
1220         try {
1221             target.getChild(
1222                 null,
1223                 "path"
1224                 ) ;
1225             }
1226         catch (IllegalArgumentException ouch)
1227             {
1228             return ;
1229             }
1230         fail("Expected IllegalArgumentException") ;
1231         }
1232 
1233     /***
1234      * Check that we get the right exception for a null path.
1235      *
1236      */
1237     public void testGetPathNullPath()
1238         throws Exception
1239         {
1240         //
1241         // Create the account home.
1242         FileManagerProperties home = new FileManagerProperties(
1243             target.addAccount(
1244                 accountName
1245                 )
1246             );
1247         //
1248         // Try getting a data node with no name.
1249         try {
1250             target.getChild(
1251                 home.getManagerResourceIvorn().toString(),
1252                 null
1253                 ) ;
1254             }
1255         catch (IllegalArgumentException ouch)
1256             {
1257             return ;
1258             }
1259         fail("Expected IllegalArgumentException") ;
1260         }
1261 
1262     /***
1263      * Check that we get the right exception for an unknown parent.
1264      *
1265      */
1266     public void testGetPathUnknownParent()
1267         throws Exception
1268         {
1269         //
1270         // Try getting a node with an unknown parent.
1271         try {
1272             target.getChild(
1273                 "ivo://unknown#unknown",
1274                 "path"
1275                 ) ;
1276             }
1277         catch (NodeNotFoundException ouch)
1278             {
1279             return ;
1280             }
1281         fail("Expected NodeNotFoundException") ;
1282         }
1283 
1284     /***
1285      * Check that we get the right exception for an unknown path.
1286      *
1287      */
1288     public void testGetPathUnknownPath()
1289         throws Exception
1290         {
1291         //
1292         // Create the account home.
1293         FileManagerProperties home = new FileManagerProperties(
1294             target.addAccount(
1295                 accountName
1296                 )
1297             );
1298         //
1299         // Try getting an unknown child.
1300         try {
1301             target.getChild(
1302                 home.getManagerResourceIvorn().toString(),
1303                 "unknown"
1304                 ) ;
1305             }
1306         catch (NodeNotFoundException ouch)
1307             {
1308             return ;
1309             }
1310         fail("Expected NodeNotFoundException") ;
1311         }
1312 
1313     /***
1314      * Check that we can get a node by path.
1315      *
1316      */
1317     public void testGetPath()
1318         throws Exception
1319         {
1320         //
1321         // Create the account home.
1322         FileManagerProperties home = new FileManagerProperties(
1323             target.addAccount(
1324                 accountName
1325                 )
1326             );
1327         //
1328         // Add some nodes.
1329         FileManagerProperties frog = new FileManagerProperties(
1330             target.addNode(
1331                 home.getManagerResourceIvorn().toString(),
1332                 "frog",
1333                 FileManagerProperties.CONTAINER_NODE_TYPE
1334                 )
1335             );
1336         FileManagerProperties toad = new FileManagerProperties(
1337             target.addNode(
1338                 frog.getManagerResourceIvorn().toString(),
1339                 "toad",
1340                 FileManagerProperties.CONTAINER_NODE_TYPE
1341                 )
1342             );
1343         FileManagerProperties newt = new FileManagerProperties(
1344             target.addNode(
1345                 toad.getManagerResourceIvorn().toString(),
1346                 "newt",
1347                 FileManagerProperties.CONTAINER_NODE_TYPE
1348                 )
1349             );
1350         //
1351         // Get a nested child node.
1352         assertNotNull(
1353             target.getChild(
1354                 home.getManagerResourceIvorn().toString(),
1355                 "frog/toad/newt"
1356                 )
1357             ) ;
1358         }
1359 
1360     /***
1361      * Check that we get the right exception for a null ident.
1362      *
1363      */
1364     public void testGetChildrenNullParent()
1365         throws Exception
1366         {
1367         //
1368         // Try getting the children for a null parent.
1369         try {
1370             target.getChildren(
1371                 null
1372                 ) ;
1373             }
1374         catch (IllegalArgumentException ouch)
1375             {
1376             return ;
1377             }
1378         fail("Expected IllegalArgumentException") ;
1379         }
1380 
1381     /***
1382      * Check that we get the right exception for an unknown parent.
1383      *
1384      */
1385     public void testGetChildrenUnknownParent()
1386         throws Exception
1387         {
1388         //
1389         // Try getting the children for an unknown parent.
1390         try {
1391             target.getChildren(
1392                 "ivo://unknown#unknown"
1393                 ) ;
1394             }
1395         catch (NodeNotFoundException ouch)
1396             {
1397             return ;
1398             }
1399         fail("Expected NodeNotFoundException") ;
1400         }
1401 
1402     /***
1403      * Check that we get an empty list of nodes.
1404      *
1405      */
1406     public void testGetChildrenEmpty()
1407         throws Exception
1408         {
1409         //
1410         // Create the account home.
1411         FileManagerProperties home = new FileManagerProperties(
1412             target.addAccount(
1413                 accountName
1414                 )
1415             );
1416         //
1417         // Get the (empty) list of child nodes.
1418         String[] array = target.getChildren(
1419             home.getManagerResourceIvorn().toString()
1420             ) ;
1421         //
1422         // Check the list is empty.
1423         assertEquals(
1424             0,
1425             array.length
1426             ) ;
1427         }
1428 
1429     /***
1430      * Check that we can get a list of child nodes.
1431      *
1432      */
1433     public void testGetChildren()
1434         throws Exception
1435         {
1436         //
1437         // Create the account home.
1438         FileManagerProperties home = new FileManagerProperties(
1439             target.addAccount(
1440                 accountName
1441                 )
1442             );
1443         //
1444         // Add some nodes.
1445         FileManagerProperties frog = new FileManagerProperties(
1446             target.addNode(
1447                 home.getManagerResourceIvorn().toString(),
1448                 "frog",
1449                 FileManagerProperties.CONTAINER_NODE_TYPE
1450                 )
1451             );
1452         FileManagerProperties toad = new FileManagerProperties(
1453             target.addNode(
1454                 home.getManagerResourceIvorn().toString(),
1455                 "toad",
1456                 FileManagerProperties.CONTAINER_NODE_TYPE
1457                 )
1458             );
1459         FileManagerProperties newt = new FileManagerProperties(
1460             target.addNode(
1461                 home.getManagerResourceIvorn().toString(),
1462                 "newt",
1463                 FileManagerProperties.CONTAINER_NODE_TYPE
1464                 )
1465             );
1466         //
1467         // Get the list of child nodes.
1468         String[] array = target.getChildren(
1469             home.getManagerResourceIvorn().toString()
1470             ) ;
1471         //
1472         // Check the list contains three nodes.
1473         assertEquals(
1474             3,
1475             array.length
1476             ) ;
1477         }
1478 
1479     /***
1480      * Check we get the right list of child nodes.
1481      *
1482      */
1483     public void testGetChildrenIvorns()
1484         throws Exception
1485         {
1486         //
1487         // Create the account home.
1488         FileManagerProperties home = new FileManagerProperties(
1489             target.addAccount(
1490                 accountName
1491                 )
1492             );
1493         //
1494         // Add some nodes.
1495         FileManagerProperties frog = new FileManagerProperties(
1496             target.addNode(
1497                 home.getManagerResourceIvorn().toString(),
1498                 "frog",
1499                 FileManagerProperties.CONTAINER_NODE_TYPE
1500                 )
1501             );
1502         FileManagerProperties toad = new FileManagerProperties(
1503             target.addNode(
1504                 home.getManagerResourceIvorn().toString(),
1505                 "toad",
1506                 FileManagerProperties.CONTAINER_NODE_TYPE
1507                 )
1508             );
1509         FileManagerProperties newt = new FileManagerProperties(
1510             target.addNode(
1511                 home.getManagerResourceIvorn().toString(),
1512                 "newt",
1513                 FileManagerProperties.CONTAINER_NODE_TYPE
1514                 )
1515             );
1516         //
1517         // Get the list of child nodes.
1518         String[] array = target.getChildren(
1519             home.getManagerResourceIvorn().toString()
1520             ) ;
1521         //
1522         // Check the list contains the right nodes.
1523         int     totalFound = 0 ;
1524         boolean frogFound  = false ;
1525         boolean toadFound  = false ;
1526         boolean newtFound  = false ;
1527         for (int i = 0 ; i < array.length ; i++)
1528             {
1529             if (array[i].equals(frog.getManagerResourceIvorn().toString()))
1530                 {
1531                 totalFound++;
1532                 frogFound = true ;
1533                 }
1534             if (array[i].equals(toad.getManagerResourceIvorn().toString()))
1535                 {
1536                 totalFound++;
1537                 toadFound = true ;
1538                 }
1539             if (array[i].equals(newt.getManagerResourceIvorn().toString()))
1540                 {
1541                 totalFound++;
1542                 newtFound = true ;
1543                 }
1544             }
1545         assertEquals(
1546             3,
1547             totalFound
1548             ) ;
1549         assertTrue(
1550             frogFound
1551             );
1552         assertTrue(
1553             toadFound
1554             );
1555         assertTrue(
1556             newtFound
1557             );
1558         }
1559 
1560 //
1561 // Check we can get at all of the child nodes ....
1562 //
1563 
1564     /***
1565      * Check that we get an empty list for a data node.
1566      *
1567      */
1568     public void testGetDataChildrenEmpty()
1569         throws Exception
1570         {
1571         //
1572         // Create the account home.
1573         FileManagerProperties home = new FileManagerProperties(
1574             target.addAccount(
1575                 accountName
1576                 )
1577             );
1578         //
1579         // Add a data node.
1580         FileManagerProperties frog = new FileManagerProperties(
1581             target.addNode(
1582                 home.getManagerResourceIvorn().toString(),
1583                 "frog",
1584                 FileManagerProperties.DATA_NODE_TYPE
1585                 )
1586             );
1587         //
1588         // Get the (empty) list of child nodes.
1589         String[] array = target.getChildren(
1590             frog.getManagerResourceIvorn().toString()
1591             ) ;
1592         //
1593         // Check the list is empty.
1594         assertEquals(
1595             0,
1596             array.length
1597             ) ;
1598         }
1599 
1600     /***
1601      * Check that we can get a nested container by path.
1602      *
1603      */
1604     public void testGetContainerByPath()
1605         throws Exception
1606         {
1607         //
1608         // Create the account home.
1609         FileManagerProperties home = new FileManagerProperties(
1610             target.addAccount(
1611                 accountName
1612                 )
1613             );
1614         //
1615         // Add some nested nodes.
1616         FileManagerProperties frog = new FileManagerProperties(
1617             target.addNode(
1618                 home.getManagerResourceIvorn().toString(),
1619                 "frog",
1620                 FileManagerProperties.CONTAINER_NODE_TYPE
1621                 )
1622             );
1623         FileManagerProperties toad = new FileManagerProperties(
1624             target.addNode(
1625                 frog.getManagerResourceIvorn().toString(),
1626                 "toad",
1627                 FileManagerProperties.CONTAINER_NODE_TYPE
1628                 )
1629             );
1630         FileManagerProperties newt = new FileManagerProperties(
1631             target.addNode(
1632                 toad.getManagerResourceIvorn().toString(),
1633                 "newt",
1634                 FileManagerProperties.CONTAINER_NODE_TYPE
1635                 )
1636             );
1637         //
1638         // Check we can access the nodes path.
1639         assertNotNull(
1640             target.getChild(
1641                 home.getManagerResourceIvorn().toString(),
1642                 "frog"
1643                 )
1644             ) ;
1645         assertNotNull(
1646             target.getChild(
1647                 home.getManagerResourceIvorn().toString(),
1648                 "frog/toad"
1649                 )
1650             ) ;
1651         assertNotNull(
1652             target.getChild(
1653                 home.getManagerResourceIvorn().toString(),
1654                 "frog/toad/newt"
1655                 )
1656             ) ;
1657 
1658         assertNotNull(
1659             target.getChild(
1660                 home.getManagerResourceIvorn().toString(),
1661                 "/frog"
1662                 )
1663             ) ;
1664         assertNotNull(
1665             target.getChild(
1666                 home.getManagerResourceIvorn().toString(),
1667                 "/frog/toad"
1668                 )
1669             ) ;
1670         assertNotNull(
1671             target.getChild(
1672                 home.getManagerResourceIvorn().toString(),
1673                 "/frog/toad/newt"
1674                 )
1675             ) ;
1676 
1677         assertNotNull(
1678             target.getChild(
1679                 home.getManagerResourceIvorn().toString(),
1680                 "//frog"
1681                 )
1682             ) ;
1683         assertNotNull(
1684             target.getChild(
1685                 home.getManagerResourceIvorn().toString(),
1686                 "//frog//toad"
1687                 )
1688             ) ;
1689         assertNotNull(
1690             target.getChild(
1691                 home.getManagerResourceIvorn().toString(),
1692                 "//frog//toad//newt"
1693                 )
1694             ) ;
1695         }
1696 
1697     /***
1698      * Check that we can get a nested container by ivorn.
1699      *
1700      */
1701     public void testGetContainerByIvorn()
1702         throws Exception
1703         {
1704         //
1705         // Create the account home.
1706         FileManagerProperties home = new FileManagerProperties(
1707             target.addAccount(
1708                 accountName
1709                 )
1710             );
1711         //
1712         // Add some nested nodes.
1713         FileManagerProperties frog = new FileManagerProperties(
1714             target.addNode(
1715                 home.getManagerResourceIvorn().toString(),
1716                 "frog",
1717                 FileManagerProperties.CONTAINER_NODE_TYPE
1718                 )
1719             );
1720         FileManagerProperties toad = new FileManagerProperties(
1721             target.addNode(
1722                 frog.getManagerResourceIvorn().toString(),
1723                 "toad",
1724                 FileManagerProperties.CONTAINER_NODE_TYPE
1725                 )
1726             );
1727         FileManagerProperties newt = new FileManagerProperties(
1728             target.addNode(
1729                 toad.getManagerResourceIvorn().toString(),
1730                 "newt",
1731                 FileManagerProperties.CONTAINER_NODE_TYPE
1732                 )
1733             );
1734         //
1735         // Check we can access the nodes by ivorn.
1736         assertNotNull(
1737             target.getNode(
1738                 home.getManagerResourceIvorn().toString() + "/frog"
1739                 )
1740             ) ;
1741         assertNotNull(
1742             target.getNode(
1743                 home.getManagerResourceIvorn().toString() + "/frog/toad"
1744                 )
1745             ) ;
1746         assertNotNull(
1747             target.getNode(
1748                 home.getManagerResourceIvorn().toString() + "/frog/toad/newt"
1749                 )
1750             ) ;
1751 
1752         assertNotNull(
1753             target.getNode(
1754                 home.getManagerResourceIvorn().toString() + "//frog"
1755                 )
1756             ) ;
1757         assertNotNull(
1758             target.getNode(
1759                 home.getManagerResourceIvorn().toString() + "//frog//toad"
1760                 )
1761             ) ;
1762         assertNotNull(
1763             target.getNode(
1764                 home.getManagerResourceIvorn().toString() + "//frog//toad//newt"
1765                 )
1766             ) ;
1767         }
1768 
1769     /***
1770      * Check we get the right Exception for null properties.
1771      *
1772      */
1773     public void testImportInitNullProperties()
1774         throws Exception
1775         {
1776         try {
1777             target.importInit(
1778                 null
1779                 );
1780             }
1781         catch (NodeNotFoundException ouch)
1782             {
1783             return ;
1784             }
1785         fail("Expected NodeNotFoundException");
1786         }
1787 
1788     /***
1789      * Check we get the right Exception for a null ivorn.
1790      *
1791      */
1792     public void testImportInitNullIvorn()
1793         throws Exception
1794         {
1795         //
1796         // Create our request properties.
1797         FileManagerProperties request = new FileManagerProperties() ;
1798         //
1799         // Call our service.
1800         try {
1801             target.importInit(
1802                 request.toArray()
1803                 );
1804             }
1805         catch (NodeNotFoundException ouch)
1806             {
1807             return ;
1808             }
1809         fail("Expected NodeNotFoundException");
1810         }
1811 
1812     /***
1813      * Check we get the right Exception for an unknown node.
1814      *
1815      */
1816     public void testImportInitUnknownIvorn()
1817         throws Exception
1818         {
1819         //
1820         // Create the ivorn factory.
1821         FileManagerIvornFactory factory = new FileManagerIvornFactory() ;
1822         //
1823         // Create our request properties.
1824         FileManagerProperties request = new FileManagerProperties() ;
1825         //
1826         // Create a new resource ivorn.
1827         request.setManagerResourceIvorn(
1828             factory.ident(
1829                 target.getIdentifier()
1830                 )
1831             );
1832         //
1833         // Call our service.
1834         try {
1835             target.importInit(
1836                 request.toArray()
1837                 );
1838             }
1839         catch (NodeNotFoundException ouch)
1840             {
1841             return ;
1842             }
1843         fail("Expected NodeNotFoundException");
1844         }
1845 
1846     /***
1847      * Check we can initiate an import into a known node.
1848      *
1849      */
1850     public void testImportInitValidNode()
1851         throws Exception
1852         {
1853         //
1854         // Create our test account.
1855         FileManagerProperties home = new FileManagerProperties(
1856             target.addAccount(
1857                 accountName
1858                 )
1859             );
1860         //
1861         // Create our target node.
1862         FileManagerProperties frog = new FileManagerProperties(
1863             target.addNode(
1864                 home.getManagerResourceIvorn().toString(),
1865                 "frog",
1866                 FileManagerProperties.DATA_NODE_TYPE
1867                 )
1868             );
1869         //
1870         // Create our request properties.
1871         FileManagerProperties request = new FileManagerProperties() ;
1872         //
1873         // Set the target node ivorn.
1874         request.setManagerResourceIvorn(
1875             frog.getManagerResourceIvorn()
1876             );
1877         //
1878         // Call our manager to initiate the import.
1879         TransferProperties importTransfer =
1880             target.importInit(
1881                 request.toArray()
1882                 ) ;
1883         //
1884         // Check we got a response.
1885         assertNotNull(
1886             importTransfer
1887             );
1888         }
1889 
1890     /***
1891      * Check we can transfer data into an existing node.
1892      *
1893      */
1894     public void testImportInitWriteData()
1895         throws Exception
1896         {
1897         //
1898         // Create our test account.
1899         FileManagerProperties home = new FileManagerProperties(
1900             target.addAccount(
1901                 accountName
1902                 )
1903             );
1904         //
1905         // Create our target node.
1906         FileManagerProperties frog = new FileManagerProperties(
1907             target.addNode(
1908                 home.getManagerResourceIvorn().toString(),
1909                 "frog",
1910                 FileManagerProperties.DATA_NODE_TYPE
1911                 )
1912             );
1913         //
1914         // Create our request properties.
1915         FileManagerProperties request = new FileManagerProperties() ;
1916         //
1917         // Set the target node ivorn.
1918         request.setManagerResourceIvorn(
1919             frog.getManagerResourceIvorn()
1920             );
1921         //
1922         // Call our manager to initiate the import.
1923         TransferProperties importTransfer =
1924             target.importInit(
1925                 request.toArray()
1926                 ) ;
1927         //
1928         // Create an output stream to the target.
1929         FileStoreOutputStream importStream = new FileStoreOutputStream(
1930             importTransfer.getLocation()
1931             ) ;
1932         //
1933         // Transfer our data.
1934         importStream.open() ;
1935         importStream.write(
1936             TEST_BYTES
1937             ) ;
1938         importStream.close() ;
1939         }
1940 
1941     /***
1942      * Check we can refresh the properties after an import. 
1943      *
1944      */
1945     public void testImportRefreshSize()
1946         throws Exception
1947         {
1948         //
1949         // Create our test account.
1950         FileManagerProperties home = new FileManagerProperties(
1951             target.addAccount(
1952                 accountName
1953                 )
1954             );
1955         //
1956         // Create our target node.
1957         FileManagerProperties frog = new FileManagerProperties(
1958             target.addNode(
1959                 home.getManagerResourceIvorn().toString(),
1960                 "frog",
1961                 FileManagerProperties.DATA_NODE_TYPE
1962                 )
1963             );
1964         //
1965         // Refresh the node properties.
1966         FileManagerProperties toad = new FileManagerProperties(
1967             target.refresh(
1968                 frog.getManagerResourceIvorn().toString()
1969                 )
1970             );
1971         //
1972         // Check the data size.
1973         assertEquals(
1974             0,
1975             toad.getContentSize()
1976             );
1977         //
1978         // Call our manager to initiate the import.
1979         TransferProperties importTransfer =
1980             target.importInit(
1981                 frog.toArray()
1982                 ) ;
1983         //
1984         // Create an output stream to the target.
1985         FileStoreOutputStream importStream = new FileStoreOutputStream(
1986             importTransfer.getLocation()
1987             ) ;
1988         //
1989         // Transfer our data.
1990         importStream.open() ;
1991         importStream.write(
1992             TEST_BYTES
1993             ) ;
1994         importStream.close() ;
1995         //
1996         // Refresh the node properties.
1997         FileManagerProperties newt = new FileManagerProperties(
1998             target.refresh(
1999                 frog.getManagerResourceIvorn().toString()
2000                 )
2001             );
2002         //
2003         // Check the data size.
2004         assertEquals(
2005             TEST_BYTES.length,
2006             newt.getContentSize()
2007             );
2008         }
2009 
2010     /***
2011      * Check we get the right Exception for null properties.
2012      *
2013      */
2014     public void testExportNullProperties()
2015         throws Exception
2016         {
2017         try {
2018             target.exportInit(
2019                 null
2020                 );
2021             }
2022         catch (NodeNotFoundException ouch)
2023             {
2024             return ;
2025             }
2026         fail("Expected NodeNotFoundException");
2027         }
2028 
2029     /***
2030      * Check we get the right Exception for a null ivorn.
2031      *
2032      */
2033     public void testExportNullIvorn()
2034         throws Exception
2035         {
2036         //
2037         // Create our request properties.
2038         FileManagerProperties request = new FileManagerProperties() ;
2039         //
2040         // Call our service.
2041         try {
2042             target.exportInit(
2043                 request.toArray()
2044                 );
2045             }
2046         catch (NodeNotFoundException ouch)
2047             {
2048             return ;
2049             }
2050         fail("Expected NodeNotFoundException");
2051         }
2052 
2053     /***
2054      * Check we get the right Exception for an unknown node.
2055      *
2056      */
2057     public void testExportUnknownIvorn()
2058         throws Exception
2059         {
2060         //
2061         // Create the ivorn factory.
2062         FileManagerIvornFactory factory = new FileManagerIvornFactory() ;
2063         //
2064         // Create our request properties.
2065         FileManagerProperties request = new FileManagerProperties() ;
2066         //
2067         // Create a new resource ivorn.
2068         request.setManagerResourceIvorn(
2069             factory.ident(
2070                 target.getIdentifier()
2071                 )
2072             );
2073         //
2074         // Call our service.
2075         try {
2076             target.exportInit(
2077                 request.toArray()
2078                 );
2079             }
2080         catch (NodeNotFoundException ouch)
2081             {
2082             return ;
2083             }
2084         fail("Expected NodeNotFoundException");
2085         }
2086 
2087     /***
2088      * Check we can initiate an export from a known node.
2089      *
2090      */
2091     public void testExportValidNode()
2092         throws Exception
2093         {
2094         //
2095         // Create our test account.
2096         FileManagerProperties home = new FileManagerProperties(
2097             target.addAccount(
2098                 accountName
2099                 )
2100             );
2101         //
2102         // Create our target node.
2103         FileManagerProperties frog = new FileManagerProperties(
2104             target.addNode(
2105                 home.getManagerResourceIvorn().toString(),
2106                 "frog",
2107                 FileManagerProperties.DATA_NODE_TYPE
2108                 )
2109             );
2110         //
2111         // Create our request properties.
2112         FileManagerProperties importRequest = new FileManagerProperties() ;
2113         //
2114         // Set the target node ivorn.
2115         importRequest.setManagerResourceIvorn(
2116             frog.getManagerResourceIvorn()
2117             );
2118         //
2119         // Call our manager to initiate the import.
2120         TransferProperties importTransfer =
2121             target.importInit(
2122                 importRequest.toArray()
2123                 ) ;
2124         //
2125         // Create an output stream to the target.
2126         FileStoreOutputStream importStream = new FileStoreOutputStream(
2127             importTransfer.getLocation()
2128             ) ;
2129         //
2130         // Transfer our data.
2131         importStream.open() ;
2132         importStream.write(
2133             TEST_BYTES
2134             ) ;
2135         importStream.close() ;
2136 
2137         //
2138         // Create our request properties.
2139         FileManagerProperties exportRequest = new FileManagerProperties() ;
2140         //
2141         // Set the target node ivorn.
2142         exportRequest.setManagerResourceIvorn(
2143             frog.getManagerResourceIvorn()
2144             );
2145         //
2146         // Call our manager to initiate the export.
2147         TransferProperties exportTransfer =
2148             target.exportInit(
2149                 exportRequest.toArray()
2150                 ) ;
2151         //
2152         // Check we got a response.
2153         assertNotNull(
2154             exportTransfer
2155             );
2156         }
2157 
2158     /***
2159      * Check we get the right data back.
2160      *
2161      */
2162     public void testExportRead()
2163         throws Exception
2164         {
2165         //
2166         // Create our test account.
2167         FileManagerProperties home = new FileManagerProperties(
2168             target.addAccount(
2169                 accountName
2170                 )
2171             );
2172         //
2173         // Create our target node.
2174         FileManagerProperties frog = new FileManagerProperties(
2175             target.addNode(
2176                 home.getManagerResourceIvorn().toString(),
2177                 "frog",
2178                 FileManagerProperties.DATA_NODE_TYPE
2179                 )
2180             );
2181         //
2182         // Create our request properties.
2183         FileManagerProperties importRequest = new FileManagerProperties() ;
2184         //
2185         // Set the target node ivorn.
2186         importRequest.setManagerResourceIvorn(
2187             frog.getManagerResourceIvorn()
2188             );
2189         //
2190         // Call our manager to initiate the import.
2191         TransferProperties importTransfer =
2192             target.importInit(
2193                 importRequest.toArray()
2194                 ) ;
2195         //
2196         // Create an output stream to the import location.
2197         FileStoreOutputStream importStream = new FileStoreOutputStream(
2198             importTransfer.getLocation()
2199             ) ;
2200         //
2201         // Transfer our data.
2202         importStream.open() ;
2203         importStream.write(
2204             TEST_BYTES
2205             ) ;
2206         importStream.close() ;
2207         //
2208         // Create our request properties.
2209         FileManagerProperties exportRequest = new FileManagerProperties() ;
2210         //
2211         // Set the target node ivorn.
2212         exportRequest.setManagerResourceIvorn(
2213             frog.getManagerResourceIvorn()
2214             );
2215         //
2216         // Call our manager to initiate the export.
2217         TransferProperties exportTransfer =
2218             target.exportInit(
2219                 exportRequest.toArray()
2220                 ) ;
2221         //
2222         // Get an input stream to the export location.
2223         FileStoreInputStream exportStream = new FileStoreInputStream(
2224             exportTransfer.getLocation()
2225             );
2226         //
2227         // Create our buffer stream.
2228         ByteArrayOutputStream buffer = new ByteArrayOutputStream() ;
2229         //
2230         // Read the data from the export location.
2231         exportStream.open();
2232         new TransferUtil(
2233             exportStream,
2234             buffer
2235             ).transfer();
2236         exportStream.close();
2237         //
2238         // Check we got the right data back.
2239         assertEquals(
2240             TEST_BYTES,
2241             buffer.toByteArray()
2242             );
2243         }
2244 
2245     /***
2246      * Test we get the right Exception for a null request.
2247      *
2248      */
2249     public void testMoveNullProperties()
2250         throws Exception
2251         {
2252         try {
2253             target.move(
2254                 null
2255                 );
2256             }
2257         catch (NodeNotFoundException ouch)
2258             {
2259             return ;
2260             }
2261         fail("Expected NodeNotFoundException");
2262         }
2263 
2264     /***
2265      * Test we can change the node name.
2266      *
2267      */
2268     public void testMoveName()
2269         throws Exception
2270         {
2271         //
2272         // Create the account home.
2273         FileManagerProperties home = new FileManagerProperties(
2274             target.addAccount(
2275                 accountName
2276                 )
2277             );
2278         //
2279         // Add a data node.
2280         FileManagerProperties frog = new FileManagerProperties(
2281             target.addNode(
2282                 home.getManagerResourceIvorn().toString(),
2283                 "frog",
2284                 FileManagerProperties.DATA_NODE_TYPE
2285                 )
2286             );
2287         //
2288         // Create our request properties.
2289         FileManagerProperties request = new FileManagerProperties();
2290         request.setManagerResourceIvorn(
2291             frog.getManagerResourceIvorn()
2292             );
2293         request.setManagerResourceName(
2294             "toad"
2295             );
2296         //
2297         // Check the node name.
2298         assertEquals(
2299             "frog",
2300             frog.getManagerResourceName()
2301             );
2302         //
2303         // Execute the move.
2304         FileManagerProperties result = new FileManagerProperties(
2305             target.move(
2306                 request.toArray()
2307                 )
2308             );
2309         //
2310         // Check the node name.
2311         assertEquals(
2312             "toad",
2313             result.getManagerResourceName()
2314             );
2315         }
2316 
2317     /***
2318      * Check we get the right Exception for a duplicate name.
2319      *
2320      */
2321     public void testMoveNameDuplicate()
2322         throws Exception
2323         {
2324         //
2325         // Create the account home.
2326         FileManagerProperties home = new FileManagerProperties(
2327             target.addAccount(
2328                 accountName
2329                 )
2330             );
2331         //
2332         // Add our data node(s).
2333         FileManagerProperties frog = new FileManagerProperties(
2334             target.addNode(
2335                 home.getManagerResourceIvorn().toString(),
2336                 "frog",
2337                 FileManagerProperties.DATA_NODE_TYPE
2338                 )
2339             );
2340         FileManagerProperties toad = new FileManagerProperties(
2341             target.addNode(
2342                 home.getManagerResourceIvorn().toString(),
2343                 "toad",
2344                 FileManagerProperties.DATA_NODE_TYPE
2345                 )
2346             );
2347         //
2348         // Create our move properties.
2349         FileManagerProperties request = new FileManagerProperties();
2350         request.setManagerResourceIvorn(
2351             frog.getManagerResourceIvorn()
2352             );
2353         request.setManagerResourceName(
2354             "toad"
2355             );
2356         //
2357         // Execute the move.
2358         try {
2359             target.move(
2360                 request.toArray()
2361                 );
2362             }
2363         catch (DuplicateNodeException ouch)
2364             {
2365             return ;
2366             }
2367         fail("Expected DuplicateNodeException");
2368         }
2369 
2370     /***
2371      * Test we can change the node parent.
2372      *
2373      */
2374     public void testMoveParent()
2375         throws Exception
2376         {
2377         //
2378         // Create the account home.
2379         FileManagerProperties home = new FileManagerProperties(
2380             target.addAccount(
2381                 accountName
2382                 )
2383             );
2384         //
2385         // Add our data node(s).
2386         FileManagerProperties frog = new FileManagerProperties(
2387             target.addNode(
2388                 home.getManagerResourceIvorn().toString(),
2389                 "frog",
2390                 FileManagerProperties.DATA_NODE_TYPE
2391                 )
2392             );
2393         //
2394         // Add our container node.
2395         FileManagerProperties newt = new FileManagerProperties(
2396             target.addNode(
2397                 home.getManagerResourceIvorn().toString(),
2398                 "newt",
2399                 FileManagerProperties.CONTAINER_NODE_TYPE
2400                 )
2401             );
2402         //
2403         // Create our move properties.
2404         FileManagerProperties request = new FileManagerProperties();
2405         request.setManagerResourceIvorn(
2406             frog.getManagerResourceIvorn()
2407             );
2408         request.setManagerParentIvorn(
2409             newt.getManagerResourceIvorn()
2410             );
2411         //
2412         // Execute the move.
2413         FileManagerProperties result = new FileManagerProperties(
2414             target.move(
2415                 request.toArray()
2416                 )
2417             );
2418         //
2419         // Check the node name.
2420         assertEquals(
2421             "frog",
2422             result.getManagerResourceName()
2423             );
2424         //
2425         // Check the node parent.
2426         assertEquals(
2427             newt.getManagerResourceIvorn(),
2428             result.getManagerParentIvorn()
2429             );
2430         }
2431 
2432     /***
2433      * Test we can change the node name and parent.
2434      *
2435      */
2436     public void testMoveNameParent()
2437         throws Exception
2438         {
2439         //
2440         // Create the account home.
2441         FileManagerProperties home = new FileManagerProperties(
2442             target.addAccount(
2443                 accountName
2444                 )
2445             );
2446         //
2447         // Add our data node(s).
2448         FileManagerProperties frog = new FileManagerProperties(
2449             target.addNode(
2450                 home.getManagerResourceIvorn().toString(),
2451                 "frog",
2452                 FileManagerProperties.DATA_NODE_TYPE
2453                 )
2454             );
2455         //
2456         // Add our container node.
2457         FileManagerProperties newt = new FileManagerProperties(
2458             target.addNode(
2459                 home.getManagerResourceIvorn().toString(),
2460                 "newt",
2461                 FileManagerProperties.CONTAINER_NODE_TYPE
2462                 )
2463             );
2464         //
2465         // Create our move properties.
2466         FileManagerProperties request = new FileManagerProperties();
2467         request.setManagerResourceIvorn(
2468             frog.getManagerResourceIvorn()
2469             );
2470         request.setManagerResourceName(
2471             "toad"
2472             );
2473         request.setManagerParentIvorn(
2474             newt.getManagerResourceIvorn()
2475             );
2476         //
2477         // Execute the move.
2478         FileManagerProperties result = new FileManagerProperties(
2479             target.move(
2480                 request.toArray()
2481                 )
2482             );
2483         //
2484         // Check the node name.
2485         assertEquals(
2486             "toad",
2487             result.getManagerResourceName()
2488             );
2489         //
2490         // Check the node parent.
2491         assertEquals(
2492             newt.getManagerResourceIvorn(),
2493             result.getManagerParentIvorn()
2494             );
2495         }
2496 
2497     /***
2498      * Check we get the right Exception for a duplicate name.
2499      *
2500      */
2501     public void testMoveParentDuplicate()
2502         throws Exception
2503         {
2504         //
2505         // Create the account home.
2506         FileManagerProperties home = new FileManagerProperties(
2507             target.addAccount(
2508                 accountName
2509                 )
2510             );
2511         //
2512         // Add our container node.
2513         FileManagerProperties newt = new FileManagerProperties(
2514             target.addNode(
2515                 home.getManagerResourceIvorn().toString(),
2516                 "newt",
2517                 FileManagerProperties.CONTAINER_NODE_TYPE
2518                 )
2519             );
2520         //
2521         // Add our data node(s).
2522         FileManagerProperties frog = new FileManagerProperties(
2523             target.addNode(
2524                 home.getManagerResourceIvorn().toString(),
2525                 "frog",
2526                 FileManagerProperties.DATA_NODE_TYPE
2527                 )
2528             );
2529         FileManagerProperties toad = new FileManagerProperties(
2530             target.addNode(
2531                 newt.getManagerResourceIvorn().toString(),
2532                 "toad",
2533                 FileManagerProperties.DATA_NODE_TYPE
2534                 )
2535             );
2536         //
2537         // Create our move properties.
2538         FileManagerProperties request = new FileManagerProperties();
2539         request.setManagerResourceIvorn(
2540             frog.getManagerResourceIvorn()
2541             );
2542         request.setManagerParentIvorn(
2543             newt.getManagerResourceIvorn()
2544             );
2545         request.setManagerResourceName(
2546             "toad"
2547             );
2548         //
2549         // Execute the move.
2550         try {
2551             target.move(
2552                 request.toArray()
2553                 );
2554             }
2555         catch (DuplicateNodeException ouch)
2556             {
2557             FileManagerProperties test = new FileManagerProperties(
2558                 target.getNode(
2559                     frog.getManagerResourceIvorn().toString()
2560                     )
2561                 );
2562             assertEquals(
2563                 home.getManagerResourceIvorn().toString(),
2564                 test.getManagerParentIvorn().toString()
2565                 );
2566             assertEquals(
2567                 "frog",
2568                 test.getManagerResourceName()
2569                 );
2570             return ;
2571             }
2572         fail("Expected DuplicateNodeException");
2573         }
2574 
2575     /***
2576      * Test we can change the location of an empty node.
2577      *
2578      */
2579     public void testMoveEmptyLocation()
2580         throws Exception
2581         {
2582         //
2583         // Create the account home.
2584         FileManagerProperties home = new FileManagerProperties(
2585             target.addAccount(
2586                 accountName
2587                 )
2588             );
2589         //
2590         // Add our data node.
2591         FileManagerProperties frog = new FileManagerProperties(
2592             target.addNode(
2593                 home.getManagerResourceIvorn().toString(),
2594                 "frog",
2595                 FileManagerProperties.DATA_NODE_TYPE
2596                 )
2597             );
2598         //
2599         // Check the node location.
2600         assertNotNull(
2601             frog.getManagerLocationIvorn()
2602             );
2603         assertEquals(
2604             filestores[0],
2605             frog.getManagerLocationIvorn()
2606             );
2607         //
2608         // Create our move properties.
2609         FileManagerProperties request = new FileManagerProperties();
2610         request.setManagerResourceIvorn(
2611             frog.getManagerResourceIvorn()
2612             );
2613         request.setManagerLocationIvorn(
2614             filestores[1]
2615             );
2616         //
2617         // Execute the move.
2618         FileManagerProperties result = new FileManagerProperties(
2619             target.move(
2620                 request.toArray()
2621                 )
2622             );
2623         //
2624         // Check the node location.
2625         assertNotNull(
2626             result.getManagerLocationIvorn()
2627             );
2628         assertEquals(
2629             filestores[1],
2630             result.getManagerLocationIvorn()
2631             );
2632         }
2633 
2634     /***
2635      * Test we can upload some data after we have changed the location.
2636      *
2637      */
2638 
2639     /***
2640      * Test that we can change the location of a node with data.
2641      *
2642      */
2643     public void testMoveDataLocation()
2644         throws Exception
2645         {
2646         //
2647         // Create the account home.
2648         FileManagerProperties home = new FileManagerProperties(
2649             target.addAccount(
2650                 accountName
2651                 )
2652             );
2653         //
2654         // Add our data node.
2655         FileManagerProperties frog = new FileManagerProperties(
2656             target.addNode(
2657                 home.getManagerResourceIvorn().toString(),
2658                 "frog",
2659                 FileManagerProperties.DATA_NODE_TYPE
2660                 )
2661             );
2662         //
2663         // Check the node location.
2664         assertNotNull(
2665             frog.getManagerLocationIvorn()
2666             );
2667         assertEquals(
2668             filestores[0],
2669             frog.getManagerLocationIvorn()
2670             );
2671         //
2672         // Call our manager to initiate the import.
2673         TransferProperties importTransfer =
2674             target.importInit(
2675                 frog.toArray()
2676                 ) ;
2677         //
2678         // Create an output stream to the import location.
2679         FileStoreOutputStream importStream = new FileStoreOutputStream(
2680             importTransfer.getLocation()
2681             ) ;
2682         //
2683         // Transfer our data.
2684         importStream.open() ;
2685         importStream.write(
2686             TEST_BYTES
2687             ) ;
2688         importStream.close() ;
2689 
2690         //
2691         // Set our target location.
2692         frog.setManagerLocationIvorn(
2693             filestores[1]
2694             );
2695         //
2696         // Execute the move.
2697         frog = new FileManagerProperties(
2698             target.move(
2699                 frog.toArray()
2700                 )
2701             );
2702         //
2703         // Check the node location.
2704         assertNotNull(
2705             frog.getManagerLocationIvorn()
2706             );
2707         assertEquals(
2708             filestores[1],
2709             frog.getManagerLocationIvorn()
2710             );
2711 
2712         //
2713         // Call our manager to initiate the export.
2714         TransferProperties exportTransfer =
2715             target.exportInit(
2716                 frog.toArray()
2717                 ) ;
2718         //
2719         // Get an input stream to the export location.
2720         FileStoreInputStream exportStream = new FileStoreInputStream(
2721             exportTransfer.getLocation()
2722             );
2723         //
2724         // Create our buffer stream.
2725         ByteArrayOutputStream buffer = new ByteArrayOutputStream() ;
2726         //
2727         // Read the data from the export location.
2728         exportStream.open();
2729         new TransferUtil(
2730             exportStream,
2731             buffer
2732             ).transfer();
2733         exportStream.close();
2734         //
2735         // Check we got the right data back.
2736         assertEquals(
2737             TEST_BYTES,
2738             buffer.toByteArray()
2739             );
2740         }
2741 
2742 /* TBD
2743  * Check that the old file has been removed ...
2744  *
2745  */
2746 
2747     /***
2748      * Check we get the right Exception for a null request.
2749      *
2750      */
2751     public void testCopyNullRequest()
2752         throws Exception
2753         {
2754         try {
2755             target.copy(
2756                 null
2757                 );
2758             }
2759         catch (NodeNotFoundException ouch)
2760             {
2761             return ;
2762             }
2763         fail("Expected NodeNotFoundException") ;
2764         }
2765 
2766     /***
2767      * Check we get the right Exception for a null resource.
2768      *
2769      */
2770     public void testCopyNullResource()
2771         throws Exception
2772         {
2773         //
2774         // Create the account home.
2775         FileManagerProperties home = new FileManagerProperties(
2776             target.addAccount(
2777                 accountName
2778                 )
2779             );
2780         //
2781         // Create our request.
2782         FileManagerProperties request = new FileManagerProperties() ;
2783         request.setManagerParentIvorn(
2784             home.getManagerResourceIvorn()
2785             );
2786         request.setManagerResourceName(
2787             "frog"
2788             );
2789         try {
2790             target.copy(
2791                 request.toArray()
2792                 );
2793             }
2794         catch (NodeNotFoundException ouch)
2795             {
2796             return ;
2797             }
2798         fail("Expected NodeNotFoundException") ;
2799         }
2800 
2801     /***
2802      * Check we get the right Exception for an unknown resource.
2803      *
2804      */
2805     public void testCopyUnknownResource()
2806         throws Exception
2807         {
2808         //
2809         // Create the account home.
2810         FileManagerProperties home = new FileManagerProperties(
2811             target.addAccount(
2812                 accountName
2813                 )
2814             );
2815         //
2816         // Create our request.
2817         FileManagerProperties request = new FileManagerProperties() ;
2818         request.setManagerParentIvorn(
2819             home.getManagerResourceIvorn()
2820             );
2821         request.setManagerResourceIvorn(
2822             "ivo://unknown#unknown"
2823             );
2824         request.setManagerResourceName(
2825             "toad"
2826             );
2827         try {
2828             target.copy(
2829                 request.toArray()
2830                 );
2831             }
2832         catch (NodeNotFoundException ouch)
2833             {
2834             return ;
2835             }
2836         fail("Expected NodeNotFoundException") ;
2837         }
2838 
2839     /***
2840      * Check we get the right Exception for the same resource.
2841      *
2842      */
2843     public void testCopyDuplicateSame()
2844         throws Exception
2845         {
2846         //
2847         // Create the account home.
2848         FileManagerProperties home = new FileManagerProperties(
2849             target.addAccount(
2850                 accountName
2851                 )
2852             );
2853         //
2854         // Add our data node.
2855         FileManagerProperties frog = new FileManagerProperties(
2856             target.addNode(
2857                 home.getManagerResourceIvorn().toString(),
2858                 "frog",
2859                 FileManagerProperties.DATA_NODE_TYPE
2860                 )
2861             );
2862         try {
2863             target.copy(
2864                 frog.toArray()
2865                 );
2866             }
2867         catch (DuplicateNodeException ouch)
2868             {
2869             return ;
2870             }
2871         fail("Expected DuplicateNodeException") ;
2872         }
2873 
2874     /***
2875      * Check we get the right Exception for a duplicate node.
2876      *
2877      */
2878     public void testCopyDuplicateNode()
2879         throws Exception
2880         {
2881         //
2882         // Create the account home.
2883         FileManagerProperties home = new FileManagerProperties(
2884             target.addAccount(
2885                 accountName
2886                 )
2887             );
2888         //
2889         // Add our source node.
2890         FileManagerProperties frog = new FileManagerProperties(
2891             target.addNode(
2892                 home.getManagerResourceIvorn().toString(),
2893                 "frog",
2894                 FileManagerProperties.DATA_NODE_TYPE
2895                 )
2896             );
2897         //
2898         // Add our duplicate target.
2899         FileManagerProperties toad = new FileManagerProperties(
2900             target.addNode(
2901                 home.getManagerResourceIvorn().toString(),
2902                 "toad",
2903                 FileManagerProperties.CONTAINER_NODE_TYPE
2904                 )
2905             );
2906         FileManagerProperties newt = new FileManagerProperties(
2907             target.addNode(
2908                 toad.getManagerResourceIvorn().toString(),
2909                 "newt",
2910                 FileManagerProperties.DATA_NODE_TYPE
2911                 )
2912             );
2913         //
2914         // Create our copy request.
2915         FileManagerProperties request = new FileManagerProperties() ;
2916         request.setManagerResourceIvorn(
2917             frog.getManagerResourceIvorn()
2918             );
2919         request.setManagerParentIvorn(
2920             toad.getManagerResourceIvorn()
2921             );
2922         request.setManagerResourceName(
2923             "newt"
2924             );
2925         try {
2926             target.copy(
2927                 request.toArray()
2928                 );
2929             }
2930         catch (DuplicateNodeException ouch)
2931             {
2932             return ;
2933             }
2934         fail("Expected DuplicateNodeException") ;
2935         }
2936 
2937     /***
2938      * Check we can copy an empty node.
2939      *
2940      */
2941     public void testCopyEmptyNode()
2942         throws Exception
2943         {
2944         //
2945         // Create the account home.
2946         FileManagerProperties home = new FileManagerProperties(
2947             target.addAccount(
2948                 accountName
2949                 )
2950             );
2951         //
2952         // Add our source node.
2953         FileManagerProperties frog = new FileManagerProperties(
2954             target.addNode(
2955                 home.getManagerResourceIvorn().toString(),
2956                 "frog",
2957                 FileManagerProperties.DATA_NODE_TYPE
2958                 )
2959             );
2960         //
2961         // Create our request.
2962         FileManagerProperties request = new FileManagerProperties() ;
2963         request.setManagerParentIvorn(
2964             home.getManagerResourceIvorn()
2965             );
2966         request.setManagerResourceIvorn(
2967             frog.getManagerResourceIvorn()
2968             );
2969         request.setManagerResourceName(
2970             "toad"
2971             );
2972         //
2973         // Create our copy.
2974         FileManagerProperties result = new FileManagerProperties(
2975             target.copy(
2976                 request.toArray()
2977                 )
2978             ) ;
2979         //
2980         // Check we got the right name.
2981         assertEquals(
2982             "toad",
2983             result.getManagerResourceName()
2984             );
2985         //
2986         // Check we got the right parent.
2987         assertEquals(
2988             home.getManagerResourceIvorn(),
2989             result.getManagerParentIvorn()
2990             );
2991         }
2992 
2993     /***
2994      * Check we can copy a node with data.
2995      *
2996      */
2997     public void testCopyNodeData()
2998         throws Exception
2999         {
3000         //
3001         // Create the account home.
3002         FileManagerProperties home = new FileManagerProperties(
3003             target.addAccount(
3004                 accountName
3005                 )
3006             );
3007         //
3008         // Add our source node.
3009         FileManagerProperties frog = new FileManagerProperties(
3010             target.addNode(
3011                 home.getManagerResourceIvorn().toString(),
3012                 "frog",
3013                 FileManagerProperties.DATA_NODE_TYPE
3014                 )
3015             );
3016         //
3017         // Call our manager to initiate the import.
3018         TransferProperties importTransfer =
3019             target.importInit(
3020                 frog.toArray()
3021                 ) ;
3022         //
3023         // Create an output stream to the import location.
3024         FileStoreOutputStream importStream = new FileStoreOutputStream(
3025             importTransfer.getLocation()
3026             ) ;
3027         //
3028         // Transfer our data.
3029         importStream.open() ;
3030         importStream.write(
3031             TEST_BYTES
3032             ) ;
3033         importStream.close() ;
3034         //
3035         // Create our copy request.
3036         FileManagerProperties request = new FileManagerProperties() ;
3037         request.setManagerParentIvorn(
3038             home.getManagerResourceIvorn()
3039             );
3040         request.setManagerResourceIvorn(
3041             frog.getManagerResourceIvorn()
3042             );
3043         request.setManagerResourceName(
3044             "toad"
3045             );
3046         //
3047         // Create our copy.
3048         FileManagerProperties toad = new FileManagerProperties(
3049             target.copy(
3050                 request.toArray()
3051                 )
3052             ) ;
3053         //
3054         // Call our manager to initiate the export.
3055         TransferProperties exportTransfer =
3056             target.exportInit(
3057                 toad.toArray()
3058                 ) ;
3059         //
3060         // Get an input stream to the export location.
3061         FileStoreInputStream exportStream = new FileStoreInputStream(
3062             exportTransfer.getLocation()
3063             );
3064         //
3065         // Create our buffer stream.
3066         ByteArrayOutputStream buffer = new ByteArrayOutputStream() ;
3067         //
3068         // Read the data from the export location.
3069         exportStream.open();
3070         new TransferUtil(
3071             exportStream,
3072             buffer
3073             ).transfer();
3074         exportStream.close();
3075         //
3076         // Check we got the right data back.
3077         assertEquals(
3078             TEST_BYTES,
3079             buffer.toByteArray()
3080             );
3081         }
3082 
3083     /***
3084      * Check we can copy a data node to another location.
3085      *
3086      */
3087     public void testCopyNodeLocation()
3088         throws Exception
3089         {
3090         //
3091         // Create the account home.
3092         FileManagerProperties home = new FileManagerProperties(
3093             target.addAccount(
3094                 accountName
3095                 )
3096             );
3097         //
3098         // Add our source node.
3099         FileManagerProperties frog = new FileManagerProperties(
3100             target.addNode(
3101                 home.getManagerResourceIvorn().toString(),
3102                 "frog",
3103                 FileManagerProperties.DATA_NODE_TYPE
3104                 )
3105             );
3106 
3107         //
3108         // Call our manager to initiate the import.
3109         TransferProperties importTransfer =
3110             target.importInit(
3111                 frog.toArray()
3112                 ) ;
3113         //
3114         // Create an output stream to the import location.
3115         FileStoreOutputStream importStream = new FileStoreOutputStream(
3116             importTransfer.getLocation()
3117             ) ;
3118         //
3119         // Transfer our data.
3120         importStream.open() ;
3121         importStream.write(
3122             TEST_BYTES
3123             ) ;
3124         importStream.close() ;
3125 
3126         //
3127         // Check the node location.
3128         assertEquals(
3129             filestores[0],
3130             frog.getManagerLocationIvorn()
3131             );
3132 
3133         //
3134         // Create our copy request.
3135         FileManagerProperties request = new FileManagerProperties() ;
3136         request.setManagerParentIvorn(
3137             home.getManagerResourceIvorn()
3138             );
3139         request.setManagerResourceIvorn(
3140             frog.getManagerResourceIvorn()
3141             );
3142         request.setManagerResourceName(
3143             "toad"
3144             );
3145         request.setManagerLocationIvorn(
3146             filestores[1]
3147             );
3148 
3149         //
3150         // Create our copy.
3151         FileManagerProperties toad = new FileManagerProperties(
3152             target.copy(
3153                 request.toArray()
3154                 )
3155             ) ;
3156 
3157         //
3158         // Call our manager to initiate the export.
3159         TransferProperties exportTransfer =
3160             target.exportInit(
3161                 toad.toArray()
3162                 ) ;
3163         //
3164         // Get an input stream to the export location.
3165         FileStoreInputStream exportStream = new FileStoreInputStream(
3166             exportTransfer.getLocation()
3167             );
3168         //
3169         // Create our buffer stream.
3170         ByteArrayOutputStream buffer = new ByteArrayOutputStream() ;
3171         //
3172         // Read the data from the export location.
3173         exportStream.open();
3174         new TransferUtil(
3175             exportStream,
3176             buffer
3177             ).transfer();
3178         exportStream.close();
3179         //
3180         // Check we got the right data back.
3181         assertEquals(
3182             TEST_BYTES,
3183             buffer.toByteArray()
3184             );
3185 
3186         //
3187         // Check the node location.
3188         assertEquals(
3189             filestores[1],
3190             toad.getManagerLocationIvorn()
3191             );
3192         }
3193 
3194     /***
3195      * Check we can copy an empty node to a new location.
3196      *
3197      */
3198     public void testCopyEmptyLocation()
3199         throws Exception
3200         {
3201         //
3202         // Create the account home.
3203         FileManagerProperties home = new FileManagerProperties(
3204             target.addAccount(
3205                 accountName
3206                 )
3207             );
3208         //
3209         // Add our source node.
3210         FileManagerProperties frog = new FileManagerProperties(
3211             target.addNode(
3212                 home.getManagerResourceIvorn().toString(),
3213                 "frog",
3214                 FileManagerProperties.DATA_NODE_TYPE
3215                 )
3216             );
3217         //
3218         // Create our request.
3219         FileManagerProperties request = new FileManagerProperties() ;
3220         request.setManagerParentIvorn(
3221             home.getManagerResourceIvorn()
3222             );
3223         request.setManagerResourceIvorn(
3224             frog.getManagerResourceIvorn()
3225             );
3226         request.setManagerResourceName(
3227             "toad"
3228             );
3229         request.setManagerLocationIvorn(
3230             filestores[1]
3231             );
3232         //
3233         // Create our copy.
3234         FileManagerProperties result = new FileManagerProperties(
3235             target.copy(
3236                 request.toArray()
3237                 )
3238             ) ;
3239         //
3240         // Check we got the right name.
3241         assertEquals(
3242             "toad",
3243             result.getManagerResourceName()
3244             );
3245         //
3246         // Check we got the right parent.
3247         assertEquals(
3248             home.getManagerResourceIvorn(),
3249             result.getManagerParentIvorn()
3250             );
3251         //
3252         // Check we got the right location.
3253         assertEquals(
3254             filestores[1],
3255             result.getManagerLocationIvorn()
3256             );
3257         }
3258 
3259 
3260 //
3261 // Check we can add something to the copy.
3262 // Check the original is unchanged.
3263 // Check the copy has the new data.
3264 // ** Needs append ...
3265 //
3266 
3267 //
3268 // Check we can delete the original.
3269 // ** Needs delete ...
3270 //
3271 
3272 //
3273 // Check we can copy a node to a new filestore.
3274 // ** Needs implementing ...
3275 //
3276 
3277     /***
3278      * Check that we can delete an empty node.
3279      *
3280      */
3281     public void testDeleteEmptyData()
3282         throws Exception
3283         {
3284         //
3285         // Create the account home.
3286         FileManagerProperties home = new FileManagerProperties(
3287             target.addAccount(
3288                 accountName
3289                 )
3290             );
3291         //
3292         // Add a container node.
3293         FileManagerProperties frog = new FileManagerProperties(
3294             target.addNode(
3295                 home.getManagerResourceIvorn().toString(),
3296                 "frog",
3297                 FileManagerProperties.CONTAINER_NODE_TYPE
3298                 )
3299             );
3300         //
3301         // Add a data node.
3302         FileManagerProperties toad = new FileManagerProperties(
3303             target.addNode(
3304                 frog.getManagerResourceIvorn().toString(),
3305                 "toad",
3306                 FileManagerProperties.DATA_NODE_TYPE
3307                 )
3308             );
3309         //
3310         // Check we can get the node details.
3311         assertNotNull(
3312             target.getNode(
3313                 toad.getManagerResourceIvorn().toString()
3314                 )
3315             );
3316         //
3317         // Try deleting the node.
3318         target.delete(
3319             toad.getManagerResourceIvorn().toString()
3320             );
3321         //
3322         // Check the node isn't there any more.
3323         try {
3324             target.getNode(
3325                 toad.getManagerResourceIvorn().toString()
3326                 ) ;
3327             }
3328         catch (NodeNotFoundException ouch)
3329             {
3330             return ;
3331             }
3332         fail("Expected NodeNotFoundException") ;
3333         }
3334 
3335     /***
3336      * Check that we can delete a data node.
3337      * This can fail on the mock implementation because the service does not let go of the data.
3338      *
3339     public void testDeleteVaildData()
3340         throws Exception
3341         {
3342         //
3343         // Create the account home.
3344         FileManagerProperties home = new FileManagerProperties(
3345             target.addAccount(
3346                 accountName
3347                 )
3348             );
3349         //
3350         // Add a container node.
3351         FileManagerProperties frog = new FileManagerProperties(
3352             target.addNode(
3353                 home.getManagerResourceIvorn().toString(),
3354                 "frog",
3355                 FileManagerProperties.CONTAINER_NODE_TYPE
3356                 )
3357             );
3358         //
3359         // Add a data node.
3360         FileManagerProperties toad = new FileManagerProperties(
3361             target.addNode(
3362                 frog.getManagerResourceIvorn().toString(),
3363                 "toad",
3364                 FileManagerProperties.DATA_NODE_TYPE
3365                 )
3366             );
3367         //
3368         // Check we can get the node details.
3369         assertNotNull(
3370             target.getNode(
3371                 toad.getManagerResourceIvorn().toString()
3372                 )
3373             );
3374         //
3375         // Call our manager to initiate an import.
3376 //
3377 // BUG ... this was 'frog' and it didn't cause an error.
3378 //
3379         TransferProperties importTransfer =
3380             target.importInit(
3381                 toad.toArray()
3382                 ) ;
3383         //
3384         // Create an output stream to the import location.
3385         FileStoreOutputStream importStream = new FileStoreOutputStream(
3386             importTransfer.getLocation()
3387             ) ;
3388         //
3389         // Transfer some data into the node.
3390         importStream.open() ;
3391         importStream.write(
3392             TEST_BYTES
3393             ) ;
3394         importStream.close() ;
3395 
3396         //
3397         // Call our manager to initiate an export.
3398         TransferProperties exportTransfer =
3399             target.exportInit(
3400                 toad.toArray()
3401                 ) ;
3402 
3403         //
3404         // Try deleting the node.
3405         target.delete(
3406             toad.getManagerResourceIvorn().toString()
3407             );
3408 //
3409 // This don't work on the mock implementation.
3410 // The current mock service does not disconnect the URL handler when a node is deleted.
3411 //
3412         //
3413         // Check the data isn't there any more.
3414         try {
3415             //
3416             // Get an input stream to the export location.
3417             FileStoreInputStream exportStream = new FileStoreInputStream(
3418                 exportTransfer.getLocation()
3419                 );
3420             //
3421             // Try opening the stream.
3422             exportStream.open();
3423             }
3424         catch (FileNotFoundException ouch)
3425             {
3426             return ;
3427             }
3428         fail("Expected FileNotFoundException") ;
3429         }
3430      */
3431 
3432     /***
3433      * Check that the file create and modify dates are set.
3434      *
3435      */
3436     public void testImportDates()
3437         throws Exception
3438         {
3439         //
3440         // Create our test account.
3441         FileManagerProperties home = new FileManagerProperties(
3442             target.addAccount(
3443                 accountName
3444                 )
3445             );
3446         //
3447         // Create our target node.
3448         FileManagerProperties frog = new FileManagerProperties(
3449             target.addNode(
3450                 home.getManagerResourceIvorn().toString(),
3451                 "frog",
3452                 FileManagerProperties.DATA_NODE_TYPE
3453                 )
3454             );
3455         //
3456         // Get the initial dates.
3457         Date frogCreateDate = frog.getFileCreateDate();
3458         Date frogModifyDate = frog.getFileModifyDate();
3459         //
3460         // Refresh the node properties.
3461         FileManagerProperties toad = new FileManagerProperties(
3462             target.refresh(
3463                 frog.getManagerResourceIvorn().toString()
3464                 )
3465             );
3466         //
3467         // Get the updated dates.
3468         Date toadCreateDate = toad.getFileCreateDate();
3469         Date toadModifyDate = toad.getFileModifyDate();
3470         //
3471         // Pause for a bit ....
3472         Thread.sleep(1000);
3473         //
3474         // Call our manager to initiate the import.
3475         TransferProperties importTransfer =
3476             target.importInit(
3477                 frog.toArray()
3478                 ) ;
3479         //
3480         // Create an output stream to the target.
3481         FileStoreOutputStream importStream = new FileStoreOutputStream(
3482             importTransfer.getLocation()
3483             ) ;
3484         //
3485         // Transfer our data.
3486         importStream.open() ;
3487         importStream.write(
3488             TEST_BYTES
3489             ) ;
3490         importStream.close() ;
3491         //
3492         // Refresh the node properties.
3493         FileManagerProperties newt = new FileManagerProperties(
3494             target.refresh(
3495                 frog.getManagerResourceIvorn().toString()
3496                 )
3497             );
3498         //
3499         // Get the final dates.
3500         Date newtCreateDate = newt.getFileCreateDate();
3501         Date newtModifyDate = newt.getFileModifyDate();
3502 
3503         System.out.println("");
3504         System.out.println("Created  : " + frogCreateDate);
3505         System.out.println("Modified : " + frogModifyDate);
3506 
3507         System.out.println("");
3508         System.out.println("Created  : " + toadCreateDate);
3509         System.out.println("Modified : " + toadModifyDate);
3510 
3511         System.out.println("");
3512         System.out.println("Created  : " + newtCreateDate);
3513         System.out.println("Modified : " + newtModifyDate);
3514         //
3515         // Check the first set of dates are null.
3516         assertNull(
3517             frogCreateDate
3518             );
3519         assertNull(
3520             frogModifyDate
3521             );
3522         assertNull(
3523             toadCreateDate
3524             );
3525         assertNull(
3526             toadModifyDate
3527             );
3528         //
3529         // Check the final dates are not null.
3530         assertNotNull(
3531             newtCreateDate
3532             );
3533         assertNotNull(
3534             newtModifyDate
3535             );
3536         //
3537         // Check the modified date is after the create date.
3538         assertTrue(
3539             newtModifyDate.after(
3540                 newtCreateDate
3541                 )
3542             );
3543         }
3544 
3545     /***
3546      * Test that we get the right Exception for null request.
3547      *
3548      */
3549     public void testImportDataNullRequest()
3550         throws Exception
3551         {
3552         //
3553         // Try to import the data.
3554         try {
3555             target.importData(
3556                 null
3557                 );
3558             }
3559         catch (NodeNotFoundException ouch)
3560             {
3561             return ;
3562             }
3563         fail("Expected NodeNotFoundException") ;
3564         }
3565 
3566     /***
3567      * Test that we get the right Exception for null properties.
3568      *
3569      */
3570     public void testImportDataNullProperties()
3571         throws Exception
3572         {
3573         //
3574         // Try to import the data.
3575         try {
3576             target.importData(
3577                 new UrlGetTransfer(
3578                     new URL(
3579                         getTestProperty(
3580                             "data.file.text"
3581                             )
3582                         ),
3583                     (FileManagerProperties)null
3584                     )
3585                 );
3586             }
3587         catch (NodeNotFoundException ouch)
3588             {
3589             return ;
3590             }
3591         fail("Expected NodeNotFoundException") ;
3592         }
3593 
3594     /***
3595      * Test that we get the right Exception for empty properties.
3596      *
3597      */
3598     public void testImportDataEmptyProperties()
3599         throws Exception
3600         {
3601         //
3602         // Create our test properties.
3603         FileManagerProperties properties = new FileManagerProperties() ;
3604         //
3605         // Try to import the data.
3606         try {
3607             target.importData(
3608                 new UrlGetTransfer(
3609                     new URL(
3610                         getTestProperty(
3611                             "data.file.text"
3612                             )
3613                         ),
3614                     properties
3615                     )
3616                 );
3617             }
3618         catch (NodeNotFoundException ouch)
3619             {
3620             return ;
3621             }
3622         fail("Expected NodeNotFoundException") ;
3623         }
3624 
3625     /***
3626      * Test that we get the right Exception for an unknown node.
3627      *
3628      */
3629     public void testImportDataUnknownNode()
3630         throws Exception
3631         {
3632         //
3633         // Create the ivorn factory.
3634         FileManagerIvornFactory factory = new FileManagerIvornFactory() ;
3635         //
3636         // Create our request properties.
3637         FileManagerProperties properties = new FileManagerProperties() ;
3638         //
3639         // Set the resource ivorn.
3640         properties.setManagerResourceIvorn(
3641             factory.ident(
3642                 target.getIdentifier()
3643                 )
3644             );
3645         //
3646         // Try to import the data.
3647         try {
3648             target.importData(
3649                 new UrlGetTransfer(
3650                     new URL(
3651                         getTestProperty(
3652                             "data.file.text"
3653                             )
3654                         ),
3655                     properties
3656                     )
3657                 );
3658             }
3659         catch (NodeNotFoundException ouch)
3660             {
3661             return ;
3662             }
3663         fail("Expected NodeNotFoundException") ;
3664         }
3665 
3666     /***
3667      * Test that we get the right Exception for container node.
3668      *
3669      */
3670     public void testImportDataContainerNode()
3671         throws Exception
3672         {
3673         //
3674         // Create our test account.
3675         FileManagerProperties home = new FileManagerProperties(
3676             target.addAccount(
3677                 accountName
3678                 )
3679             );
3680         //
3681         // Create our target node.
3682         FileManagerProperties frog = new FileManagerProperties(
3683             target.addNode(
3684                 home.getManagerResourceIvorn().toString(),
3685                 "frog",
3686                 FileManagerProperties.CONTAINER_NODE_TYPE
3687                 )
3688             );
3689         //
3690         // Try to import the data.
3691         try {
3692             target.importData(
3693                 new UrlGetTransfer(
3694                     new URL(
3695                         getTestProperty(
3696                             "data.file.text"
3697                             )
3698                         ),
3699                     frog
3700                     )
3701                 );
3702             }
3703         catch (FileManagerServiceException ouch)
3704             {
3705             return ;
3706             }
3707         fail("Expected FileManagerServiceException") ;
3708         }
3709 
3710     /***
3711      * Check that we can import data from local file.
3712      *
3713      */
3714     public void testImportDataFile()
3715         throws Exception
3716         {
3717         //
3718         // Create our test account.
3719         FileManagerProperties home = new FileManagerProperties(
3720             target.addAccount(
3721                 accountName
3722                 )
3723             );
3724         //
3725         // Create our target node.
3726         FileManagerProperties frog = new FileManagerProperties(
3727             target.addNode(
3728                 home.getManagerResourceIvorn().toString(),
3729                 "frog",
3730                 FileManagerProperties.DATA_NODE_TYPE
3731                 )
3732             );
3733         //
3734         // Import the data.
3735         target.importData(
3736             new UrlGetTransfer(
3737                 new URL(
3738                     getTestProperty(
3739                         "data.file.text"
3740                         )
3741                     ),
3742                 frog
3743                 )
3744             );
3745         }
3746 
3747     /***
3748      * Check that we get the right data from a local file.
3749      *
3750      */
3751     public void testImportDataFileData()
3752         throws Exception
3753         {
3754         //
3755         // Create our test account.
3756         FileManagerProperties home = new FileManagerProperties(
3757             target.addAccount(
3758                 accountName
3759                 )
3760             );
3761         //
3762         // Create our target node.
3763         FileManagerProperties frog = new FileManagerProperties(
3764             target.addNode(
3765                 home.getManagerResourceIvorn().toString(),
3766                 "frog",
3767                 FileManagerProperties.DATA_NODE_TYPE
3768                 )
3769             );
3770         //
3771         // Import the data.
3772         target.importData(
3773             new UrlGetTransfer(
3774                 new URL(
3775                     getTestProperty(
3776                         "data.file.text"
3777                         )
3778                     ),
3779                 frog
3780                 )
3781             );
3782         //
3783         // Create our request properties.
3784         FileManagerProperties exportRequest = new FileManagerProperties() ;
3785         //
3786         // Set the target node ivorn.
3787         exportRequest.setManagerResourceIvorn(
3788             frog.getManagerResourceIvorn()
3789             );
3790         //
3791         // Call our manager to initiate the export.
3792         TransferProperties exportTransfer =
3793             target.exportInit(
3794                 exportRequest.toArray()
3795                 ) ;
3796         //
3797         // Get an input stream to the export location.
3798         FileStoreInputStream exportStream = new FileStoreInputStream(
3799             exportTransfer.getLocation()
3800             );
3801         //
3802         // Create our buffer stream.
3803         ByteArrayOutputStream buffer = new ByteArrayOutputStream() ;
3804         //
3805         // Read the data from the export location.
3806         exportStream.open();
3807         TransferUtil util =
3808             new TransferUtil(
3809                 exportStream,
3810                 buffer
3811                 );
3812         int count = util.transfer();
3813         exportStream.close();
3814         //
3815         // Check we got the right data back.
3816         assertEquals(
3817             TEST_STRING,
3818             new String(
3819                 buffer.toByteArray()
3820                 )
3821             );
3822         }
3823 
3824     /***
3825      * Check that we can't change the name with an import.
3826      *
3827      */
3828     public void testImportDataName()
3829         throws Exception
3830         {
3831         //
3832         // Create our test account.
3833         FileManagerProperties home = new FileManagerProperties(
3834             target.addAccount(
3835                 accountName
3836                 )
3837             );
3838         //
3839         // Create our target node.
3840         FileManagerProperties frog =
3841             new FileManagerProperties(
3842                 target.addNode(
3843                     home.getManagerResourceIvorn().toString(),
3844                     "frog",
3845                     FileManagerProperties.DATA_NODE_TYPE
3846                     )
3847                 );
3848         //
3849         // Modify the node name.
3850         frog.setManagerResourceName(
3851             "toad"
3852             );
3853         //
3854         // Import the data.
3855         FileManagerProperties toad = 
3856             new FileManagerProperties(
3857                 target.importData(
3858                     new UrlGetTransfer(
3859                         new URL(
3860                             getTestProperty(
3861                                 "data.file.text"
3862                                 )
3863                             ),
3864                         frog
3865                         )
3866                     )
3867                 );
3868         //
3869         // Check we still have the original name.
3870         assertEquals(
3871             "frog",
3872             toad.getManagerResourceName()
3873             );
3874         }
3875 
3876     /***
3877      * Check that we can't change the parent with an import.
3878      *
3879      */
3880     public void testImportDataParent()
3881         throws Exception
3882         {
3883         //
3884         // Create our test account.
3885         FileManagerProperties home = new FileManagerProperties(
3886             target.addAccount(
3887                 accountName
3888                 )
3889             );
3890         //
3891         // Create our target node.
3892         FileManagerProperties frog =
3893             new FileManagerProperties(
3894                 target.addNode(
3895                     home.getManagerResourceIvorn().toString(),
3896                     "frog",
3897                     FileManagerProperties.DATA_NODE_TYPE
3898                     )
3899                 );
3900         //
3901         // Create our other parent node.
3902         FileManagerProperties newt =
3903             new FileManagerProperties(
3904                 target.addNode(
3905                     home.getManagerResourceIvorn().toString(),
3906                     "newt",
3907                     FileManagerProperties.CONTAINER_NODE_TYPE
3908                     )
3909                 );
3910         //
3911         // Modify the node parent.
3912         frog.setManagerParentIvorn(
3913             newt.getManagerResourceIvorn()
3914             );
3915         //
3916         // Import the data.
3917         FileManagerProperties toad = 
3918             new FileManagerProperties(
3919                 target.importData(
3920                     new UrlGetTransfer(
3921                         new URL(
3922                             getTestProperty(
3923                                 "data.file.text"
3924                                 )
3925                             ),
3926                         frog
3927                         )
3928                     )
3929                 );
3930         //
3931         // Check we still have the original name.
3932         assertEquals(
3933             home.getManagerResourceIvorn(),
3934             toad.getManagerParentIvorn()
3935             );
3936         }
3937 
3938     /***
3939      * Check that we can't change the type with an import.
3940      *
3941      */
3942     public void testImportDataType()
3943         throws Exception
3944         {
3945         //
3946         // Create our test account.
3947         FileManagerProperties home = new FileManagerProperties(
3948             target.addAccount(
3949                 accountName
3950                 )
3951             );
3952         //
3953         // Create our target node.
3954         FileManagerProperties frog =
3955             new FileManagerProperties(
3956                 target.addNode(
3957                     home.getManagerResourceIvorn().toString(),
3958                     "frog",
3959                     FileManagerProperties.DATA_NODE_TYPE
3960                     )
3961                 );
3962         //
3963         // Modify the node type.
3964         frog.setManagerResourceType(
3965             FileManagerProperties.CONTAINER_NODE_TYPE
3966             );
3967         //
3968         // Import the data.
3969         FileManagerProperties toad = 
3970             new FileManagerProperties(
3971                 target.importData(
3972                     new UrlGetTransfer(
3973                         new URL(
3974                             getTestProperty(
3975                                 "data.file.text"
3976                                 )
3977                             ),
3978                         frog
3979                         )
3980                     )
3981                 );
3982         //
3983         // Check we still have the original name.
3984         assertEquals(
3985             FileManagerProperties.DATA_NODE_TYPE,
3986             toad.getManagerResourceType()
3987             );
3988         }
3989     }