1 package org.xmlBlaster.test.jmx;
 2 
 3 import junit.framework.*;
 4 
 5 import java.util.logging.Logger;
 6 import java.util.logging.Level;
 7 import org.xmlBlaster.util.Global;
 8 
 9 import org.xmlBlaster.util.admin.extern.SerializeHelper;
10 import org.xmlBlaster.util.admin.extern.MethodInvocation;
11 import java.io.*;
12 
13 public class TestSerializer  extends TestCase{
14   private final static String ME = "TestSerializer";
15   private Global glob = null;
16    private static Logger log = Logger.getLogger(TestSerializer.class.getName());
17 
18   SerializeHelper sh = null;
19   MethodInvocation mi = null;
20 
21   public TestSerializer(String testName)
22    {
23        super(testName);
24    }
25 
26 
27    protected void setUp()
28    {
29      this.glob = Global.instance();
30 
31    }
32 
33 
34    /**
35     * Method is used by TestRunner to load these tests
36     */
37    public static Test suite() {
38        TestSuite suite= new TestSuite();
39        suite.addTest(new TestSerializer("testSerializer"));
40        return suite;
41    }
42 
43    /**
44     * TEST:
45     * <p />
46     */
47    public void testSerializer()
48    {
49     try {
50       sh = new SerializeHelper(glob);
51     }
52     catch (Exception ex) {
53       log.severe("Error when creating SerializeHelper" + ex.toString());
54       assertTrue("Error when creating SerializeHelper" + ex.toString(),false);
55     }
56     mi = new MethodInvocation();
57     try {
58       mi.setMethodName("Test");
59        log.info("Serializing MethodInvocation");
60        byte[] testByte = sh.serializeObject(mi);
61        log.info("Deserializing MethodInvocation...");
62        MethodInvocation mi2 = (MethodInvocation) sh.deserializeObject(testByte);
63        if (!(mi2.getMethodName().equals("Test"))) {
64          log.severe("Values are different");
65          assertTrue("Values are different", false);
66        }
67     }
68     catch (Exception ex) {
69       assertTrue("Error when serializing or deserialiizing Object " + ex.toString(), false);
70       log.severe("Error when serializing or deserialiizing Object " + ex.toString());
71     }
72    }
73 
74    public static void main(String args[])
75    {
76      TestSerializer testSer = new TestSerializer("SerializerTest");
77      testSer.setUp();
78      testSer.testSerializer();
79    }
80 
81 }


syntax highlighted by Code2HTML, v. 0.9.1