View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/filestore/common/src/java/org/astrogrid/filestore/common/FileStoreTest.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.12 $</cvs:version>
6    * <cvs:log>
7    *   $Log: FileStoreTest.java,v $
8    *   Revision 1.12  2005/01/28 10:43:58  clq2
9    *   dave_dev_200501141257 (filemanager)
10   *
11   *   Revision 1.11.10.7  2005/01/20 07:18:04  dave
12   *   Tided up tabs to spaces ..
13   *
14   *   Revision 1.11.10.6  2005/01/19 13:22:25  dave
15   *   Removed fragile date test (fails if it takes less than 1ms to update a file) ..
16   *
17   *   Revision 1.11.10.5  2005/01/19 12:56:16  dave
18   *   Added sleep to date tests to avoid race condition ...
19   *
20   *   Revision 1.11.10.4  2005/01/17 17:19:21  dave
21   *   Fixed bug in FileManagerImpl test (missing '/' in repository path on Unix) ...
22   *   Changed tabs to spaces ..
23   *
24   *   Revision 1.11.10.3  2005/01/15 08:25:50  dave
25   *   Refactored file created and modified date handling ..
26   *
27   *   Revision 1.11.10.2  2005/01/15 04:50:58  dave
28   *   Added created and modified dates to server ....
29   *   Removed log debug messages from JUnit tests ...
30   *
31   *   Revision 1.11.10.1  2005/01/15 03:46:50  dave
32   *   Added initial tests for create and modified date(s) ..
33   *
34   *   Revision 1.11  2004/11/25 00:19:19  jdt
35   *   Merge from dave-dev-200410061224-200411221626
36   *
37   *   Revision 1.10.14.5  2004/11/09 17:41:36  dave
38   *   Added file:// URL handling to allow server URLs to be tested.
39   *   Added importInit and exportInit to server implementation.
40   *   Moved remaining tests out of extended test abd removed it.
41   *
42   *   Revision 1.10.14.4  2004/11/06 19:12:18  dave
43   *   Refactored identifier properties ...
44   *
45   *   Revision 1.10.14.3  2004/10/27 18:58:48  dave
46   *   Uncommented the rest of the tests ...
47   *
48   *   Revision 1.10.14.2  2004/10/27 10:56:30  dave
49   *   Changed inport init to save the details, and simplified tests for debug
50   *
51   *   Revision 1.10.14.1  2004/10/21 21:00:13  dave
52   *   Added mock://xyz URL handler to enable testing of transfer.
53   *   Implemented importInit to the mock service and created transfer tests.
54   *
55   *   Revision 1.10  2004/09/17 06:57:10  dave
56   *   Added commons logging to FileStore.
57   *   Updated logging properties in Community.
58   *   Fixed bug in AGINAB deployment.
59   *   Removed MySpace tests with hard coded grendel address.
60   *
61   *   Revision 1.9.16.1  2004/09/17 01:08:36  dave
62   *   Updated debug to use commons logging API ....
63   *
64   *   Revision 1.9  2004/09/02 10:25:41  dave
65   *   Updated FileStore and MySpace to handle mime type and file size.
66   *   Updated Community deployment script.
67   *
68   *   Revision 1.8.2.1  2004/09/01 02:58:07  dave
69   *   Updated to use external mime type for imported files.
70   *
71   *   Revision 1.8  2004/08/27 22:43:15  dave
72   *   Updated filestore and myspace to report file size correctly.
73   *
74   *   Revision 1.7.12.3  2004/08/27 11:48:41  dave
75   *   Added getContentSize to FileProperties.
76   *
77   *   Revision 1.7.12.2  2004/08/26 19:41:47  dave
78   *   Updated tests to check import URL size.
79   *
80   *   Revision 1.7.12.1  2004/08/26 19:06:50  dave
81   *   Modified filestore to return file size in properties.
82   *
83   *   Revision 1.7  2004/08/18 19:00:01  dave
84   *   Myspace manager modified to use remote filestore.
85   *   Tested before checkin - integration tests at 91%.
86   *
87   *   Revision 1.6.10.3  2004/08/09 10:16:28  dave
88   *   Added resource URL to the properties.
89   *
90   *   Revision 1.6.10.2  2004/08/06 22:25:06  dave
91   *   Refactored bits and broke a few tests ...
92   *
93   *   Revision 1.6.10.1  2004/08/02 14:54:15  dave
94   *   Trying to get integration tests to run
95   *
96   *   Revision 1.6  2004/07/23 09:11:16  dave
97   *   Merged development branch, dave-dev-200407221513, into HEAD
98   *
99   *   Revision 1.5.4.2  2004/07/23 03:37:06  dave
100  *   Debugged tests and parser bugs
101  *
102  *   Revision 1.5.4.1  2004/07/23 02:10:58  dave
103  *   Added IvornFactory and IvornParser
104  *
105  *   Revision 1.5  2004/07/22 13:40:26  dave
106  *   Merged development branch, dave-dev-200407211922, into HEAD
107  *
108  *   Revision 1.4.2.1  2004/07/22 13:10:37  dave
109  *   Updated integration test config
110  *
111  *   Revision 1.4  2004/07/21 18:11:55  dave
112  *   Merged development branch, dave-dev-200407201059, into HEAD
113  *
114  *   Revision 1.3.2.2  2004/07/21 16:28:16  dave
115  *   Added content properties and tests
116  *
117  *   Revision 1.3.2.1  2004/07/20 19:10:40  dave
118  *   Refactored to implement URL import
119  *
120  *   Revision 1.3  2004/07/19 23:42:07  dave
121  *   Merged development branch, dave-dev-200407151443, into HEAD
122  *
123  *   Revision 1.2.4.1  2004/07/19 19:40:28  dave
124  *   Debugged and worked around Axis Exception handling
125  *
126  *   Revision 1.2  2004/07/14 13:50:29  dave
127  *   Merged development branch, dave-dev-200406301228, into HEAD
128  *
129  *   Revision 1.1.2.5  2004/07/13 16:37:29  dave
130  *   Refactored common and client to use an array of FileProperties (more SOAP friendly)
131  *
132  *   Revision 1.1.2.4  2004/07/12 14:39:03  dave
133  *   Added server repository classes
134  *
135  *   Revision 1.1.2.3  2004/07/07 14:54:35  dave
136  *   Changed DataInfo to File Info (leaves room to use DataInfo for the more abstract VoStore interface).
137  *
138  *   Revision 1.1.2.2  2004/07/07 11:55:54  dave
139  *   Fixed byte array compare in tests
140  *
141  *   Revision 1.1.2.1  2004/07/05 04:50:29  dave
142  *   Created initial FileStore components
143  *
144  * </cvs:log>
145  *
146  */
147 package org.astrogrid.filestore.common ;
148 
149 import java.net.URL ;
150 import java.net.URLConnection ;
151 import java.net.HttpURLConnection ;
152 
153 import java.util.Date ;
154 
155 import java.io.OutputStream ;
156 import java.io.BufferedOutputStream;
157 import java.io.ByteArrayOutputStream;
158 
159 import junit.framework.TestCase ;
160 
161 import org.astrogrid.filestore.common.file.FileProperty ;
162 import org.astrogrid.filestore.common.file.FileProperties ;
163 import org.astrogrid.filestore.common.ivorn.FileStoreIvornFactory ;
164 import org.astrogrid.filestore.common.transfer.TransferProperties ;
165 import org.astrogrid.filestore.common.exception.FileStoreException ;
166 import org.astrogrid.filestore.common.exception.FileStoreNotFoundException ;
167 import org.astrogrid.filestore.common.exception.FileStoreIdentifierException ;
168 import org.astrogrid.filestore.common.exception.FileStoreTransferException ;
169 
170 import org.astrogrid.filestore.common.transfer.TransferUtil ;
171 import org.astrogrid.filestore.common.transfer.UrlGetRequest ;
172 import org.astrogrid.filestore.common.transfer.UrlGetTransfer ;
173 import org.astrogrid.filestore.common.transfer.UrlPutTransfer ;
174 import org.astrogrid.filestore.common.transfer.TransferProperties ;
175 
176 /***
177  * A JUnit test case for the store service.
178  *
179  */
180 public class FileStoreTest
181     extends TestCase
182     {
183     /***
184      * The name of our test property.
185      *
186      */
187     public static final String TEST_PROPERTY_NAME  = "test.property" ;
188 
189     /***
190      * The value of our test property.
191      *
192      */
193     public static final String TEST_PROPERTY_VALUE  = "alphabet" ;
194 
195     /***
196      * A test string.
197      * "A short test string ...."
198      *
199      */
200     public static final String TEST_STRING = "A short test string ...." ;
201 
202     /***
203      * A test string.
204      * " plus a bit more ...."
205      *
206      */
207     public static final String EXTRA_STRING = " plus a bit more ...." ;
208 
209     /***
210      * A test byte array.
211      * "A short byte array ...."
212      *
213      */
214     public static final byte[] TEST_BYTES = {
215         0x41,
216         0x20,
217         0x73,
218         0x68,
219         0x6f,
220         0x72,
221         0x74,
222         0x20,
223         0x62,
224         0x79,
225         0x74,
226         0x65,
227         0x20,
228         0x61,
229         0x72,
230         0x72,
231         0x61,
232         0x79,
233         0x20,
234         0x2e,
235         0x2e,
236         0x2e,
237         0x2e
238         } ;
239 
240     /***
241      * A test byte array.
242      * " plus a few more ...."
243      *
244      */
245     public static final byte[] EXTRA_BYTES = {
246         0x20,
247         0x70,
248         0x6c,
249         0x75,
250         0x73,
251         0x20,
252         0x61,
253         0x20,
254         0x66,
255         0x65,
256         0x77,
257         0x20,
258         0x6d,
259         0x6f,
260         0x72,
261         0x65,
262         0x20,
263         0x2e,
264         0x2e,
265         0x2e,
266         0x2e
267         } ;
268 
269     /***
270      * Test properties prefix.
271      *
272      */
273     public static final String TEST_PROPERTY_PREFIX = "org.astrogrid.filestore.test" ;
274 
275     /***
276      * Helper method to get a local property.
277      *
278      */
279     public String getTestProperty(String name)
280         {
281         return System.getProperty(TEST_PROPERTY_PREFIX + "." + name) ;
282         }
283 
284     /***
285      * Test utility to compare two arrays of bytes.
286      *
287      */
288     public static void assertEquals(byte[] left, byte[] right)
289         {
290         assertEquals(
291             "Different array length",
292             left.length,
293             right.length
294             ) ;
295         for (int i = 0 ; i < left.length ; i++)
296             {
297             assertEquals(
298                 "Wrong value for byte[" + i + "]",
299                 left[i],
300                 right[i]
301                 ) ;
302             }
303         }
304 
305     /***
306      * Internal reference to our target service.
307      *
308      */
309     protected FileStore target ;
310 
311     /***
312      * Test that we can get the service identifier..
313      *
314      */
315     public void testGetServiceIdentifier()
316         throws Exception
317         {
318         assertNotNull(
319             "Null service identifier",
320             target.identifier()
321             ) ;
322         }
323 
324     /***
325      * Check the identifier properties.
326      *
327      */
328     protected void checkIdentProperties(FileProperty[] properties)
329         throws Exception
330         {
331         checkIdentProperties(
332             new FileProperties(
333                 properties
334                 )
335             ) ;
336         }
337 
338     /***
339      * Check the identifier properties.
340      *
341      */
342     protected void checkIdentProperties(FileProperties properties)
343         throws Exception
344         {
345         //
346         // Check the info is not null.
347         assertNotNull(
348             "Null properties",
349             properties
350             ) ;
351         //
352         // Check the server ivorn is correct.
353         assertEquals(
354             "Wrong service ivorn in FileProperties",
355             target.identifier(),
356             properties.getStoreServiceIvorn().toString()
357             ) ;
358         //
359         // Check the resource ident is not null.
360         assertNotNull(
361             "Null resource ident in properties",
362             properties.getStoreResourceIdent()
363             ) ;
364         //
365         // Check the resource ivorn is correct.
366         assertEquals(
367             "Wrong resource ident in properties",
368             properties.getStoreResourceIvorn().toString(),
369             FileStoreIvornFactory.createIdent(
370                 target.identifier(),
371                 properties.getStoreResourceIdent()
372                 )
373             ) ;
374         //
375         // Check the resource URL is not null.
376         assertNotNull(
377             "Null resource URL in properties",
378             properties.getProperty(
379                 FileProperties.STORE_RESOURCE_URL
380                 )
381             ) ;
382         }
383 
384     /***
385      * Set the type properties.
386      *
387      */
388     protected void configTypeProperties(FileProperties properties, String mime)
389         {
390         properties.setProperty(
391             FileProperties.MIME_TYPE_PROPERTY,
392             mime
393             ) ;
394         }
395 
396     /***
397      * Check the type properties.
398      *
399      */
400     protected void checkTypeProperties(FileProperties properties, String mime)
401         throws Exception
402         {
403         //
404         // Check the info is not null.
405         assertNotNull(
406             "Null properties",
407             properties
408             ) ;
409         //
410         // Check the mime type.
411         assertEquals(
412             "Wrong mime type property",
413             mime,
414             properties.getProperty(
415                 FileProperties.MIME_TYPE_PROPERTY
416                 )
417             ) ;
418         }
419 
420     /***
421      * Set the test property.
422      *
423      */
424     protected void configTestProperty(FileProperties properties, String value)
425         {
426         properties.setProperty(
427             TEST_PROPERTY_NAME,
428             value
429             ) ;
430         }
431 
432     /***
433      * Check the test property.
434      *
435      */
436     protected void checkTestProperty(FileProperties properties, String value)
437         throws Exception
438         {
439         //
440         // Check the ivoa type.
441         assertEquals(
442             "Wrong test property value",
443             value,
444             properties.getProperty(
445                 TEST_PROPERTY_NAME
446                 )
447             ) ;
448         }
449 
450 //
451 // Import strings.
452 //
453 
454     /***
455      * Check we get the right Exception if we import a null string.
456      *
457      */
458     public void testImportNullString()
459         throws Exception
460         {
461         try {
462             target.importString(
463                 null,
464                 null
465                 ) ;
466             }
467         catch (FileStoreException ouch)
468             {
469             return ;
470             }
471         fail("Expected FileStoreException") ;
472         }
473 
474     /***
475      * Check we can import a string.
476      *
477      */
478     public void testImportString()
479         throws Exception
480         {
481         //
482         // Import the test string.
483         FileProperties properties = new FileProperties(
484             target.importString(
485                 null,
486                 TEST_STRING
487                 )
488             ) ;
489         //
490         // Check the identifier properties.
491         checkIdentProperties(
492             properties
493             ) ;
494         //
495         // Check the type properties.
496         checkTypeProperties(
497             properties,
498             null
499             ) ;
500         //
501         // Check the test properties.
502         checkTestProperty(
503             properties,
504             null
505             ) ;
506         }
507 
508     /***
509      * Check we can store a string, with additional info.
510      *
511      */
512     public void testImportStringInfo()
513         throws Exception
514         {
515         //
516         // Create our data info.
517         FileProperties properties = new FileProperties() ;
518         //
519         // Set the type properties.
520         configTypeProperties(
521             properties,
522             FileProperties.MIME_TYPE_XML
523             ) ;
524         //
525         // Set the test properties.
526         configTestProperty(
527             properties,
528             TEST_PROPERTY_VALUE
529             ) ;
530         //
531         // Import the test string.
532         FileProperties imported = new FileProperties(
533             target.importString(
534                 properties.toArray(),
535                 TEST_STRING
536                 )
537             ) ;
538         //
539         // Check the identifier properties.
540         checkIdentProperties(
541             imported
542             ) ;
543         //
544         // Check the type properties.
545         checkTypeProperties(
546             imported,
547             FileProperties.MIME_TYPE_XML
548             ) ;
549         //
550         // Check the test properties.
551         checkTestProperty(
552             imported,
553             TEST_PROPERTY_VALUE
554             ) ;
555         }
556 
557     /***
558      * Check we get the right Exception for a null ident.
559      *
560      */
561     public void testExportNullString()
562         throws Exception
563         {
564         try {
565             target.exportString(
566                 null
567                 ) ;
568             }
569         catch (FileStoreIdentifierException ouch)
570             {
571             return ;
572             }
573         fail("Expected FileStoreIdentifierException") ;
574         }
575 
576     /***
577      * Check we get the right Exception for an unknown ident.
578      *
579      */
580     public void testExportUnknownString()
581         throws Exception
582         {
583         try {
584             target.exportString(
585                 "unknown"
586                 ) ;
587             }
588         catch (FileStoreNotFoundException ouch)
589             {
590             return ;
591             }
592         fail("Expected FileStoreNotFoundException") ;
593         }
594 
595     /***
596      * Check we can import a string and export it as a string.
597      *
598      */
599     public void testImportStringExportString()
600         throws Exception
601         {
602         //
603         // Import the test string.
604         FileProperties imported = new FileProperties(
605             target.importString(
606                 null,
607                 TEST_STRING
608                 )
609             ) ;
610         //
611         // Check the identifier properties.
612         checkIdentProperties(
613             imported
614             ) ;
615         //
616         // Check that we get the same string back.
617         assertEquals(
618             "Wrong string returned",
619             TEST_STRING,
620             target.exportString(
621                 imported.getStoreResourceIdent()
622                 )
623             ) ;
624         }
625 
626     /***
627      * Check we can import a string and export it as bytes.
628      *
629      */
630     public void testImportStringExportBytes()
631         throws Exception
632         {
633         //
634         // Import the test string.
635         FileProperties imported = new FileProperties(
636             target.importString(
637                 null,
638                 TEST_STRING
639                 )
640             ) ;
641         //
642         // Check the identifier properties.
643         checkIdentProperties(
644             imported
645             ) ;
646         //
647         // Check that we get the same string back.
648         assertEquals(
649             "Wrong bytes returned",
650             TEST_STRING,
651             new String(
652                 target.exportBytes(
653                     imported.getStoreResourceIdent()
654                     )
655                 )
656             ) ;
657         }
658 
659     /***
660      * Check we get the right Exception if we import a null byte array.
661      *
662      */
663     public void testImportNullBytes()
664         throws Exception
665         {
666         try {
667             target.importBytes(
668                 null,
669                 null
670                 ) ;
671             }
672         catch (FileStoreException ouch)
673             {
674             return ;
675             }
676         fail("Expected FileStoreException") ;
677         }
678 
679     /***
680      * Check we can import a byte array.
681      *
682      */
683     public void testImportBytes()
684         throws Exception
685         {
686         FileProperties imported = new FileProperties(
687             target.importBytes(
688                 null,
689                 TEST_BYTES
690                 )
691             ) ;
692         //
693         // Check the identifier properties.
694         checkIdentProperties(
695             imported
696             ) ;
697         //
698         // Check the type properties.
699         checkTypeProperties(
700             imported,
701             null
702             ) ;
703         //
704         // Check the test properties.
705         checkTestProperty(
706             imported,
707             null
708             ) ;
709         }
710 
711     /***
712      * Check we can import a byte array, with additional info.
713      *
714      */
715     public void testImportBytesInfo()
716         throws Exception
717         {
718         //
719         // Create our data info.
720         FileProperties properties = new FileProperties() ;
721         //
722         // Set the type properties.
723         configTypeProperties(
724             properties,
725             FileProperties.MIME_TYPE_XML
726             ) ;
727         //
728         // Set the test properties.
729         configTestProperty(
730             properties,
731             TEST_PROPERTY_VALUE
732             ) ;
733         //
734         // Import the test bytes.
735         FileProperties imported = new FileProperties(
736             target.importBytes(
737                 properties.toArray(),
738                 TEST_BYTES
739                 )
740             ) ;
741         //
742         // Check the identifier properties.
743         checkIdentProperties(
744             imported
745             ) ;
746         //
747         // Check the type properties.
748         checkTypeProperties(
749             imported,
750             FileProperties.MIME_TYPE_XML
751             ) ;
752         //
753         // Check the test properties.
754         checkTestProperty(
755             imported,
756             TEST_PROPERTY_VALUE
757             ) ;
758         }
759 
760     /***
761      * Check we get the right Exception for a null ident.
762      *
763      */
764     public void testExportNullBytes()
765         throws Exception
766         {
767         try {
768             target.exportBytes(
769                 null
770                 ) ;
771             }
772         catch (FileStoreIdentifierException ouch)
773             {
774             return ;
775             }
776         fail("Expected FileStoreIdentifierException") ;
777         }
778 
779     /***
780      * Check we get the right Exception for an unknown ident.
781      *
782      */
783     public void testExportUnknownBytes()
784         throws Exception
785         {
786         try {
787             target.exportBytes(
788                 "unknown"
789                 ) ;
790             }
791         catch (FileStoreNotFoundException ouch)
792             {
793             return ;
794             }
795         fail("Expected FileStoreNotFoundException") ;
796         }
797 
798     /***
799      * Check we can import bytes and export it as bytes.
800      *
801      */
802     public void testImportBytesExportBytes()
803         throws Exception
804         {
805         //
806         // Import the test bytes.
807         FileProperties imported = new FileProperties(
808             target.importBytes(
809                 null,
810                 TEST_BYTES
811                 )
812             ) ;
813         //
814         // Check the identifier properties.
815         checkIdentProperties(
816             imported
817             ) ;
818         //
819         // Check that we get the same data back.
820         assertEquals(
821             TEST_BYTES,
822             target.exportBytes(
823                 imported.getStoreResourceIdent()
824                 )
825             ) ;
826         }
827 
828     /***
829      * Check we can import bytes and export it as a string.
830      *
831      */
832     public void testImportBytesExportString()
833         throws Exception
834         {
835         //
836         // Import the test bytes.
837         FileProperties imported = new FileProperties(
838             target.importBytes(
839                 null,
840                 TEST_BYTES
841                 )
842             ) ;
843         //
844         // Check the identifier properties.
845         checkIdentProperties(
846             imported
847             ) ;
848         //
849         // Check that we get the right string back.
850         assertEquals(
851             "Wrong bytes returned",
852             new String(
853                 TEST_BYTES
854                 ),
855             target.exportString(
856                 imported.getStoreResourceIdent()
857                 )
858             ) ;
859         }
860 
861     /***
862      * Check we get the right Exception for a null ident.
863      *
864      */
865     public void testRequestNullInfo()
866         throws Exception
867         {
868         try {
869             target.properties(
870                 null
871                 ) ;
872             }
873         catch (FileStoreIdentifierException ouch)
874             {
875             return ;
876             }
877         fail("Expected FileStoreIdentifierException") ;
878         }
879 
880     /***
881      * Check we get the right Exception for an unknown ident.
882      *
883      */
884     public void testRequestUnknownInfo()
885         throws Exception
886         {
887         try {
888             target.properties(
889                 "unknown"
890                 ) ;
891             }
892         catch (FileStoreNotFoundException ouch)
893             {
894             return ;
895             }
896         fail("Expected FileStoreNotFoundException") ;
897         }
898 
899     /***
900      * Check we can import a string and request the info for it.
901      *
902      */
903     public void testRequestStringInfo()
904         throws Exception
905         {
906         //
907         // Store the test string.
908         FileProperties imported = new FileProperties(
909             target.importString(
910                 null,
911                 TEST_STRING
912                 )
913             ) ;
914         //
915         // Check that we can find it.
916         FileProperties requested = new FileProperties(
917             target.properties(
918                 imported.getStoreResourceIdent()
919                 )
920             ) ;
921         //
922         // Check the identifiers are the same.
923         assertEquals(
924             "Requested ident not the same as imported",
925             imported.getStoreResourceIdent(),
926             requested.getStoreResourceIdent()
927             ) ;
928         }
929 
930     /***
931      * Check we can import bytes and request the info for it.
932      *
933      */
934     public void testRequestBytesInfo()
935         throws Exception
936         {
937         //
938         // Store the test string.
939         FileProperties imported = new FileProperties(
940             target.importBytes(
941                 null,
942                 TEST_BYTES
943                 )
944             ) ;
945         //
946         // Check that we can find it.
947         FileProperties requested = new FileProperties(
948             target.properties(
949                 imported.getStoreResourceIdent()
950                 )
951             ) ;
952         //
953         // Check the identifiers are the same.
954         assertEquals(
955             "Requested ident not the same as imported",
956             imported.getStoreResourceIdent(),
957             requested.getStoreResourceIdent()
958             ) ;
959         }
960 
961     /***
962      * Check we get the right Exception for a null ident.
963      *
964      */
965     public void testDeleteNull()
966         throws Exception
967         {
968         try {
969             target.delete(
970                 null
971                 ) ;
972             }
973         catch (FileStoreIdentifierException ouch)
974             {
975             return ;
976             }
977         fail("Expected FileStoreIdentifierException") ;
978         }
979 
980     /***
981      * Check we get the right Exception for an unknown ident.
982      *
983      */
984     public void testDeleteUnknown()
985         throws Exception
986         {
987         try {
988             target.delete(
989                 "unknown"
990                 ) ;
991             }
992         catch (FileStoreNotFoundException ouch)
993             {
994             return ;
995             }
996         fail("Expected FileStoreNotFoundException") ;
997         }
998 
999     /***
1000      * Check we can import a string and delete it.
1001      *
1002      */
1003     public void testDeleteString()
1004         throws Exception
1005         {
1006         //
1007         // Store the test string.
1008         FileProperties imported = new FileProperties(
1009             target.importString(
1010                 null,
1011                 TEST_STRING
1012                 )
1013             ) ;
1014         //
1015         // Check that we can delete it.
1016         FileProperties deleted = new FileProperties(
1017             target.delete(
1018                 imported.getStoreResourceIdent()
1019                 )
1020             ) ;
1021         //
1022         // Check the properties are the same.
1023         assertEquals(
1024             "Deleted properties not the same as imported",
1025             imported.getStoreResourceIdent(),
1026             deleted.getStoreResourceIdent()
1027             ) ;
1028         }
1029 
1030     /***
1031      * Check we can import a byte array and delete it.
1032      *
1033      */
1034     public void testDeleteBytes()
1035         throws Exception
1036         {
1037         //
1038         // Store the test string.
1039         FileProperties imported = new FileProperties(
1040             target.importBytes(
1041                 null,
1042                 TEST_BYTES
1043                 )
1044             ) ;
1045         //
1046         // Check that we can delete it.
1047         FileProperties deleted = new FileProperties(
1048             target.delete(
1049                 imported.getStoreResourceIdent()
1050                 )
1051             ) ;
1052         //
1053         // Check the properties are the same.
1054         assertEquals(
1055             "Deleted properties not the same as imported",
1056             imported.getStoreResourceIdent(),
1057             deleted.getStoreResourceIdent()
1058             ) ;
1059         }
1060 
1061     /***
1062      * Check we can't query the info on something that we have deleted.
1063      *
1064      */
1065     public void testInfoDeleted()
1066         throws Exception
1067         {
1068         //
1069         // Store the test string.
1070         FileProperties imported = new FileProperties(
1071             target.importString(
1072                 null,
1073                 TEST_STRING
1074                 )
1075             ) ;
1076         //
1077         // Check that we can delete it.
1078         FileProperties deleted = new FileProperties(
1079             target.delete(
1080                 imported.getStoreResourceIdent()
1081                 )
1082             ) ;
1083         //
1084         // Check that we can't find it.
1085         try {
1086             target.properties(
1087                 imported.getStoreResourceIdent()
1088                 ) ;
1089             }
1090         catch (FileStoreNotFoundException ouch)
1091             {
1092             return ;
1093             }
1094         fail("Expected FileStoreNotFoundException") ;
1095         }
1096 
1097     /***
1098      * Check we can't export something that we have deleted.
1099      *
1100      */
1101     public void testExportDeleted()
1102         throws Exception
1103         {
1104         //
1105         // Store the test string.
1106         FileProperties imported = new FileProperties(
1107             target.importString(
1108                 null,
1109                 TEST_STRING
1110                 )
1111             ) ;
1112         //
1113         // Check that we can delete it.
1114         FileProperties deleted = new FileProperties(
1115             target.delete(
1116                 imported.getStoreResourceIdent()
1117                 )
1118             ) ;
1119         //
1120         // Check that we can't export it.
1121         try {
1122             target.exportString(
1123                 imported.getStoreResourceIdent()
1124                 ) ;
1125             }
1126         catch (FileStoreNotFoundException ouch)
1127             {
1128             return ;
1129             }
1130         fail("Expected FileStoreNotFoundException") ;
1131         }
1132 
1133     /***
1134      * Check we get the right Exception for a null string.
1135      *
1136      */
1137     public void testAppendNullString()
1138         throws Exception
1139         {
1140         try {
1141             target.appendString(
1142                 "anything",
1143                 null
1144                 ) ;
1145             }
1146         catch (FileStoreException ouch)
1147             {
1148             return ;
1149             }
1150         fail("Expected FileStoreException") ;
1151         }
1152 
1153     /***
1154      * Check we get the right Exception for a null ident.
1155      *
1156      */
1157     public void testAppendStringNullIdent()
1158         throws Exception
1159         {
1160         try {
1161             target.appendString(
1162                 null,
1163                 EXTRA_STRING
1164                 ) ;
1165             }
1166         catch (FileStoreIdentifierException ouch)
1167             {
1168             return ;
1169             }
1170         fail("Expected FileStoreIdentifierException") ;
1171         }
1172 
1173     /***
1174      * Check we get the right Exception for an unknown ident.
1175      *
1176      */
1177     public void testAppendStringUnknownIdent()
1178         throws Exception
1179         {
1180         try {
1181             target.appendString(
1182                 "unknown",
1183                 EXTRA_STRING
1184                 ) ;
1185             }
1186         catch (FileStoreNotFoundException ouch)
1187             {
1188             return ;
1189             }
1190         fail("Expected FileStoreNotFoundException") ;
1191         }
1192 
1193     /***
1194      * Check we can append a string.
1195      *
1196      */
1197     public void testImportStringAppendString()
1198         throws Exception
1199         {
1200         //
1201         // Import the test string.
1202         FileProperties imported = new FileProperties(
1203             target.importString(
1204                 null,
1205                 TEST_STRING
1206                 )
1207             ) ;
1208         //
1209         // Append the extra string.
1210         FileProperties modified = new FileProperties(
1211             target.appendString(
1212                 imported.getStoreResourceIdent(),
1213                 EXTRA_STRING
1214                 )
1215             ) ;
1216         //
1217         // Check we get the right string back.
1218         assertEquals(
1219             "Wrong string returned",
1220             (TEST_STRING + EXTRA_STRING),
1221             target.exportString(
1222                 modified.getStoreResourceIdent()
1223                 )
1224             ) ;
1225         }
1226 
1227     /***
1228      * Check we can append some bytes.
1229      *
1230      */
1231     public void testImportStringAppendBytes()
1232         throws Exception
1233         {
1234         //
1235         // Import the test string.
1236         FileProperties imported = new FileProperties(
1237             target.importString(
1238                 null,
1239                 TEST_STRING
1240                 )
1241             ) ;
1242         //
1243         // Append the extra string.
1244         FileProperties modified = new FileProperties(
1245             target.appendBytes(
1246                 imported.getStoreResourceIdent(),
1247                 EXTRA_BYTES
1248                 )
1249             ) ;
1250         //
1251         // Check we get the right string back.
1252         assertEquals(
1253             "Wrong string returned",
1254             (TEST_STRING + new String(EXTRA_BYTES)),
1255             target.exportString(
1256                 modified.getStoreResourceIdent()
1257                 )
1258             ) ;
1259         }
1260 
1261     /***
1262      * Check we get the right Exception for a null ident.
1263      *
1264      */
1265     public void testDuplicateNullIdent()
1266         throws Exception
1267         {
1268         try {
1269             target.duplicate(
1270                 null,
1271                 null
1272                 ) ;
1273             }
1274         catch (FileStoreIdentifierException ouch)
1275             {
1276             return ;
1277             }
1278         fail("Expected FileStoreIdentifierException") ;
1279         }
1280 
1281     /***
1282      * Check we get the right Exception for an unknown ident.
1283      *
1284      */
1285     public void testDuplicateUnknownIdent()
1286         throws Exception
1287         {
1288         try {
1289             target.duplicate(
1290                 "unknown",
1291                 null
1292                 ) ;
1293             }
1294         catch (FileStoreNotFoundException ouch)
1295             {
1296             return ;
1297             }
1298         fail("Expected FileStoreNotFoundException") ;
1299         }
1300 
1301     /***
1302      * Check a duplicate gets a new ident.
1303      *
1304      */
1305     public void testDuplicateIdent()
1306         throws Exception
1307         {
1308         //
1309         // Import the test string.
1310         FileProperties imported = new FileProperties(
1311             target.importString(
1312                 null,
1313                 TEST_STRING
1314                 )
1315             ) ;
1316         //
1317         // Create a duplicate
1318         FileProperties duplicate = new FileProperties(
1319             target.duplicate(
1320                 imported.getStoreResourceIdent(),
1321                 null
1322                 )
1323             ) ;
1324         //
1325         // Check the identifiers are different.
1326         assertFalse(
1327             "Duplicate identifiers",
1328             imported.getStoreResourceIdent().equals(
1329                 duplicate.getStoreResourceIdent()
1330                 )
1331             ) ;
1332         }
1333 
1334     /***
1335      * Check a duplicate gets the right data.
1336      *
1337      */
1338     public void testDuplicateString()
1339         throws Exception
1340         {
1341         //
1342         // Import the test string.
1343         FileProperties imported = new FileProperties(
1344             target.importString(
1345                 null,
1346                 TEST_STRING
1347                 )
1348             ) ;
1349         //
1350         // Create a duplicate
1351         FileProperties duplicate = new FileProperties(
1352             target.duplicate(
1353                 imported.getStoreResourceIdent(),
1354                 null
1355                 )
1356             ) ;
1357         //
1358         // Check we get the same string back.
1359         assertEquals(
1360             "Wrong string returned",
1361             TEST_STRING,
1362             target.exportString(
1363                 duplicate.getStoreResourceIdent()
1364                 )
1365             ) ;
1366         }
1367 
1368     /***
1369      * Check a duplicate gets the right info.
1370      *
1371      */
1372     public void testDuplicateInfo()
1373         throws Exception
1374         {
1375         //
1376         // Create our data info.
1377         FileProperties properties = new FileProperties() ;
1378         //
1379         // Set the type properties.
1380         configTypeProperties(
1381             properties,
1382             FileProperties.MIME_TYPE_XML
1383             ) ;
1384         //
1385         // Set the test properties.
1386         configTestProperty(
1387             properties,
1388             TEST_PROPERTY_VALUE
1389             ) ;
1390         //
1391         // Import the test bytes.
1392         FileProperties imported = new FileProperties(
1393             target.importBytes(
1394                 properties.toArray(),
1395                 TEST_BYTES
1396                 )
1397             ) ;
1398         //
1399         // Create a duplicate
1400         FileProperties duplicate = new FileProperties(
1401             target.duplicate(
1402                 imported.getStoreResourceIdent(),
1403                 null
1404                 )
1405             ) ;
1406         //
1407         // Check the identifier properties.
1408         checkIdentProperties(
1409             duplicate
1410             ) ;
1411         //
1412         // Check the type properties.
1413         checkTypeProperties(
1414             duplicate,
1415             FileProperties.MIME_TYPE_XML
1416             ) ;
1417         //
1418         // Check the test properties.
1419         checkTestProperty(
1420             duplicate,
1421             TEST_PROPERTY_VALUE
1422             ) ;
1423         }
1424 
1425     /***
1426      * Check we can modify a duplicate.
1427      *
1428      */
1429     public void testDuplicateAppend()
1430         throws Exception
1431         {
1432         //
1433         // Import the test string.
1434         FileProperties imported = new FileProperties(
1435             target.importString(
1436                 null,
1437                 TEST_STRING
1438                 )
1439             ) ;
1440         //
1441         // Create a duplicate.
1442         FileProperties duplicate = new FileProperties(
1443             target.duplicate(
1444                 imported.getStoreResourceIdent(),
1445                 null
1446                 )
1447             ) ;
1448         //
1449         // Modify the duplicate.
1450         FileProperties modified = new FileProperties(
1451             target.appendString(
1452                 duplicate.getStoreResourceIdent(),
1453                 EXTRA_STRING
1454                 )
1455             ) ;
1456         //
1457         // Check the original is unchanged.
1458         assertEquals(
1459             "Wrong string returned",
1460             TEST_STRING,
1461             target.exportString(
1462                 imported.getStoreResourceIdent()
1463                 )
1464             ) ;
1465         //
1466         // Check the duplicate has changed.
1467         assertEquals(
1468             "Wrong string returned",
1469             (TEST_STRING + EXTRA_STRING),
1470             target.exportString(
1471                 modified.getStoreResourceIdent()
1472                 )
1473             ) ;
1474         }
1475 
1476     /***
1477      * Check we get the right Exception for a null url.
1478      *
1479      */
1480     public void testCreateNullUrlGetTransfer()
1481         throws Exception
1482         {
1483         try {
1484             new UrlGetTransfer(
1485                 null
1486                 ) ;
1487             }
1488         catch (IllegalArgumentException ouch)
1489             {
1490             return ;
1491             }
1492         fail("Expected IllegalArgumentException") ;
1493         }
1494 
1495     /***
1496      * Check we can create a transfer info.
1497      *
1498      */
1499     public void testCreateUrlGetTransfer()
1500         throws Exception
1501         {
1502         assertNotNull(
1503             "Null transfer info",
1504             new UrlGetTransfer(
1505                 new URL(
1506                     getTestProperty(
1507                         "data.file.text"
1508                         )
1509                     )
1510                 )
1511             ) ;
1512         }
1513 
1514     /***
1515      * Check we get the right Exception for a null transfer properties.
1516      *
1517      */
1518     public void testImportNullTransfer()
1519         throws Exception
1520         {
1521         try {
1522             target.importData(
1523                 null
1524                 ) ;
1525             }
1526         catch (FileStoreTransferException ouch)
1527             {
1528             return ;
1529             }
1530         fail("Expected FileStoreTransferException") ;
1531         }
1532 
1533     /***
1534      * Check that we get the right exception from a failed import.
1535      *
1536      */
1537     public void testImportMissing()
1538         throws Exception
1539         {
1540         try {
1541             target.importData(
1542                 new UrlGetTransfer(
1543                     new URL(
1544                         getTestProperty(
1545                             "data.file.miss"
1546                             )
1547                         )
1548                     )
1549                 ) ;
1550             }
1551         catch (FileStoreTransferException ouch)
1552             {
1553             return ;
1554             }
1555         fail("Expected FileStoreTransferException") ;
1556         }
1557 
1558     /***
1559      * Check that we can import a local file.
1560      *
1561      */
1562     public void testImportFile()
1563         throws Exception
1564         {
1565         TransferProperties transfer = 
1566             target.importData(
1567                 new UrlGetTransfer(
1568                     new URL(
1569                         getTestProperty(
1570                             "data.file.text"
1571                             )
1572                         )
1573                     )
1574                 ) ;
1575         assertNotNull(
1576             "Null transfer properties",
1577             transfer
1578             ) ;
1579         }
1580 
1581     /***
1582      * Check that we can import from a http server.
1583      *
1584      */
1585     public void testImportHttp()
1586         throws Exception
1587         {
1588         TransferProperties transfer = 
1589             target.importData(
1590                 new UrlGetTransfer(
1591                     new URL(
1592                         getTestProperty(
1593                             "data.http.html"
1594                             )
1595                         )
1596                     )
1597                 ) ;
1598         assertNotNull(
1599             "Null transfer properties",
1600             transfer
1601             ) ;
1602         }
1603 
1604     /***
1605      * Check that we get valid file properties from an import.
1606      *
1607      */
1608     public void testImportProperties()
1609         throws Exception
1610         {
1611         TransferProperties transfer = 
1612             target.importData(
1613                 new UrlGetTransfer(
1614                     new URL(
1615                         getTestProperty(
1616                             "data.file.text"
1617                             )
1618                         )
1619                     )
1620                 ) ;
1621         assertNotNull(
1622             "Null transfer properties",
1623             transfer
1624             ) ;
1625         checkIdentProperties(
1626             transfer.getFileProperties()
1627             ) ;
1628         }
1629 
1630 //
1631 // Check test properties after an import.
1632 //
1633 
1634 //
1635 // Check the source URL after an import.
1636 //
1637 
1638 //
1639 // Check the MD5 after an import.
1640 //
1641 
1642     /***
1643      * Check that an imported file contains the right content.
1644      *
1645      */
1646     public void testImportContent()
1647         throws Exception
1648         {
1649         //
1650         // Import a text file.
1651         TransferProperties transfer = 
1652             target.importData(
1653                 new UrlGetTransfer(
1654                     new URL(
1655                         getTestProperty(
1656                             "data.file.text"
1657                             )
1658                         )
1659                     )
1660                 ) ;
1661         //
1662         // Get the imported data properties.
1663         FileProperties imported = new FileProperties(
1664             transfer.getFileProperties()
1665             ) ;
1666         //
1667         // Check the imported content.
1668         assertEquals(
1669             "Wrong content from URL import",
1670             TEST_STRING,
1671             target.exportString(
1672                 imported.getStoreResourceIdent()
1673                 )
1674             ) ;
1675         }
1676 
1677     /***
1678      * Check that imported HTML has the right type.
1679      *
1680      */
1681     public void testImportTypeHtml()
1682         throws Exception
1683         {
1684         //
1685         // Import a text file.
1686         TransferProperties transfer = 
1687             target.importData(
1688                 new UrlGetTransfer(
1689                     new URL(
1690                         getTestProperty(
1691                             "data.http.html"
1692                             )
1693                         )
1694                     )
1695                 ) ;
1696         //
1697         // Get the imported data properties.
1698         FileProperties imported = new FileProperties(
1699             transfer.getFileProperties()
1700             ) ;
1701         //
1702         // Check the imported data has the right type.
1703         checkTypeProperties(
1704             imported,
1705             "text/html; charset=ISO-8859-1"
1706             ) ;
1707         }
1708 
1709     /***
1710      * Check that an imported jar has the right type.
1711      *
1712      */
1713     public void testImportTypeJar()
1714         throws Exception
1715         {
1716         //
1717         // Import a text file.
1718         TransferProperties transfer = 
1719             target.importData(
1720                 new UrlGetTransfer(
1721                     new URL(
1722                         getTestProperty(
1723                             "data.http.jar"
1724                             )
1725                         )
1726                     )
1727                 ) ;
1728         //
1729         // Get the imported data properties.
1730         FileProperties imported = new FileProperties(
1731             transfer.getFileProperties()
1732             ) ;
1733         //
1734         // Check the imported data has the right type.
1735         checkTypeProperties(
1736             imported,
1737             "text/plain; charset=ISO-8859-1"
1738             ) ;
1739         }
1740 
1741     /***
1742      * Check that an imported properties has the right source.
1743      *
1744      */
1745     public void testImportSource()
1746         throws Exception
1747         {
1748         //
1749         // Import a text file.
1750         TransferProperties transfer = 
1751             target.importData(
1752                 new UrlGetTransfer(
1753                     new URL(
1754                         getTestProperty(
1755                             "data.http.html"
1756                             )
1757                         )
1758                     )
1759                 ) ;
1760         //
1761         // Get the imported data properties.
1762         FileProperties imported = new FileProperties(
1763             transfer.getFileProperties()
1764             ) ;
1765         //
1766         // Check the imported data has the right source.
1767         assertEquals(
1768             "Wrong string returned",
1769             getTestProperty(
1770                 "data.http.html"
1771                 ),
1772             imported.getProperty(
1773                 FileProperties.TRANSFER_SOURCE_URL
1774                 )
1775             ) ;
1776         }
1777 
1778     /***
1779      * Check that an imported byte array has the right size.
1780      *
1781      */
1782     public void testImportBytesSize()
1783         throws Exception
1784         {
1785         //
1786         // Import some bytes.
1787         FileProperties imported = new FileProperties(
1788             target.importBytes(
1789                 null,
1790                 TEST_BYTES
1791                 )
1792             ) ;
1793         //
1794         // Check the imported file size.
1795         assertEquals(
1796             TEST_BYTES.length,
1797             imported.getContentSize()
1798             ) ;
1799         }
1800 
1801     /***
1802      * Check that an imported string has the right size.
1803      *
1804      */
1805     public void testImportStringSize()
1806         throws Exception
1807         {
1808         //
1809         // Import the test string.
1810         FileProperties imported = new FileProperties(
1811             target.importString(
1812                 null,
1813                 TEST_STRING
1814                 )
1815             ) ;
1816         //
1817         // Check the imported file size.
1818         assertEquals(
1819             TEST_STRING.getBytes().length,
1820             imported.getContentSize()
1821             ) ;
1822         }
1823 
1824     /***
1825      * Check that an appended byte array has the right size.
1826      *
1827      */
1828     public void testAppendBytesSize()
1829         throws Exception
1830         {
1831         //
1832         // Import some bytes.
1833         FileProperties imported = new FileProperties(
1834             target.importBytes(
1835                 null,
1836                 TEST_BYTES
1837                 )
1838             ) ;
1839         //
1840         // Append some bytes.
1841         FileProperties modified = new FileProperties(
1842             target.appendBytes(
1843                 imported.getStoreResourceIdent(),
1844                 EXTRA_BYTES
1845                 )
1846             ) ;
1847         //
1848         // Check the imported file size.
1849         assertEquals(
1850             TEST_BYTES.length + EXTRA_BYTES.length,
1851             modified.getContentSize()
1852             ) ;
1853         }
1854 
1855     /***
1856      * Check that an imported file URL has the right size.
1857      *
1858      */
1859     public void testImportFileUrlSize()
1860         throws Exception
1861         {
1862         //
1863         // Create our URL.
1864         URL url = new URL(
1865             getTestProperty(
1866                 "data.file.text"
1867                 )
1868             ) ;
1869         //
1870         // Import some bytes.
1871         TransferProperties transfer = 
1872             target.importData(
1873                 new UrlGetTransfer(
1874                     url
1875                     )
1876                 ) ;
1877         //
1878         // Get the file properties.
1879         FileProperties properties = new FileProperties(
1880             transfer.getFileProperties()
1881             ) ;
1882         //
1883         // Check the imported file size.
1884         assertEquals(
1885             url.openConnection().getContentLength(),
1886             properties.getContentSize()
1887             ) ;
1888         }
1889 
1890     /***
1891      * Check that an imported http URL has the right size.
1892      *
1893      */
1894     public void testImportHttpUrlSize()
1895         throws Exception
1896         {
1897         //
1898         // Create our URL.
1899         URL url = new URL(
1900             getTestProperty(
1901                 "data.http.jar"
1902                 )
1903             ) ;
1904         //
1905         // Import the data.
1906         TransferProperties transfer = 
1907             target.importData(
1908                 new UrlGetTransfer(
1909                     url
1910                     )
1911                 ) ;
1912         //
1913         // Get the file properties.
1914         FileProperties properties = new FileProperties(
1915             transfer.getFileProperties()
1916             ) ;
1917         //
1918         // Check the imported file size.
1919         assertEquals(
1920             url.openConnection().getContentLength(),
1921             properties.getContentSize()
1922             ) ;
1923         }
1924 
1925     /***
1926      * Check that imported string has the right type.
1927      *
1928      */
1929     public void testImportStringAsXmlVotable()
1930         throws Exception
1931         {
1932         //
1933         // Create our data info.
1934         FileProperties properties = new FileProperties() ;
1935         //
1936         // Set the mime type property.
1937         properties.setProperty(
1938             FileProperties.MIME_TYPE_PROPERTY,
1939             FileProperties.MIME_TYPE_VOTABLE
1940             ) ;
1941         //
1942         // Import the test string.
1943         FileProperties imported = new FileProperties(
1944             target.importString(
1945                 properties.toArray(),
1946                 TEST_STRING
1947                 )
1948             ) ;
1949         //
1950         // Get the file properties.
1951         FileProperties requested = new FileProperties(
1952             target.properties(
1953                 imported.getStoreResourceIdent()
1954                 )
1955             ) ;
1956         //
1957         // Check the mime type.
1958         assertEquals(
1959             FileProperties.MIME_TYPE_VOTABLE,
1960             requested.getProperty(
1961                 FileProperties.MIME_TYPE_PROPERTY
1962                 )
1963             ) ;
1964         }
1965 
1966     /***
1967      * Check that appended string has the right type.
1968      *
1969      */
1970     public void testAppendStringAsXmlVotable()
1971         throws Exception
1972         {
1973         //
1974         // Create our file properties.
1975         FileProperties properties = new FileProperties() ;
1976         //
1977         // Set the mime type property.
1978         properties.setProperty(
1979             FileProperties.MIME_TYPE_PROPERTY,
1980             FileProperties.MIME_TYPE_VOTABLE
1981             ) ;
1982         //
1983         // Import the test string.
1984         FileProperties imported = new FileProperties(
1985             target.importString(
1986                 properties.toArray(),
1987                 TEST_STRING
1988                 )
1989             ) ;
1990         //
1991         // Append the extra string.
1992         FileProperties modified = new FileProperties(
1993             target.appendString(
1994                 imported.getStoreResourceIdent(),
1995                 EXTRA_STRING
1996                 )
1997             ) ;
1998         //
1999         // Get the file properties.
2000         FileProperties requested = new FileProperties(
2001             target.properties(
2002                 imported.getStoreResourceIdent()
2003                 )
2004             ) ;
2005         //
2006         // Check the mime type.
2007         assertEquals(
2008             FileProperties.MIME_TYPE_VOTABLE,
2009             requested.getProperty(
2010                 FileProperties.MIME_TYPE_PROPERTY
2011                 )
2012             ) ;
2013         }
2014 
2015     /***
2016      * Check that an imported URL has the right type.
2017      *
2018      */
2019     public void testImportUrlAsVotable()
2020         throws Exception
2021         {
2022         //
2023         // Create our file properties.
2024         FileProperties properties = new FileProperties() ;
2025         //
2026         // Set the mime type property.
2027         properties.setProperty(
2028             FileProperties.MIME_TYPE_PROPERTY,
2029             FileProperties.MIME_TYPE_VOTABLE
2030             ) ;
2031         //
2032         // Transfer the data.
2033         TransferProperties transfer = 
2034             target.importData(
2035                 new UrlGetTransfer(
2036                     new URL(
2037                         getTestProperty(
2038                             "data.http.jar"
2039                             )
2040                         ),
2041                     properties
2042                     )
2043                 ) ;
2044         //
2045         // Get the file properties.
2046         FileProperties requested = new FileProperties(
2047             transfer.getFileProperties()
2048             ) ;
2049         //
2050         // Check the mime type.
2051         assertEquals(
2052             FileProperties.MIME_TYPE_VOTABLE,
2053             requested.getProperty(
2054                 FileProperties.MIME_TYPE_PROPERTY
2055                 )
2056             ) ;
2057         }
2058 
2059 /*
2060  * Gradually moving tests from ExtendedTestCase into here ...
2061  *
2062  */
2063 
2064     /***
2065      * Check we can send a null transfer properties.
2066      *
2067      */
2068     public void testImportInitNullTransfer()
2069         throws Exception
2070         {
2071         try {
2072             target.importInit(
2073                 null
2074                 ) ;
2075             }
2076         catch (FileStoreTransferException ouch)
2077             {
2078             return ;
2079             }
2080         fail("Expected FileStoreTransferException") ;
2081         }
2082 
2083     /***
2084      * Check we can initiate an import.
2085      *
2086      */
2087     public void testImportInit()
2088         throws Exception
2089         {
2090         TransferProperties transfer = new UrlPutTransfer() ;
2091         assertNotNull(
2092             target.importInit(
2093                 transfer
2094                 )
2095             );
2096         }
2097 
2098     /***
2099      * Check that the transfer properties contains a URL.
2100      *
2101      */
2102     public void testImportInitURL()
2103         throws Exception
2104         {
2105         TransferProperties transfer = new UrlPutTransfer() ;
2106         transfer = target.importInit(
2107             transfer
2108             ) ;
2109         assertNotNull(
2110             transfer.getLocation()
2111             );
2112         }
2113 
2114     /***
2115      * Check that we can open the import URL.
2116      *
2117      */
2118     public void testImportInitURLConnection()
2119         throws Exception
2120         {
2121         TransferProperties transfer = new UrlPutTransfer() ;
2122         transfer = target.importInit(
2123             transfer
2124             ) ;
2125         URL url = new URL(
2126             transfer.getLocation()
2127             ) ;
2128         assertNotNull(
2129             url.openConnection()
2130             );
2131         }
2132 
2133     /***
2134      * Check that we get valid file properties for an import.
2135      *
2136      */
2137     public void testImportInitProperties()
2138         throws Exception
2139         {
2140         TransferProperties transfer = new UrlPutTransfer() ;
2141         transfer = target.importInit(
2142             transfer
2143             ) ;
2144         assertNotNull(
2145             transfer.getFileProperties()
2146             );
2147         }
2148 
2149     /***
2150      * Check that we can transfer some data.
2151      *
2152      */
2153     public void testImportInitWrite()
2154         throws Exception
2155         {
2156         //
2157         // Initiate our transfer.
2158         TransferProperties transfer = target.importInit(
2159             new UrlPutTransfer()
2160             ) ;
2161         //
2162         // Transfer our data.
2163         FileStoreOutputStream stream = new FileStoreOutputStream(
2164             transfer.getLocation()
2165             ) ;
2166         stream.open() ;
2167         stream.write(
2168             TEST_BYTES
2169             ) ;
2170         stream.close() ;
2171         }
2172 
2173 //
2174 // .............
2175 //
2176 
2177     /***
2178      * Check we get the right Exception for a null transfer properties.
2179      *
2180      */
2181     public void testExportInitNullTransfer()
2182         throws Exception
2183         {
2184         try {
2185             target.exportInit(
2186                 null
2187                 ) ;
2188             }
2189         catch (FileStoreTransferException ouch)
2190             {
2191             return ;
2192             }
2193         fail("Expected FileStoreTransferException") ;
2194         }
2195 
2196     /***
2197      * Check we get the right Exception for an unknown file.
2198      *
2199      */
2200     public void testExportInitNullProperties()
2201         throws Exception
2202         {
2203         TransferProperties transfer = new UrlGetRequest() ;
2204         try {
2205             target.exportInit(
2206                 transfer
2207                 ) ;
2208             }
2209         catch (FileStoreNotFoundException ouch)
2210             {
2211             return ;
2212             }
2213         fail("Expected FileStoreNotFoundException") ;
2214         }
2215 
2216     /***
2217      * Check that we get a transfer properties for an export.
2218      *
2219      */
2220     public void testExportInitTransfer()
2221         throws Exception
2222         {
2223         //
2224         // Initiate our import transfer.
2225         TransferProperties importTransfer = target.importInit(
2226             new UrlPutTransfer()
2227             ) ;
2228         //
2229         // Open an output stream.
2230         FileStoreOutputStream importStream = new FileStoreOutputStream(
2231             importTransfer.getLocation()
2232             ) ;
2233         //
2234         // Open our stream.
2235         importStream.open() ;
2236         //
2237         // Transfer our data.
2238         importStream.write(
2239             TEST_BYTES
2240             ) ;
2241         //
2242         // Close our stream.
2243         importStream.close() ;
2244         //
2245         // Get the file properties.
2246         FileProperties properties = new FileProperties(
2247             importTransfer.getFileProperties()
2248             ) ;
2249         //
2250         // Initiate our export transfer.
2251         TransferProperties exportTransfer = target.exportInit(
2252             new UrlGetRequest(
2253                 properties
2254                 )
2255             ) ;
2256         assertNotNull(
2257             exportTransfer
2258             );
2259         }
2260 
2261     /***
2262      * Check that we get the right Exception for a null file identifier.
2263      *
2264      */
2265     public void testExportInitEmptyProperties()
2266         throws Exception
2267         {
2268         //
2269         // Create our file properties.
2270         FileProperties properties = new FileProperties() ;
2271         //
2272         // Create our transfer request.
2273         TransferProperties transfer = new UrlGetRequest(
2274             properties
2275             ) ;
2276         try {
2277             target.exportInit(
2278                 transfer
2279                 ) ;
2280             }
2281         catch (FileStoreNotFoundException ouch)
2282             {
2283             return ;
2284             }
2285         fail("Expected FileStoreNotFoundException") ;
2286         }
2287 
2288     /***
2289      * Check that we get the right Exception for an unknown file identifier.
2290      *
2291      */
2292 // ....
2293 
2294     /***
2295      * Check that the transfer properties contains a location URL.
2296      *
2297      */
2298     public void testExportInitTransferLocation()
2299         throws Exception
2300         {
2301         //
2302         // Initiate our import transfer.
2303         TransferProperties importTransfer = target.importInit(
2304             new UrlPutTransfer()
2305             ) ;
2306         //
2307         // Open an output stream.
2308         FileStoreOutputStream importStream = new FileStoreOutputStream(
2309             importTransfer.getLocation()
2310             ) ;
2311         //
2312         // Open our stream.
2313         importStream.open() ;
2314         //
2315         // Transfer our data.
2316         importStream.write(
2317             TEST_BYTES
2318             ) ;
2319         //
2320         // Close our stream.
2321         importStream.close() ;
2322         //
2323         // Get the file properties.
2324         FileProperties properties = new FileProperties(
2325             importTransfer.getFileProperties()
2326             ) ;
2327         //
2328         // Initiate our export transfer.
2329         TransferProperties exportTransfer = target.exportInit(
2330             new UrlGetRequest(
2331                 properties
2332                 )
2333             ) ;
2334         assertNotNull(
2335             exportTransfer.getLocation()
2336             );
2337         }
2338 
2339     /***
2340      * Check that we read data from an export stream.
2341      *
2342      */
2343     public void testExportInitRead()
2344         throws Exception
2345         {
2346         //
2347         // Initiate our import transfer.
2348         TransferProperties importTransfer = target.importInit(
2349             new UrlPutTransfer()
2350             ) ;
2351         //
2352         // Open an output stream.
2353         FileStoreOutputStream importStream = new FileStoreOutputStream(
2354             importTransfer.getLocation()
2355             ) ;
2356         //
2357         // Open our stream.
2358         importStream.open() ;
2359         //
2360         // Transfer our data.
2361         importStream.write(
2362             TEST_BYTES
2363             ) ;
2364         //
2365         // Close our stream.
2366         importStream.close() ;
2367         //
2368         // Get the file properties.
2369         FileProperties properties = new FileProperties(
2370             importTransfer.getFileProperties()
2371             ) ;
2372         //
2373         // Initiate our export transfer.
2374         TransferProperties exportTransfer = target.exportInit(
2375             new UrlGetRequest(
2376                 properties
2377                 )
2378             ) ;
2379         //
2380         // Get an input stream to the file.
2381         FileStoreInputStream exportStream = new FileStoreInputStream(
2382             exportTransfer.getLocation()
2383             );
2384         //
2385         // Open our input stream.
2386         exportStream.open() ;
2387         //
2388         // Create our buffer stream.
2389         ByteArrayOutputStream buffer = new ByteArrayOutputStream() ;
2390         //
2391         // Read our test bytes.
2392         TransferUtil util = new TransferUtil(
2393             exportStream,
2394             buffer
2395             );
2396         util.transfer();
2397         //
2398         // Close our input stream.
2399         exportStream.close() ;
2400         //
2401         // Check we got the right data back.
2402         assertEquals(
2403             TEST_BYTES,
2404             buffer.toByteArray()
2405             );
2406         }
2407 
2408     /***
2409      * Check we can get the initial dates for a file.
2410      *
2411      */
2412     public void testInitialDates()
2413         throws Exception
2414         {
2415         //
2416         // Import the test string.
2417         FileProperties properties = new FileProperties(
2418             target.importString(
2419                 null,
2420                 TEST_STRING
2421                 )
2422             ) ;
2423         //
2424         // Check the create date.
2425         Date created = properties.getFileCreateDate();
2426         assertNotNull(
2427             created
2428             );
2429         //
2430         // Check the modified date.
2431         Date modified = properties.getFileModifyDate();
2432         assertNotNull(
2433             modified
2434             );
2435         }
2436 
2437     /***
2438      * Check that adding some data changes the modified date.
2439      *
2440      */
2441     public void testModifiedDates()
2442         throws Exception
2443         {
2444         //
2445         // Import the test string.
2446         FileProperties imported = new FileProperties(
2447             target.importString(
2448                 null,
2449                 TEST_STRING
2450                 )
2451             ) ;
2452         //
2453         // Get the initial dates.
2454         Date initialCreateDate = imported.getFileCreateDate();
2455         Date initialModifyDate = imported.getFileModifyDate();
2456         //
2457         // Pause for a bit ....
2458         Thread.sleep(1000);
2459         //
2460         // Append the extra string.
2461         FileProperties modified = new FileProperties(
2462             target.appendString(
2463                 imported.getStoreResourceIdent(),
2464                 EXTRA_STRING
2465                 )
2466             ) ;
2467         //
2468         // Get the updated dates.
2469         Date updatedCreateDate = modified.getFileCreateDate();
2470         Date updatedModifyDate = modified.getFileModifyDate();
2471         //
2472         // Check the create dates are the same.
2473         assertEquals(
2474             initialCreateDate,
2475             updatedCreateDate
2476             );
2477         //
2478         // Check the modified date has changed.
2479         assertTrue(
2480             updatedModifyDate.after(
2481                 initialModifyDate
2482                 )
2483             );
2484         }
2485     }