KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > marshall > VersionAwareMarshallerTest


1 /*
2  * JBoss, Home of Professional Open Source
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.cache.marshall;
8
9 import junit.framework.TestCase;
10 import org.jboss.cache.RegionManager;
11 import org.jboss.cache.Version;
12
13 import java.io.ObjectInputStream JavaDoc;
14
15 /**
16  * Tests the enhanced treecache marshaller
17  *
18  * @author <a HREF="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
19  */

20 public class VersionAwareMarshallerTest extends TestCase
21 {
22    public void testMarshallerSelection()
23    {
24       VersionAwareMarshaller marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "2.0.0.GA");
25       assertEquals(CacheMarshaller200.class, marshaller.defaultMarshaller.getClass());
26
27       marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.4.0.GA");
28       assertEquals(CacheMarshaller200.class, marshaller.defaultMarshaller.getClass());
29
30       marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.5.0.GA");
31       assertEquals(CacheMarshaller200.class, marshaller.defaultMarshaller.getClass());
32
33       marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.3.0.GA");
34       assertEquals(CacheMarshaller200.class, marshaller.defaultMarshaller.getClass());
35
36       marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.3.0.SP2");
37       assertEquals(CacheMarshaller200.class, marshaller.defaultMarshaller.getClass());
38
39       marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.3.1.GA");
40       assertEquals(CacheMarshaller200.class, marshaller.defaultMarshaller.getClass());
41
42       marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.2.4.SP2");
43       assertEquals(CacheMarshaller200.class, marshaller.defaultMarshaller.getClass());
44
45       marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.2.3");
46       assertEquals(CacheMarshaller200.class, marshaller.defaultMarshaller.getClass());
47    }
48
49    public void testVersionHeaderDefaultCurrent() throws Exception JavaDoc
50    {
51       VersionAwareMarshaller marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, Version.getVersionString(Version.getVersionShort()));
52       byte[] bytes = marshaller.objectToByteBuffer("Hello");
53
54       // expect that this has been serialized using JBoss Serialization so use this to get an OIS.
55
ObjectInputStream JavaDoc in = ObjectSerializationFactory.createObjectInputStream(bytes);
56       assertEquals("Version header short should be '20'", 20, in.readShort());
57    }
58
59    public void testVersionHeader200() throws Exception JavaDoc
60    {
61       VersionAwareMarshaller marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "2.0.0.GA");
62       byte[] bytes = marshaller.objectToByteBuffer("Hello");
63
64       // expect that this has been serialized using JBoss Serialization so use this to get an OIS.
65
ObjectInputStream JavaDoc in = ObjectSerializationFactory.createObjectInputStream(bytes);
66       assertEquals("Version header short should be '20'", 20, in.readShort());
67    }
68
69 }
70
Popular Tags