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_Frontal.java 9237 2006-07-26 08:33:32Z coqp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.distribution;
027:
028: import java.rmi.NoSuchObjectException;
029: import javax.naming.NamingException;
030: import javax.rmi.PortableRemoteObject;
031:
032: import junit.framework.Assert;
033: import junit.framework.Test;
034: import junit.framework.TestSuite;
035:
036: import org.objectweb.carol.util.perfs.CarolJRMPPerformanceHelper;
037: import org.objectweb.jonas.jtests.beans.folder.File;
038: import org.objectweb.jonas.jtests.beans.folder.Folder;
039: import org.objectweb.jonas.jtests.beans.folder.FolderHome;
040: import org.objectweb.jonas.jtests.util.JTestCase;
041:
042: /**
043: * Test a session bean remote accessing entities local.
044: * Beans used: folder
045: * @author Philippe Durieux
046: */
047: public class F_Frontal extends JTestCase {
048:
049: protected static FolderHome fhome = null;
050: protected Folder folder = null;
051:
052: public F_Frontal(String name) {
053: super (name);
054: }
055:
056: protected void setUp() {
057: super .setUp();
058: if (fhome == null) {
059: useBeans("folder", true);
060: try {
061: fhome = (FolderHome) PortableRemoteObject.narrow(ictx
062: .lookup("FolderSYHome"), FolderHome.class);
063: assertNotNull(fhome);
064: } catch (NamingException e) {
065: fail("Cannot get bean home");
066: }
067: }
068: if (folder == null) {
069: try {
070: folder = fhome.create();
071: assertNotNull(folder);
072: } catch (Exception e) {
073: fail("Cannot create folder session " + e);
074: }
075: }
076: }
077:
078: public void testSetRollbackOnly() throws Exception {
079: Folder f1 = fhome.createForRollback();
080: f1.getIntTS(2);
081: f1.remove();
082: }
083:
084: /**
085: * create 1 entity and remove it by its remote reference.
086: */
087: public void testCreate1F() throws Exception {
088: File f = folder.newFile("file1");
089: assertNotNull(f);
090: f.remove();
091: }
092:
093: public void testAccessOnRemovedEntity() throws Exception {
094: File f = folder.newFile("file1");
095: File f2 = folder.getFile("file1");
096: f2.remove();
097: try {
098: f.getName();
099: fail("Should not access deleted object");
100: } catch (NoSuchObjectException e) {
101: } catch (Exception e) {
102: fail("Bab Exception:" + e);
103: }
104: }
105:
106: /**
107: * print serialized form of the reference
108: */
109: public void testSerializedReference() throws Exception {
110: String mfolder = CarolJRMPPerformanceHelper
111: .getMarshalBytes(folder);
112: //System.out.println("Marshalled Ref = " + mfolder);
113: }
114:
115: /**
116: * send a reference as argument
117: */
118: public void testSendRef() throws Exception {
119: for (int i = 0; i < 20; i++) {
120: folder.sendRef(folder);
121: }
122: }
123:
124: /**
125: * send an int as argument
126: */
127: public void testSendInt() throws Exception {
128: for (int i = 0; i < 20; i++) {
129: folder.sendInt(1);
130: }
131: }
132:
133: /**
134: * send and get a reference as argument
135: */
136: public void testGetRef() throws Exception {
137: for (int i = 0; i < 20; i++) {
138: folder.getRef(folder);
139: }
140: }
141:
142: /**
143: * send and get an int as argument
144: */
145: public void testGetInt() throws Exception {
146: for (int i = 0; i < 20; i++) {
147: folder.getInt(1);
148: }
149: }
150:
151: /**
152: * send a reference as argument
153: */
154: public void testSendRefTS() throws Exception {
155: for (int i = 0; i < 20; i++) {
156: folder.sendRefTS(folder);
157: }
158: }
159:
160: /**
161: * send an int as argument
162: */
163: public void testSendIntTS() throws Exception {
164: for (int i = 0; i < 20; i++) {
165: folder.sendIntTS(1);
166: }
167: }
168:
169: /**
170: * send and get a reference as argument
171: */
172: public void testGetRefTS() throws Exception {
173: for (int i = 0; i < 20; i++) {
174: folder.getRefTS(folder);
175: }
176: }
177:
178: /**
179: * send and get an int as argument
180: */
181: public void testGetIntTS() throws Exception {
182: for (int i = 0; i < 20; i++) {
183: folder.getIntTS(1);
184: }
185: }
186:
187: /**
188: * to reproduce bug 305498
189: * use ejbql query SELECT SUM (p.value) FROM jt2_paper AS p]
190: */
191: public void testModify() throws Exception {
192: int result = folder.modify("aaaa", 100);
193: Assert.assertEquals("bad result", 120, result);
194: }
195:
196: /**
197: * try to reproduce bug on ejbSelect #305711
198: * use ejbql query SELECT SUM (p.valeur) FROM jt2_paper2 AS p WHERE p.paper3.valide = '1'
199: */
200: public void testModifyPaper2And3() throws Exception {
201: int result = folder.modifypaper2And3("1", 55);
202: Assert.assertEquals("bad result", 85, result);
203: }
204:
205: /**
206: * to see if the previous pb on ejbSelect exists on finder
207: * Here we use a finder method with
208: * SELECT OBJECT(o) FROM jt2_paper2 AS p WHERE p.paper3.valide = '1'
209: */
210: public void testModifyPaper2And3WithFinder() throws Exception {
211: int result = folder.modifypaper2And3WithFinder("1", 55);
212: Assert.assertEquals("bad result", 3, result);
213: }
214:
215: public static Test suite() {
216: return new TestSuite(F_Frontal.class);
217: }
218:
219: public static void main(String args[]) {
220: String testtorun = null;
221: // Get args
222: for (int argn = 0; argn < args.length; argn++) {
223: String s_arg = args[argn];
224: Integer i_arg;
225: if (s_arg.equals("-n")) {
226: testtorun = args[++argn];
227: }
228: }
229: if (testtorun == null) {
230: junit.textui.TestRunner.run(suite());
231: } else {
232: junit.textui.TestRunner.run(new F_Frontal(testtorun));
233: }
234: }
235: }
|