KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > test > stateless > StatelessEjbMetaDataTests


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "Exolab" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of Exoffice Technologies. For written permission,
18  * please contact info@exolab.org.
19  *
20  * 4. Products derived from this Software may not be called "Exolab"
21  * nor may "Exolab" appear in their names without prior written
22  * permission of Exoffice Technologies. Exolab is a registered
23  * trademark of Exoffice Technologies.
24  *
25  * 5. Due credit should be given to the Exolab Project
26  * (http://www.exolab.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 1999 (C) Exoffice Technologies Inc. All Rights Reserved.
42  *
43  * $Id: StatelessEjbMetaDataTests.java 1096 2004-03-26 21:41:16Z dblevins $
44  */

45 package org.openejb.test.stateless;
46
47 import javax.ejb.EJBHome JavaDoc;
48
49 /**
50  * [8] Should be run as the eigth test suite of the BasicStatelessTestClients
51  *
52  * @author <a HREF="mailto:david.blevins@visi.com">David Blevins</a>
53  * @author <a HREF="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
54  */

55 public class StatelessEjbMetaDataTests extends BasicStatelessTestClient{
56
57     public StatelessEjbMetaDataTests(){
58         super("EJBMetaData.");
59     }
60
61     protected void setUp() throws Exception JavaDoc{
62         super.setUp();
63         Object JavaDoc obj = initialContext.lookup("client/tests/stateless/BasicStatelessHome");
64         ejbHome = (BasicStatelessHome)javax.rmi.PortableRemoteObject.narrow( obj, BasicStatelessHome.class);
65         ejbMetaData = ejbHome.getEJBMetaData();
66     }
67
68     //=================================
69
// Test meta data methods
70
//
71
public void test01_getEJBHome(){
72         try{
73
74         EJBHome JavaDoc home = ejbMetaData.getEJBHome();
75         assertNotNull( "The EJBHome is null", home );
76         } catch (Exception JavaDoc e){
77             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
78         }
79     }
80
81     public void test02_getHomeInterfaceClass(){
82         try{
83         Class JavaDoc clazz = ejbMetaData.getHomeInterfaceClass();
84         assertNotNull( "The Home Interface class is null", clazz );
85         assertEquals(clazz , BasicStatelessHome.class);
86         } catch (Exception JavaDoc e){
87             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
88         }
89     }
90     /**
91      * 5.5 Session object identity
92      *
93      * Session objects are intended to be private resources used only by the
94      * client that created them. For this reason, session objects, from the
95      * client’s perspective, appear anonymous. In contrast to entity objects,
96      * which expose their identity as a primary key, session objects hide their
97      * identity. As a result, the EJBObject.getPrimaryKey() and
98      * EJBHome.remove(Object primaryKey) methods result in a java.rmi.RemoteException
99      * if called on a session bean. If the EJBMetaData.getPrimaryKeyClass()
100      * method is invoked on a EJBMetaData object for a Session bean, the method throws
101      * the java.lang.RuntimeException.
102      */

103     public void test03_getPrimaryKeyClass(){
104         try{
105             Class JavaDoc clazz = ejbMetaData.getPrimaryKeyClass();
106             assertNull("Should not return a primary key. Method should throw an java.lang.RuntimeException", clazz );
107         } catch (UnsupportedOperationException JavaDoc e){
108             assertTrue( true );
109             return;
110         } catch (Exception JavaDoc e){
111             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
112         }
113         assertTrue( "Method should throw an java.lang.RuntimeException", false );
114     }
115
116     public void test04_getRemoteInterfaceClass(){
117         try{
118         Class JavaDoc clazz = ejbMetaData.getRemoteInterfaceClass();
119         assertNotNull( "The Remote Interface class is null", clazz );
120         assertEquals(clazz , BasicStatelessObject.class);
121         } catch (Exception JavaDoc e){
122             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
123         }
124     }
125
126     public void test05_isSession(){
127         try{
128         assertTrue( "EJBMetaData says this is not a session bean", ejbMetaData.isSession() );
129         } catch (Exception JavaDoc e){
130             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
131         }
132     }
133
134     public void test06_isStatelessSession(){
135         try{
136         assertTrue( "EJBMetaData says this is not a stateless session bean", ejbMetaData.isStatelessSession() );
137         } catch (Exception JavaDoc e){
138             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
139         }
140     }
141     //
142
// Test meta data methods
143
//=================================
144
}
145
Popular Tags