1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
202 super.setUp();
203
204
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
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 }