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.stateless;
017:
018: import javax.ejb.EJBHome;
019:
020: /**
021: * [8] Should be run as the eigth test suite of the BasicStatelessTestClients
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 StatelessEjbMetaDataTests extends BasicStatelessTestClient {
027:
028: public StatelessEjbMetaDataTests() {
029: super ("EJBMetaData.");
030: }
031:
032: protected void setUp() throws Exception {
033: super .setUp();
034: Object obj = initialContext
035: .lookup("client/tests/stateless/BasicStatelessHome");
036: ejbHome = (BasicStatelessHome) javax.rmi.PortableRemoteObject
037: .narrow(obj, BasicStatelessHome.class);
038: ejbMetaData = ejbHome.getEJBMetaData();
039: }
040:
041: //=================================
042: // Test meta data methods
043: //
044: public void test01_getEJBHome() {
045: try {
046:
047: EJBHome home = ejbMetaData.getEJBHome();
048: assertNotNull("The EJBHome is null", home);
049: } catch (Exception e) {
050: fail("Received Exception " + e.getClass() + " : "
051: + e.getMessage());
052: }
053: }
054:
055: public void test02_getHomeInterfaceClass() {
056: try {
057: Class clazz = ejbMetaData.getHomeInterfaceClass();
058: assertNotNull("The Home Interface class is null", clazz);
059: assertEquals(clazz, BasicStatelessHome.class);
060: } catch (Exception e) {
061: fail("Received Exception " + e.getClass() + " : "
062: + e.getMessage());
063: }
064: }
065:
066: /**
067: * 5.5 Session object identity
068: *
069: * Session objects are intended to be private resources used only by the
070: * client that created them. For this reason, session objects, from the
071: * client's perspective, appear anonymous. In contrast to entity objects,
072: * which expose their identity as a primary key, session objects hide their
073: * identity. As a result, the EJBObject.getPrimaryKey() and
074: * EJBHome.remove(Object primaryKey) methods result in a java.rmi.RemoteException
075: * if called on a session bean. If the EJBMetaData.getPrimaryKeyClass()
076: * method is invoked on a EJBMetaData object for a Session bean, the method throws
077: * the java.lang.RuntimeException.
078: */
079: public void test03_getPrimaryKeyClass() {
080: try {
081: Class clazz = ejbMetaData.getPrimaryKeyClass();
082: assertNull(
083: "Should not return a primary key. Method should throw an java.lang.RuntimeException",
084: clazz);
085: } catch (UnsupportedOperationException e) {
086: assertTrue(true);
087: return;
088: } catch (Exception e) {
089: fail("Received Exception " + e.getClass() + " : "
090: + e.getMessage());
091: }
092: assertTrue("Method should throw an java.lang.RuntimeException",
093: false);
094: }
095:
096: public void test04_getRemoteInterfaceClass() {
097: try {
098: Class clazz = ejbMetaData.getRemoteInterfaceClass();
099: assertNotNull("The Remote Interface class is null", clazz);
100: assertEquals(clazz, BasicStatelessObject.class);
101: } catch (Exception e) {
102: fail("Received Exception " + e.getClass() + " : "
103: + e.getMessage());
104: }
105: }
106:
107: public void test05_isSession() {
108: try {
109: assertTrue("EJBMetaData says this is not a session bean",
110: ejbMetaData.isSession());
111: } catch (Exception e) {
112: fail("Received Exception " + e.getClass() + " : "
113: + e.getMessage());
114: }
115: }
116:
117: public void test06_isStatelessSession() {
118: try {
119: assertTrue(
120: "EJBMetaData says this is not a stateless session bean",
121: ejbMetaData.isStatelessSession());
122: } catch (Exception e) {
123: fail("Received Exception " + e.getClass() + " : "
124: + e.getMessage());
125: }
126: }
127: //
128: // Test meta data methods
129: //=================================
130: }
|