001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: F_Inherit.java 7471 2005-10-05 15:08:35Z ashah $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.entity;
027:
028: import javax.naming.NamingException;
029: import javax.rmi.PortableRemoteObject;
030:
031: import junit.framework.Test;
032: import junit.framework.TestSuite;
033:
034: import org.objectweb.jonas.jtests.beans.inherit.Person;
035: import org.objectweb.jonas.jtests.beans.inherit.PersonHome;
036: import org.objectweb.jonas.jtests.beans.inherit.User;
037: import org.objectweb.jonas.jtests.beans.inherit.UserHome;
038: import org.objectweb.jonas.jtests.util.JTestCase;
039:
040: /**
041: * This test check it's possible to use inheritance to develop beans.
042: * (The test is essentially do at the beans compilation and beans deployment !!!)
043: * Beans used: inherit
044: * @author Helene Joanin (jonas team)
045: */
046: public class F_Inherit extends JTestCase {
047:
048: private static String BEAN_HOME_PERSON = "inheritPersonECHome";
049: protected static PersonHome phome = null;
050: private static String BEAN_HOME_USER = "inheritUserECHome";
051: protected static UserHome uhome = null;
052: private static String BEAN_HOME_DERIVED_USER = "inheritDerivedUserECHome";
053: protected static UserHome duhome = null;
054:
055: public F_Inherit(String name) {
056: super (name);
057: }
058:
059: protected void setUp() {
060: super .setUp();
061: if ((phome == null) || (uhome == null) || (duhome == null)) {
062: useBeans("inherit", true);
063: try {
064: phome = (PersonHome) PortableRemoteObject.narrow(ictx
065: .lookup(BEAN_HOME_PERSON), PersonHome.class);
066: uhome = (UserHome) PortableRemoteObject.narrow(ictx
067: .lookup(BEAN_HOME_USER), UserHome.class);
068: duhome = (UserHome) PortableRemoteObject
069: .narrow(ictx.lookup(BEAN_HOME_DERIVED_USER),
070: UserHome.class);
071: } catch (NamingException e) {
072: fail("Cannot get bean home: " + e.getMessage());
073: }
074: }
075: }
076:
077: /**
078: * test that the bean Person works well
079: */
080: public void testPerson() throws Exception {
081: int id = 0;
082: String name = "Rose";
083: int age = 1; // initial value for Person
084:
085: Person prs = phome.create(id, name);
086: try {
087: assertEquals("Age", age, prs.getAge());
088: assertEquals("obj.getValue(10)", "10", prs.getValue(10));
089: } finally {
090: prs.remove();
091: }
092:
093: assertEquals("home.getValue()", "ejbHomeGetValue", phome
094: .getValue(10));
095: }
096:
097: /**
098: * test that the bean User works well
099: */
100: public void testUser() throws Exception {
101: int id = 10;
102: String name = "Helene";
103: String passwd = "oode";
104: int age = 40;
105:
106: User usr = uhome.create(id, name);
107: try {
108: usr.changePassword(passwd);
109: usr.setAge(age);
110: assertEquals("Password", passwd, usr.getPassword());
111: assertEquals("Age", age, usr.getAge());
112: assertEquals("getData()", "UserEC.getData", usr.getData());
113: assertEquals("obj.getValue(10)", "10", usr.getValue(10));
114: } finally {
115: usr.remove();
116: }
117:
118: assertEquals("home.getValue()", "ejbHomeGetValue", uhome
119: .getValue(10));
120: }
121:
122: /**
123: * test that the bean DerivedUser works well
124: */
125: public void testDerivedUser() throws Exception {
126: int id = 20;
127: String name = "Eric";
128:
129: User dusr = duhome.create(id, name);
130: try {
131: assertEquals("getData()", "DerivedUserEC.getData", dusr
132: .getData());
133: } finally {
134: dusr.remove();
135: }
136: }
137:
138: public static Test suite() {
139: return new TestSuite(F_Inherit.class);
140: }
141:
142: public static void main(String args[]) {
143: String testtorun = null;
144: // Get args
145: for (int argn = 0; argn < args.length; argn++) {
146: String s_arg = args[argn];
147: Integer i_arg;
148: if (s_arg.equals("-n")) {
149: testtorun = args[++argn];
150: }
151: }
152: if (testtorun == null) {
153: junit.textui.TestRunner.run(suite());
154: } else {
155: junit.textui.TestRunner.run(new F_Inherit(testtorun));
156: }
157: }
158: }
|