KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > type > TestPTypeSpace


1 /**
2  * JORM: an implementation of a generic mapping system for persistent Java
3  * objects. Two mapping are supported: to RDBMS and to binary files.
4  * Copyright (C) 2001-2003 France Telecom R&D - INRIA
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Contact: jorm-team@objectweb.org
21  *
22  */

23 package org.objectweb.jorm.type;
24
25 import junit.framework.Test;
26 import junit.framework.TestCase;
27 import junit.framework.TestSuite;
28 import junit.textui.TestRunner;
29 import org.objectweb.jorm.type.api.PTypeSpace;
30 import org.objectweb.jorm.type.api.PType;
31 import org.objectweb.jorm.type.api.PExceptionTyping;
32 import org.objectweb.jorm.type.lib.PTypeSpacePAAH;
33 import org.objectweb.jorm.api.PException;
34
35 /**
36  * This class is used to test the PTypeSpacePAAH.
37  *
38  * @author S.Chassande-Barrioz
39  */

40 public class TestPTypeSpace extends TestCase {
41     /**
42      * Main method to launch the tests manually.
43      */

44     public static void main(String JavaDoc[] args) {
45         TestRunner.run(suite());
46     }
47
48     /**
49      * This method creates a TestSuite object with the current tests
50      */

51     public static Test suite() {
52         return new TestSuite(TestPTypeSpace.class);
53     }
54
55     protected PTypeSpace ptypeSpace = null;
56
57     /**
58      * Main constructor for the current object.
59      */

60     public TestPTypeSpace(String JavaDoc name) {
61         super(name);
62     }
63
64     protected void setUp() throws Exception JavaDoc {
65         ptypeSpace = new PTypeSpacePAAH();
66     }
67
68     protected void tearDown() throws Exception JavaDoc {
69     }
70
71     public void testIsa() {
72         PType titi = null;
73         PType toto = null;
74         try {
75             titi = ptypeSpace.createPType("titi", new String JavaDoc[][]{});
76             assertNotNull("Simple class definition is null", titi);
77             String JavaDoc[] z = new String JavaDoc[]{"toto", "titi"};
78             String JavaDoc[][] r = new String JavaDoc[1][];
79             r[0] = z;
80             toto = ptypeSpace.createPType("toto", r);
81             assertNotNull("Class definition with inheritance is null", toto);
82         }
83         catch (PExceptionTyping typing) {
84             printException(typing);
85             fail(typing.getMessage());
86         }
87         assertTrue("same PType", titi.isa(titi));
88         assertTrue("same PType", toto.isa(toto));
89         //assertTrue("Inheritance does not work", !titi.isa(toto));
90
assertTrue("Inheritance does not work", toto.isa(titi));
91
92         PType a = null;
93         PType b = null;
94         try {
95             a = ptypeSpace.createPType("a",
96                 new String JavaDoc[][]{new String JavaDoc[]{"a", "b"}});
97             b = ptypeSpace.createPType("b", new String JavaDoc[][]{});
98         }
99         catch (PExceptionTyping typing) {
100             printException(typing);
101             fail(typing.getMessage());
102         }
103         assertNotNull("Class definition with inheritance is null", a);
104         assertNotNull("Simple class definition is null", b);
105         assertTrue("reverse order definition does not work", a.isa(b));
106     }
107
108     private static void printException(Exception JavaDoc e) {
109         if (e instanceof PException && ((PException) e).getNestedException()!=null) {
110             System.out.println(e.getMessage());
111             printException(((PException) e).getNestedException());
112         }
113         else
114             e.printStackTrace();
115     }
116 }
117
Popular Tags