View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/filemanager/common/src/java/org/astrogrid/filemanager/common/BaseTest.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: BaseTest.java,v $
8    *   Revision 1.5  2005/01/28 10:43:58  clq2
9    *   dave_dev_200501141257 (filemanager)
10   *
11   *   Revision 1.4.2.1  2005/01/25 08:01:16  dave
12   *   Added tests for FileManagerClientFactory ....
13   *
14   *   Revision 1.4  2005/01/13 17:23:15  jdt
15   *   merges from dave-dev-200412201250
16   *
17   *   Revision 1.3.4.1  2005/01/12 13:16:27  dave
18   *   Changed tabs to spaces ...
19   *
20   *   Revision 1.3  2004/12/16 17:25:49  jdt
21   *   merge from dave-dev-200410061224-200412161312
22   *
23   *   Revision 1.1.2.5  2004/12/10 05:21:25  dave
24   *   Added node and iterator to client API ...
25   *
26   *   Revision 1.1.2.4  2004/11/24 16:15:08  dave
27   *   Added node functions to client ...
28   *
29   *   Revision 1.1.2.3  2004/11/16 03:25:37  dave
30   *   Updated API to use full ivorn rather than ident ...
31   *
32   *   Revision 1.1.2.2  2004/11/13 01:39:03  dave
33   *   Modifications to support the new client API ...
34   *
35   *   Revision 1.1.2.1  2004/10/13 06:33:17  dave
36   *   Refactored exceptions ...
37   *   Refactored the container API
38   *   Added placeholder file interface ...
39   *
40   * </cvs:log>
41   *
42   */
43  package org.astrogrid.filemanager.common ;
44  
45  import junit.framework.TestCase ;
46  
47  import org.astrogrid.store.Ivorn ;
48  import org.astrogrid.community.common.ivorn.CommunityAccountIvornFactory ;
49  
50  /***
51   * A common utility base class for file manager tests.
52   *
53   */
54  public class BaseTest
55      extends TestCase
56      {
57  
58      /***
59       * Test properties prefix.
60       *
61       */
62      public static final String TEST_PROPERTY_PREFIX = "org.astrogrid.filemanager.test" ;
63  
64      /***
65       * Helper method to get a local property.
66       *
67       */
68      public String getTestProperty(String name)
69          {
70          return System.getProperty(TEST_PROPERTY_PREFIX + "." + name) ;
71          }
72  
73      /***
74       * A test string.
75       * "A short test string ...."
76       *
77       */
78      public static final String TEST_STRING = "A short test string ...." ;
79  
80      /***
81       * A test string.
82       * " plus a bit more ...."
83       *
84       */
85      public static final String EXTRA_STRING = " plus a bit more ...." ;
86  
87      /***
88       * A test byte array.
89       * "A short byte array ...."
90       *
91       */
92      public static final byte[] TEST_BYTES = {
93          0x41,
94          0x20,
95          0x73,
96          0x68,
97          0x6f,
98          0x72,
99          0x74,
100         0x20,
101         0x62,
102         0x79,
103         0x74,
104         0x65,
105         0x20,
106         0x61,
107         0x72,
108         0x72,
109         0x61,
110         0x79,
111         0x20,
112         0x2e,
113         0x2e,
114         0x2e,
115         0x2e
116         } ;
117 
118     /***
119      * A test byte array.
120      * " plus a few more ...."
121      *
122      */
123     public static final byte[] EXTRA_BYTES = {
124         0x20,
125         0x70,
126         0x6c,
127         0x75,
128         0x73,
129         0x20,
130         0x61,
131         0x20,
132         0x66,
133         0x65,
134         0x77,
135         0x20,
136         0x6d,
137         0x6f,
138         0x72,
139         0x65,
140         0x20,
141         0x2e,
142         0x2e,
143         0x2e,
144         0x2e
145         } ;
146 
147     /***
148      * Test utility to compare two arrays of bytes.
149      *
150      */
151     public static void assertEquals(byte[] left, byte[] right)
152         {
153         assertEquals(
154             "Different array length",
155             left.length,
156             right.length
157             ) ;
158         for (int i = 0 ; i < left.length ; i++)
159             {
160             assertEquals(
161                 "Wrong value for byte[" + i + "]",
162                 left[i],
163                 right[i]
164                 ) ;
165             }
166         }
167 
168     /***
169      * Our test account ivorn.
170      *
171      */
172     protected Ivorn accountIvorn ;
173 
174     /***
175      * Our test account name.
176      *
177      */
178     protected String accountName ;
179 
180     /***
181      * Our test account ivorn.
182      *
183      */
184     protected Ivorn unknownIvorn ;
185 
186     /***
187      * Our test account name.
188      *
189      */
190     protected String unknownName ;
191 
192     /***
193      * Setup our test.
194      * This may need to be changed for the integration tests.
195      *
196      */
197     public void setUp()
198         throws Exception
199         {
200 		//
201 		// Initialise our base class.
202 		super.setUp();
203         //
204         // Create our test accounts.
205         accountIvorn = CommunityAccountIvornFactory.createLocal(
206             "test-" +
207             String.valueOf(
208                 System.currentTimeMillis()
209                 )
210             ) ;
211         unknownIvorn = CommunityAccountIvornFactory.createLocal(
212             "unknown-" +
213             String.valueOf(
214                 System.currentTimeMillis()
215                 )
216             ) ;
217         //
218         // Create our test account names.
219         accountName = accountIvorn.toString() ;
220         unknownName = unknownIvorn.toString() ;
221         }
222 
223     /***
224      * Compare two ivorns.
225      *
226      */
227     public boolean compare(Ivorn frog, Ivorn toad)
228         {
229         return frog.toString().equals(
230             toad.toString()
231             );
232         }
233 
234     /***
235      * Compare two Ivorns.
236      *
237      */
238     public void assertEquals(Ivorn frog, Ivorn toad)
239         {
240         assertEquals(
241             frog.toString(),
242             toad.toString()
243             );
244         }
245     }