1 /*
2 * Created on 30.04.2004
3 */
4 package org.xpcards.model.test;
5
6 import java.beans.XMLDecoder;
7 import java.io.ByteArrayInputStream;
8 import java.io.ByteArrayOutputStream;
9 import java.util.Enumeration;
10
11 import junit.framework.TestCase;
12
13 import org.xpcards.model.FileProjectSource;
14 import org.xpcards.model.ProjectsCollection;
15 import org.xpcards.model.XPEncoder;
16
17 /***
18 * @author Mikhail Galyutin
19 */
20 public class ProjectsCollectionTest extends TestCase {
21
22 /***
23 * Constructor for ProjectsCollectionTest.
24 * @param arg0
25 */
26 public ProjectsCollectionTest(String arg0) {
27 super(arg0);
28 }
29
30 public static void main(String[] args) {
31 junit.textui.TestRunner.run(ProjectsCollectionTest.class);
32 }
33
34 ProjectsCollection pc = null;
35 /***
36 * @see junit.framework.TestCase#setUp()
37 */
38 protected void setUp() throws Exception {
39 if (pc == null) {
40 pc = new ProjectsCollection();
41
42 pc.putProject(new FileProjectSource("./test1.test", null));
43 pc.putProject(new FileProjectSource("./test2.test", null));
44 }
45 super.setUp();
46 }
47
48 public void testGetProjects() throws Exception {
49 int count = 0;
50 for ( Enumeration i = pc.projects(); i.hasMoreElements(); count ++) {
51 assertNotNull(i.nextElement());
52 }
53 assertEquals(2, count);
54 }
55
56
57 public void testPersistenece() throws Exception {
58 ByteArrayOutputStream out = new ByteArrayOutputStream();
59 XPEncoder enc = new XPEncoder( out);
60
61 enc.writeObject(pc);
62
63 enc.close();
64
65 System.err.println("Result is : \n" + new String(out.toByteArray()));
66
67 XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(out.toByteArray()));
68
69 ProjectsCollection ppc = (ProjectsCollection)dec.readObject();
70
71 for ( Enumeration i = pc.projects(); i.hasMoreElements(); ) {
72 System.err.println("Project Source : \n" + i.nextElement());
73 }
74
75 assertEquals(pc, ppc);
76
77
78 }
79
80 }
This page was automatically generated by Maven