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_ClientViewSF.java 7497 2005-10-13 07:53:22Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.session;
027:
028: import junit.framework.Test;
029: import junit.framework.TestSuite;
030: import javax.rmi.PortableRemoteObject;
031: import org.objectweb.jonas.jtests.beans.local.Target;
032: import org.objectweb.jonas.jtests.beans.local.TargetSFHome;
033: import org.objectweb.jonas.jtests.beans.local.TargetSLHome;
034:
035: /**
036: * testcases specifics for stateful session beans must be here
037: *
038: * - isIdentical, create<Method>
039: */
040: public class F_ClientViewSF extends A_ClientView {
041:
042: protected static String BEAN_HOME = "EJB/localTargetSFHome";
043: protected static TargetSFHome home = null;
044:
045: public F_ClientViewSF(String name) {
046: super (name);
047: }
048:
049: /**
050: * test EJBObject.isIdentical on two beans
051: * @see Spec EJB2.0 6.9.1
052: */
053: public void testIsIdenticalOnBeans() throws Exception {
054: Target tr1 = (Target) getHome().create();
055: Target tr2 = (Target) getHome().create();
056: assertTrue(!tr1.isIdentical(tr2));
057: tr1.remove();
058: tr2.remove();
059: }
060:
061: /**
062: * test create with parameters
063: */
064: public void testCreateWithParameter() throws Exception {
065: String s1 = "String1";
066: TargetSFHome tsfh = (TargetSFHome) getHome();
067: Target tr = tsfh.create(s1, 1000);
068: assertEquals(tr.getString(), s1);
069: assertEquals(tr.getNumber(), 1000);
070: assertTrue(!tr.isCreatedViaCreateXX());
071: tr.remove();
072: }
073:
074: /**
075: * test create<METHOD>
076: *
077: */
078: public void testCreateMethod() throws Exception {
079: String s2 = "String2";
080: TargetSFHome tsfh = (TargetSFHome) getHome();
081: Target tr = tsfh.createXX(s2, 2000);
082: assertEquals(tr.getString(), s2);
083: assertEquals(tr.getNumber(), 2000);
084: assertTrue(tr.isCreatedViaCreateXX());
085: tr.remove();
086: }
087:
088: /**
089: * Test for stateful session bean serialization
090: */
091: public void testSerialization() throws Exception {
092: final int tnb1 = 6;
093: final int tnb2 = 4;
094: Target[] tarray1 = new Target[tnb1];
095: Target[] tarray2 = new Target[tnb2];
096: TargetSFHome tsfh = (TargetSFHome) getHome();
097: for (int i = 0; i < tnb1; i++) {
098: tarray1[i] = tsfh.create("seri", i);
099: }
100: for (int i = 0; i < tnb1; i++) {
101: assertEquals(tarray1[i].getNumber(), i);
102: }
103: for (int i = 0; i < tnb2; i++) {
104: tarray2[i] = tsfh.create("seri", i);
105: }
106: for (int i = 0; i < tnb2; i++) {
107: assertEquals(tarray2[i].getNumber(), i);
108: }
109: for (int i = 0; i < tnb1; i++) {
110: assertEquals(tarray1[i].getNumber(), i);
111: }
112: for (int i = 0; i < tnb2; i++) {
113: tarray2[i].remove();
114: }
115: for (int i = 0; i < tnb1; i++) {
116: tarray1[i].remove();
117: }
118: }
119:
120: /**
121: * init environment:
122: */
123: protected void setUp() {
124: super .setUp();
125: useBeans("local", false);
126: }
127:
128: public TargetSLHome getHome() throws Exception {
129: if (home == null) {
130: home = (TargetSFHome) PortableRemoteObject.narrow(ictx
131: .lookup(BEAN_HOME), TargetSFHome.class);
132: }
133: assertTrue(home != null);
134: return home;
135: }
136:
137: public static Test suite() {
138: return new TestSuite(F_ClientViewSF.class);
139: }
140:
141: public static void main(String args[]) throws Exception {
142: String testtorun = null;
143: // Get args
144: for (int argn = 0; argn < args.length; argn++) {
145: String s_arg = args[argn];
146: Integer i_arg;
147: if (s_arg.equals("-n")) {
148: testtorun = args[++argn];
149: }
150: }
151: if (testtorun == null) {
152: junit.textui.TestRunner.run(suite());
153: } else {
154: junit.textui.TestRunner.run(new F_ClientViewSF(testtorun));
155:
156: }
157: }
158: }
|