KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*****************************************************************************
2  * Copyright (c) PicoContainer Organization. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  * *
8  * Idea by Rachel Davies, Original code by Aslak Hellesoy and Paul Hammant *
9  *****************************************************************************/

10
11 package org.picocontainer.defaults;
12
13 import java.io.ByteArrayInputStream JavaDoc;
14 import java.io.ByteArrayOutputStream JavaDoc;
15 import java.io.IOException JavaDoc;
16 import java.io.ObjectInputStream JavaDoc;
17 import java.io.ObjectOutputStream JavaDoc;
18
19 import org.picocontainer.MutablePicoContainer;
20 import org.picocontainer.PicoContainer;
21 import org.picocontainer.PicoException;
22 import org.picocontainer.PicoInitializationException;
23 import org.picocontainer.tck.AbstractPicoContainerTestCase;
24
25 /**
26  * @author Thomas Heller
27  * @author Paul Hammant
28  */

29 public class DefaultPicoContainerTreeSerializationTestCase extends AbstractPicoContainerTestCase {
30     protected MutablePicoContainer createPicoContainer(PicoContainer parent) {
31         DefaultPicoContainer child = new DefaultPicoContainer(parent);
32         return child;
33     }
34
35     public void testContainerIsDeserializableWithParent() throws PicoException, PicoInitializationException,
36             IOException JavaDoc, ClassNotFoundException JavaDoc {
37
38         PicoContainer parent = createPicoContainer(null);
39         MutablePicoContainer child = createPicoContainer(parent);
40
41         ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
42         ObjectOutputStream JavaDoc oos = new ObjectOutputStream JavaDoc(baos);
43
44         oos.writeObject(child);
45
46         child = null;
47         ObjectInputStream JavaDoc ois = new ObjectInputStream JavaDoc(new ByteArrayInputStream JavaDoc(baos.toByteArray()));
48         child = (MutablePicoContainer) ois.readObject();
49         assertNotNull(child.getParent());
50     }
51 }
52
Popular Tags