1 25 26 package org.objectweb.jonas.jtests.clients.entity; 27 28 import javax.naming.NamingException ; 29 import javax.rmi.PortableRemoteObject ; 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 47 public class F_Inherit extends JTestCase { 48 49 private static String BEAN_HOME_PERSON = "inheritPersonECHome"; 50 protected static PersonHome phome = null; 51 private static String BEAN_HOME_USER = "inheritUserECHome"; 52 protected static UserHome uhome = null; 53 private static String BEAN_HOME_DERIVED_USER = "inheritDerivedUserECHome"; 54 protected static UserHome duhome = null; 55 56 public F_Inherit(String 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 e) { 75 fail("Cannot get bean home: "+e.getMessage()); 76 } 77 } 78 } 79 80 83 public void testPerson() throws Exception { 84 int id = 0; 85 String name = "Rose"; 86 int age = 1; 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 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 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 122 public void testDerivedUser() throws Exception { 123 int id = 20; 124 String 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 args[]) { 136 String testtorun = null; 137 for (int argn = 0; argn < args.length; argn++) { 139 String s_arg = args[argn]; 140 Integer 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 |