KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > picocontainer > defaults > XStreamSerialisationTestCase


1 package org.picocontainer.defaults;
2
3 import com.thoughtworks.xstream.XStream;
4 import com.thoughtworks.xstream.core.JVM;
5 import com.thoughtworks.xstream.io.xml.XppDriver;
6 import junit.framework.TestCase;
7 import org.picocontainer.MutablePicoContainer;
8 import org.picocontainer.PicoContainer;
9 import org.picocontainer.testmodel.DependsOnTouchable;
10 import org.picocontainer.testmodel.SimpleTouchable;
11
12 /**
13  * @author Aslak Hellesøy
14  * @version $Revision: 1697 $
15  */

16 public class XStreamSerialisationTestCase extends TestCase {
17     private XStream xStream = new XStream(new XppDriver());
18
19     public void testShouldBeAbleToSerialiseEmptyPico() {
20         if (JVM.is14()) {
21             MutablePicoContainer pico = new DefaultPicoContainer();
22             String JavaDoc picoXml = xStream.toXML(pico);
23             PicoContainer serializedPico = (PicoContainer) xStream.fromXML(picoXml);
24
25             assertEquals(0, serializedPico.getComponentInstances().size());
26         }
27     }
28
29     public void testShouldBeAbleToSerialisePicoWithUninstantiatedComponents() {
30         if (JVM.is14()) {
31             MutablePicoContainer pico = new DefaultPicoContainer();
32             pico.registerComponentImplementation(SimpleTouchable.class);
33             pico.registerComponentImplementation(DependsOnTouchable.class);
34             String JavaDoc picoXml = xStream.toXML(pico);
35             PicoContainer serializedPico = (PicoContainer) xStream.fromXML(picoXml);
36
37             assertEquals(2, serializedPico.getComponentInstances().size());
38         }
39     }
40
41     public void testShouldBeAbleToSerialisePicoWithInstantiatedComponents() {
42         if (JVM.is14()) {
43             MutablePicoContainer pico = new DefaultPicoContainer();
44             pico.registerComponentImplementation(SimpleTouchable.class);
45             pico.registerComponentImplementation(DependsOnTouchable.class);
46             pico.getComponentInstances();
47             String JavaDoc picoXml = xStream.toXML(pico);
48             PicoContainer serializedPico = (PicoContainer) xStream.fromXML(picoXml);
49
50             assertEquals(2, serializedPico.getComponentInstances().size());
51         }
52     }
53 }
Popular Tags