6 import org
.apache
.commons
.codec
.binary
.Base64
;
7 import static org
.junit
.Assert
.assertEquals
;
8 import static org
.junit
.Assert
.assertTrue
;
9 import org
.junit
.Before
;
10 import org
.junit
.Test
;
11 import org
.lwes
.db
.EventTemplateDB
;
13 import java
.math
.BigInteger
;
14 import java
.net
.InetAddress
;
15 import java
.net
.UnknownHostException
;
17 public class EventTest
{
19 private EventTemplateDB eventTemplate
;
23 eventTemplate
= new EventTemplateDB();
27 public void testSerialize() throws EventSystemException
{
28 Event evt
= new Event("Test", false, eventTemplate
);
29 evt
.setString("attr_s", "str_value");
30 evt
.setInt32("attr_i", 1);
31 byte[] bytes
= evt
.serialize();
32 String str
= new String(bytes
);
33 //System.out.println("as string: "+str);
34 byte[] encoded
= Base64
.encodeBase64(bytes
);
35 //System.out.println(new String(encoded));
36 // TODO this test not finished yet.
40 public void testEventAccessors() throws EventSystemException
, UnknownHostException
{
41 Event evt
= new Event("Test", false, eventTemplate
);
43 evt
.setInt16("int16", (short) 1);
44 evt
.setInt32("int32", 1337);
45 evt
.setInt64("int64", 1337133713371337l);
46 evt
.setBoolean("bool", true);
47 evt
.setString("str", "string");
48 evt
.setUInt16("uint16", 1337); // uint16 in java is just an int
49 evt
.setUInt32("uint32", 1337133713371337l); // uint32 in java is a long
50 evt
.setUInt64("uint64", 1337133713371337l); // uint64 is a BigInteger
51 evt
.setIPAddress("ipaddr", InetAddress
.getByName("localhost"));
53 assertEquals("int16 wrong", 1, evt
.getInt16("int16"));
54 assertEquals("int32 wrong", 1337, evt
.getInt32("int32"));
55 assertEquals("int64 wrong", 1337133713371337l, evt
.getInt64("int64"));
56 assertEquals("bool wrong", true, evt
.getBoolean("bool"));
57 assertEquals("str wrong", "string", evt
.getString("str"));
58 assertEquals("uint16 wrong", 1337, evt
.getUInt16("uint16"));
59 assertEquals("uint32 wrong", 1337133713371337l, evt
.getUInt32("uint32"));
60 assertEquals("uint64 wrong",
61 BigInteger
.valueOf(1337133713371337l),
62 evt
.getUInt64("uint64"));
67 public void testEventSize() throws EventSystemException
{
69 Event evt
= new Event("Test", false, eventTemplate
);
71 for (int i
= 0; i
< 5000; i
++) {
72 evt
.setInt32("" + i
, i
);
75 byte[] bytes
= evt
.serialize();
76 assertEquals("number of bytes wrong?", 48904, bytes
.length
);
78 boolean exceptionThrown
= false;
80 for (int i
= 5001; i
< 10000; i
++) {
81 evt
.setInt32("" + i
, i
);
85 exceptionThrown
= true;
86 assertEquals("Different exception",
87 "org.lwes.EventSystemException",
88 e
.getClass().getName());
90 assertTrue("Size exception was not thrown", exceptionThrown
);