KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > testbyvalue > test > ByValueUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.testbyvalue.test;
23
24 import java.rmi.*;
25
26
27 import javax.naming.Context JavaDoc;
28 import javax.naming.InitialContext JavaDoc;
29 import javax.ejb.DuplicateKeyException JavaDoc;
30 import javax.ejb.Handle JavaDoc;
31 import javax.ejb.EJBMetaData JavaDoc;
32 import javax.ejb.EJBHome JavaDoc;
33 import javax.ejb.HomeHandle JavaDoc;
34 import javax.rmi.PortableRemoteObject JavaDoc;
35
36 import java.util.Date JavaDoc;
37
38 import junit.framework.Test;
39 import junit.framework.TestCase;
40 import junit.framework.TestSuite;
41
42 import org.jboss.test.JBossTestCase;
43 import org.jboss.test.testbyvalue.interfaces.RootStatelessSessionHome;
44
45 /**
46 * @author Clebert Suconic
47 */

48 public class ByValueUnitTestCase
49 extends JBossTestCase
50 {
51    static boolean deployed = false;
52    static int test = 0;
53    static Date JavaDoc startDate = new Date JavaDoc();
54
55    protected final String JavaDoc namingFactory =
56    System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
57
58    protected final String JavaDoc providerURL =
59    System.getProperty(Context.PROVIDER_URL);
60     private static final int ITERATIONS = 1000;
61
62     public ByValueUnitTestCase(String JavaDoc name) {
63       super(name);
64    }
65
66     public void testByValue() throws Exception JavaDoc
67     {
68         InitialContext JavaDoc ctx = new InitialContext JavaDoc();
69         Object JavaDoc obj = ctx.lookup("RootTestByValue");
70
71         RootStatelessSessionHome home = (RootStatelessSessionHome) PortableRemoteObject.narrow(obj, RootStatelessSessionHome.class);
72         long time = home.create().doTestByValue(ITERATIONS);
73         // I really wanted System.out as I wanted this to be sent to the XML output for ant junit tests
74
System.out.println("Time spent into CallByValues over "+ITERATIONS+" iterations=" + time);
75     }
76
77     public void testByValueOnEntity() throws Exception JavaDoc
78     {
79         InitialContext JavaDoc ctx = new InitialContext JavaDoc();
80         Object JavaDoc obj = ctx.lookup("RootTestByValue");
81
82         RootStatelessSessionHome home = (RootStatelessSessionHome) PortableRemoteObject.narrow(obj, RootStatelessSessionHome.class);
83         long time = home.create().doTestEntity(ITERATIONS);
84         // I really wanted System.out as I wanted this to be sent to the XML output for ant junit tests
85
System.out.println("Time spent into CallByValues over "+ITERATIONS+" iterations=" + time);
86     }
87
88     public void testByReferenceOnEntity() throws Exception JavaDoc
89     {
90         InitialContext JavaDoc ctx = new InitialContext JavaDoc();
91         Object JavaDoc obj = ctx.lookup("RootTestByValue");
92
93         RootStatelessSessionHome home = (RootStatelessSessionHome) PortableRemoteObject.narrow(obj, RootStatelessSessionHome.class);
94         long time = home.create().doTestEntityByReference(ITERATIONS);
95         // I really wanted System.out as I wanted this to be sent to the XML output for ant junit tests
96
System.out.println("Time spent into CallByValues over "+ITERATIONS+" iterations=" + time);
97     }
98
99     public void testByReference() throws Exception JavaDoc
100     {
101         InitialContext JavaDoc ctx = new InitialContext JavaDoc();
102         Object JavaDoc obj = ctx.lookup("RootTestByValue");
103
104         RootStatelessSessionHome home = (RootStatelessSessionHome) PortableRemoteObject.narrow(obj, RootStatelessSessionHome.class);
105         long time = home.create().doTestByReference(ITERATIONS);
106         // I really wanted System.out as I wanted this to be sent to the XML output for ant junit tests
107
System.out.println("Time spent into CallByReferences over "+ITERATIONS+" iterations=" + time);
108     }
109
110    public static Test suite() throws Exception JavaDoc
111    {
112       Test t1 = getDeploySetup(ByValueUnitTestCase.class, "jar-byvalue.jar");
113       return t1;
114    }
115
116 }
117
Popular Tags