3 import static org
.junit
.Assert
.assertEquals
;
4 import static org
.junit
.Assert
.assertNotNull
;
5 import static org
.junit
.Assert
.assertTrue
;
6 import org
.junit
.Before
;
9 import org
.lwes
.EventAttributeSizeException
;
10 import org
.lwes
.EventSystemException
;
11 import org
.lwes
.util
.Log
;
14 import java
.util
.Enumeration
;
21 public class ArrayTest
{
23 private static final String ESF
= "src/test/java/org/lwes/db/ArrayTest.esf";
24 private static final String TEST_EVENT
= "TestEvent";
26 private EventTemplateDB template
= null;
30 template
= new EventTemplateDB();
31 template
.setESFFile(new File(ESF
));
32 template
.initialize();
36 public void testArrayParse() {
38 EventTemplateDB template
= new EventTemplateDB();
39 template
.setESFFile(new File(ESF
));
40 assertTrue("Template did not initialize", template
.initialize());
42 Enumeration
<String
> eventNames
= template
.getEventNames();
43 assertNotNull("Event names enum was null", eventNames
);
45 assertTrue("TestEvent was not known to the template",
46 template
.checkForEvent(TEST_EVENT
));
48 assertTrue("field1 attribute not known to the template",
49 template
.checkForAttribute(TEST_EVENT
, "field1"));
54 public void testStringArray() throws EventSystemException
{
56 // First try to set a valid string array
57 Event evt
= new Event("TestEvent", true, template
);
58 evt
.setStringArray("field1", new String
[]{"1", "2", "3"});
59 String
[] ar
= evt
.getStringArray("field1");
60 assertNotNull("string array was null", ar
);
61 assertEquals("length was incorrect", 3, ar
.length
);
63 // Make sure we can serialize/deserialize it
64 byte[] serializedEvent
= evt
.serialize();
65 Event evt2
= new Event(serializedEvent
, true, template
);
67 String
[] a2
= evt2
.getStringArray("field1");
69 assertEquals("deserialized array length was incorrect", 3, a2
.length
);
71 // Now try to set an invalid string array and make
72 // sure an exception is thrown.
73 boolean exceptionThrown
= false;
75 evt
.setStringArray("field1", new String
[]{"1", "2", "3",
80 catch (EventAttributeSizeException e
) {
81 if (Log
.isLogDebug()) {
82 Log
.debug(e
.getMessage());
84 exceptionThrown
= true;
86 assertTrue("No exception was thrown for array length", exceptionThrown
);
90 public void testInt16() throws EventSystemException
{
91 // First try to set a valid string array
92 Event evt
= new Event("TestEvent", true, template
);
93 evt
.setInt16Array("field2", new short[]{1, 2, 3});
94 short[] ar
= evt
.getInt16Array("field2");
95 assertNotNull("string array was null", ar
);
96 assertEquals("length was incorrect", 3, ar
.length
);
98 // Make sure we can serialize/deserialize it
99 byte[] serializedEvent
= evt
.serialize();
100 Event evt2
= new Event(serializedEvent
, true, template
);
102 short[] a2
= evt2
.getInt16Array("field2");
104 assertEquals("deserialized array length was incorrect", 3, a2
.length
);
106 // Now try to set an invalid string array and make
107 // sure an exception is thrown.
108 boolean exceptionThrown
= false;
110 evt
.setInt16Array("field2", new short[]{1, 2, 3,
115 catch (EventAttributeSizeException e
) {
116 if (Log
.isLogDebug()) {
117 Log
.debug(e
.getMessage());
119 exceptionThrown
= true;
121 assertTrue("No exception was thrown for array length", exceptionThrown
);
125 public void testInt32() throws EventSystemException
{
126 // First try to set a valid string array
127 Event evt
= new Event("TestEvent", true, template
);
128 evt
.setInt32Array("field3", new int[]{1234567890, 234567890, 345678901});
129 int[] ar
= evt
.getInt32Array("field3");
130 assertNotNull("string array was null", ar
);
131 assertEquals("length was incorrect", 3, ar
.length
);
133 // Make sure we can serialize/deserialize it
134 byte[] serializedEvent
= evt
.serialize();
135 Event evt2
= new Event(serializedEvent
, true, template
);
137 int[] a2
= evt2
.getInt32Array("field3");
139 assertEquals("deserialized array length was incorrect", 3, a2
.length
);
140 assertEquals("a2[0]", a2
[0], 1234567890);
141 assertEquals("a2[1]", a2
[1], 234567890);
142 assertEquals("a2[2]", a2
[2], 345678901);
144 // Now try to set an invalid string array and make
145 // sure an exception is thrown.
146 boolean exceptionThrown
= false;
148 evt
.setInt32Array("field3", new int[]{1, 2, 3,
153 catch (EventAttributeSizeException e
) {
154 if (Log
.isLogDebug()) {
155 Log
.debug(e
.getMessage());
157 exceptionThrown
= true;
159 assertTrue("No exception was thrown for array length", exceptionThrown
);
163 public void testInt64() throws EventSystemException
{
164 // First try to set a valid string array
165 Event evt
= new Event("TestEvent", true, template
);
166 evt
.setInt64Array("field4", new long[]{123456789012l, 234567890123l});
167 long[] ar
= evt
.getInt64Array("field4");
168 assertNotNull("string array was null", ar
);
169 assertEquals("length was incorrect", 2, ar
.length
);
171 // Make sure we can serialize/deserialize it
172 byte[] serializedEvent
= evt
.serialize();
173 Event evt2
= new Event(serializedEvent
, true, template
);
175 long[] a2
= evt2
.getInt64Array("field4");
177 assertEquals("deserialized array length was incorrect", 2, a2
.length
);
178 assertEquals("a2[0]", a2
[0], 123456789012l);
179 assertEquals("a2[1]", a2
[1], 234567890123l);
181 // Now try to set an invalid string array and make
182 // sure an exception is thrown.
183 boolean exceptionThrown
= false;
185 evt
.setInt64Array("field4", new long[]{1, 2, 3,
190 catch (EventAttributeSizeException e
) {
191 if (Log
.isLogDebug()) {
192 Log
.debug(e
.getMessage());
194 exceptionThrown
= true;
196 assertTrue("No exception was thrown for array length", exceptionThrown
);
200 public void testUInt16() throws EventSystemException
{
201 // First try to set a valid string array
202 Event evt
= new Event("TestEvent", true, template
);
203 evt
.setUInt16Array("field5", new int[]{1, 2, 3});
204 int[] ar
= evt
.getUInt16Array("field5");
205 assertNotNull("string array was null", ar
);
206 assertEquals("length was incorrect", 3, ar
.length
);
208 // Make sure we can serialize/deserialize it
209 byte[] serializedEvent
= evt
.serialize();
210 Event evt2
= new Event(serializedEvent
, true, template
);
212 int[] a2
= evt2
.getUInt16Array("field5");
214 assertEquals("deserialized array length was incorrect", 3, a2
.length
);
216 // Now try to set an invalid string array and make
217 // sure an exception is thrown.
218 boolean exceptionThrown
= false;
220 evt
.setUInt16Array("field5", new int[]{1, 2, 3,
225 catch (EventAttributeSizeException e
) {
226 if (Log
.isLogDebug()) {
227 Log
.debug(e
.getMessage());
229 exceptionThrown
= true;
231 assertTrue("No exception was thrown for array length", exceptionThrown
);
235 public void testUInt32() throws EventSystemException
{
236 // First try to set a valid string array
237 Event evt
= new Event("TestEvent", true, template
);
238 evt
.setUInt32Array("field6", new long[]{1234567890, 234567890, 345678901});
239 long[] ar
= evt
.getUInt32Array("field6");
240 assertNotNull("string array was null", ar
);
241 assertEquals("length was incorrect", 3, ar
.length
);
243 // Make sure we can serialize/deserialize it
244 byte[] serializedEvent
= evt
.serialize();
245 Event evt2
= new Event(serializedEvent
, true, template
);
247 long[] a2
= evt2
.getUInt32Array("field6");
249 assertEquals("deserialized array length was incorrect", 3, a2
.length
);
250 assertEquals("a2[0]", a2
[0], 1234567890);
251 assertEquals("a2[1]", a2
[1], 234567890);
252 assertEquals("a2[2]", a2
[2], 345678901);
254 // Now try to set an invalid string array and make
255 // sure an exception is thrown.
256 boolean exceptionThrown
= false;
258 evt
.setUInt32Array("field6", new long[]{1, 2, 3,
263 catch (EventAttributeSizeException e
) {
264 if (Log
.isLogDebug()) {
265 Log
.debug(e
.getMessage());
267 exceptionThrown
= true;
269 assertTrue("No exception was thrown for array length", exceptionThrown
);
273 public void testUInt64() throws EventSystemException
{
274 // First try to set a valid string array
275 Event evt
= new Event("TestEvent", true, template
);
276 evt
.setUInt64Array("field7", new long[]{123456789012l, 234567890123l});
277 long[] ar
= evt
.getUInt64Array("field7");
278 assertNotNull("string array was null", ar
);
279 assertEquals("length was incorrect", 2, ar
.length
);
281 // Make sure we can serialize/deserialize it
282 byte[] serializedEvent
= evt
.serialize();
283 Event evt2
= new Event(serializedEvent
, true, template
);
285 long[] a2
= evt2
.getUInt64Array("field7");
287 assertEquals("deserialized array length was incorrect", 2, a2
.length
);
288 assertEquals("a2[0]", a2
[0], 123456789012l);
289 assertEquals("a2[1]", a2
[1], 234567890123l);
291 // Now try to set an invalid string array and make
292 // sure an exception is thrown.
293 boolean exceptionThrown
= false;
295 evt
.setUInt64Array("field7", new long[]{1, 2, 3,
300 catch (EventAttributeSizeException e
) {
301 if (Log
.isLogDebug()) {
302 Log
.debug(e
.getMessage());
304 exceptionThrown
= true;
306 assertTrue("No exception was thrown for array length", exceptionThrown
);
310 public void testBooleanArray() throws EventSystemException
{
311 Event evt
= new Event("TestEvent", true, template
);
312 evt
.setBooleanArray("field8", new boolean[]{true, false});
313 boolean[] ar
= evt
.getBooleanArray("field8");
314 assertNotNull("boolean array was null", ar
);
315 assertEquals("length was incorrect", 2, ar
.length
);
317 // Make sure we can serialize/deserialize it
318 byte[] serializedEvent
= evt
.serialize();
319 Event evt2
= new Event(serializedEvent
, true, template
);
321 boolean[] a2
= evt2
.getBooleanArray("field8");
323 assertEquals("deserialized array length was incorrect", 2, a2
.length
);
324 assertEquals("a2[0]", a2
[0], true);
325 assertEquals("a2[1]", a2
[1], false);
329 public void testByteArray() throws EventSystemException
{
330 Event evt
= new Event("TestEvent", true, template
);
331 evt
.setByteArray("field9", new byte[]{(byte) 0x1, (byte) 0x2});
332 byte[] ar
= evt
.getByteArray("field9");
333 assertNotNull("boolean array was null", ar
);
334 assertEquals("length was incorrect", 2, ar
.length
);
336 // Make sure we can serialize/deserialize it
337 byte[] serializedEvent
= evt
.serialize();
338 Event evt2
= new Event(serializedEvent
, true, template
);
340 byte[] a2
= evt2
.getByteArray("field9");
342 assertEquals("deserialized array length was incorrect", 2, a2
.length
);
343 assertEquals("a2[0]", a2
[0], (byte) 0x1);
344 assertEquals("a2[1]", a2
[1], (byte) 0x2);