001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.test.stateful;
017:
018: import javax.ejb.EJBHome;
019:
020: /**
021: * [8] Should be run as the eigth test suite of the BasicStatefulTestClients
022: *
023: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
024: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
025: */
026: public class StatefulEjbMetaDataTests extends BasicStatefulTestClient {
027:
028: public StatefulEjbMetaDataTests() {
029: super ("EJBMetaData.");
030: }
031:
032: protected void setUp() throws Exception {
033: super .setUp();
034: Object obj = initialContext
035: .lookup("client/tests/stateful/BasicStatefulHome");
036: ejbHome = (BasicStatefulHome) javax.rmi.PortableRemoteObject
037: .narrow(obj, BasicStatefulHome.class);
038: ejbMetaData = ejbHome.getEJBMetaData();
039: }
040:
041: //=================================
042: // Test meta data methods
043: //
044: public void test01_getEJBHome() {
045: try {
046: EJBHome home = ejbMetaData.getEJBHome();
047: assertNotNull("The EJBHome is null", home);
048: } catch (Exception e) {
049: fail("Received Exception " + e.getClass() + " : "
050: + e.getMessage());
051: }
052: }
053:
054: public void test02_getHomeInterfaceClass() {
055: try {
056: Class clazz = ejbMetaData.getHomeInterfaceClass();
057: assertNotNull("The Home Interface class is null", clazz);
058: assertEquals(clazz, BasicStatefulHome.class);
059: } catch (Exception e) {
060: fail("Received Exception " + e.getClass() + " : "
061: + e.getMessage());
062: }
063: }
064:
065: /**
066: * 5.5 Session object identity
067: *
068: * Session objects are intended to be private resources used only by the
069: * client that created them. For this reason, session objects, from the
070: * client's perspective, appear anonymous. In contrast to entity objects,
071: * which expose their identity as a primary key, session objects hide their
072: * identity. As a result, the EJBObject.getPrimaryKey() and
073: * EJBHome.remove(Object primaryKey) methods result in a java.rmi.RemoteException
074: * if called on a session bean. If the EJBMetaData.getPrima-ryKeyClass()
075: * method is invoked on a EJBMetaData object for a Session bean, the method throws
076: * the java.lang.RuntimeException.
077: */
078: public void test03_getPrimaryKeyClass() {
079: try {
080: Class clazz = ejbMetaData.getPrimaryKeyClass();
081: assertNull(
082: "Should not return a primary key. Method should throw an java.lang.RuntimeException",
083: clazz);
084: } catch (UnsupportedOperationException e) {
085: assertTrue(true);
086: return;
087: } catch (Exception e) {
088: fail("Received Exception " + e.getClass() + " : "
089: + e.getMessage());
090: }
091: assertTrue("Method should throw an java.lang.RuntimeException",
092: false);
093: }
094:
095: public void test04_getRemoteInterfaceClass() {
096: try {
097: Class clazz = ejbMetaData.getRemoteInterfaceClass();
098: assertNotNull("The Remote Interface class is null", clazz);
099: assertEquals(clazz, BasicStatefulObject.class);
100: } catch (Exception e) {
101: fail("Received Exception " + e.getClass() + " : "
102: + e.getMessage());
103: }
104: }
105:
106: public void test05_isSession() {
107: try {
108: assertTrue("EJBMetaData says this is not a session bean",
109: ejbMetaData.isSession());
110: } catch (Exception e) {
111: fail("Received Exception " + e.getClass() + " : "
112: + e.getMessage());
113: }
114: }
115:
116: public void test06_isStatelessSession() {
117: try {
118: assertTrue(
119: "EJBMetaData says this is a stateless session bean",
120: !ejbMetaData.isStatelessSession());
121: } catch (Exception e) {
122: fail("Received Exception " + e.getClass() + " : "
123: + e.getMessage());
124: }
125: }
126: //
127: // Test meta data methods
128: //=================================
129: }
|