KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > entity > F_Inherit


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
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.1 of the License, or 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
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: F_Inherit.java,v 1.2 2004/03/19 11:57:15 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.entity;
27
28 import javax.naming.NamingException JavaDoc;
29 import javax.rmi.PortableRemoteObject JavaDoc;
30
31 import junit.framework.Assert;
32 import junit.framework.Test;
33 import junit.framework.TestSuite;
34
35 import org.objectweb.jonas.jtests.beans.inherit.Person;
36 import org.objectweb.jonas.jtests.beans.inherit.PersonHome;
37 import org.objectweb.jonas.jtests.beans.inherit.User;
38 import org.objectweb.jonas.jtests.beans.inherit.UserHome;
39 import org.objectweb.jonas.jtests.util.JTestCase;
40
41 /**
42  * This test check it's possible to use inheritance to develop beans.
43  * (The test is essentially do at the beans compilation and beans deployment !!!)
44  * Beans used: inherit
45  * @author Helene Joanin (jonas team)
46  */

47 public class F_Inherit extends JTestCase {
48
49     private static String JavaDoc BEAN_HOME_PERSON = "inheritPersonECHome";
50     protected static PersonHome phome = null;
51     private static String JavaDoc BEAN_HOME_USER = "inheritUserECHome";
52     protected static UserHome uhome = null;
53     private static String JavaDoc BEAN_HOME_DERIVED_USER = "inheritDerivedUserECHome";
54     protected static UserHome duhome = null;
55
56     public F_Inherit(String JavaDoc name) {
57     super(name);
58     }
59
60     protected void setUp() {
61     super.setUp();
62     if ((phome == null) || (uhome == null) || (duhome == null)) {
63         useBeans("inherit", true);
64         try {
65         phome = (PersonHome) PortableRemoteObject.narrow(
66                                         ictx.lookup(BEAN_HOME_PERSON),
67                     PersonHome.class);
68         uhome = (UserHome) PortableRemoteObject.narrow(
69                                         ictx.lookup(BEAN_HOME_USER),
70                     UserHome.class);
71         duhome = (UserHome) PortableRemoteObject.narrow(
72                                         ictx.lookup(BEAN_HOME_DERIVED_USER),
73                     UserHome.class);
74         } catch (NamingException JavaDoc e) {
75         fail("Cannot get bean home: "+e.getMessage());
76         }
77     }
78     }
79
80     /**
81      * test that the bean Person works well
82      */

83     public void testPerson() throws Exception JavaDoc {
84     int id = 0;
85     String JavaDoc name = "Rose";
86     int age = 1; // initial value for Person
87

88     Person prs = phome.create(id, name);
89     Assert.assertEquals("Age", age, prs.getAge());
90     Assert.assertEquals("obj.getValue(10)", "10", prs.getValue(10));
91     prs.remove();
92
93     Assert.assertEquals("home.getValue()", "ejbHomeGetValue", phome.getValue(10));
94     
95     }
96
97     /**
98      * test that the bean User works well
99      */

100     public void testUser() throws Exception JavaDoc {
101     int id = 10;
102     String JavaDoc name = "Helene";
103     String JavaDoc passwd = "oode";
104     int age = 40;
105
106     User usr = uhome.create(id, name);
107     usr.changePassword(passwd);
108     usr.setAge(age);
109     Assert.assertEquals("Password", passwd, usr.getPassword());
110     Assert.assertEquals("Age", age, usr.getAge());
111     Assert.assertEquals("getData()", "UserEC.getData", usr.getData());
112     Assert.assertEquals("obj.getValue(10)", "10", usr.getValue(10));
113     usr.remove();
114
115     Assert.assertEquals("home.getValue()", "ejbHomeGetValue", uhome.getValue(10));
116     
117     }
118
119     /**
120      * test that the bean DerivedUser works well
121      */

122     public void testDerivedUser() throws Exception JavaDoc {
123     int id = 20;
124     String JavaDoc name = "Eric";
125
126     User dusr = duhome.create(id, name);
127     Assert.assertEquals("getData()", "DerivedUserEC.getData", dusr.getData());
128     dusr.remove();
129     }
130
131     public static Test suite() {
132     return new TestSuite(F_Inherit.class);
133     }
134
135     public static void main (String JavaDoc args[]) {
136     String JavaDoc testtorun = null;
137     // Get args
138
for (int argn = 0; argn < args.length; argn++) {
139         String JavaDoc s_arg = args[argn];
140         Integer JavaDoc i_arg;
141         if (s_arg.equals("-n")) {
142         testtorun = args[++argn];
143         }
144     }
145     if (testtorun == null) {
146         junit.textui.TestRunner.run(suite());
147     } else {
148         junit.textui.TestRunner.run(new F_Inherit(testtorun));
149     }
150     }
151 }
152
Popular Tags