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