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: import javax.ejb.EJBLocalHome;
020:
021: /**
022: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
023: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
024: * @author <a href="mailto:manu.t.george@gmail.com">Manu George</a>
025: */
026: public class StatefulPojoEjbLocalObjectTests extends
027: BasicStatefulLocalTestClient {
028:
029: public StatefulPojoEjbLocalObjectTests() {
030: super ("EJBLocalObject.");
031: }
032:
033: protected void setUp() throws Exception {
034: super .setUp();
035: Object obj = initialContext
036: .lookup("client/tests/stateful/BasicStatefulPojoHomeLocal");
037: ejbLocalHome = (BasicStatefulLocalHome) obj;
038: ejbLocalObject = ejbLocalHome
039: .create("StatefulEjbLocalObject Test Bean");
040: }
041:
042: protected void tearDown() throws Exception {
043: super .tearDown();
044: }
045:
046: public void test01_isIdentical() {
047: try {
048: assertTrue("The EJBObjects are not equal", ejbLocalObject
049: .isIdentical(ejbLocalObject));
050: } catch (Exception e) {
051: fail("Received Exception " + e.getClass() + " : "
052: + e.getMessage());
053: }
054: }
055:
056: public void test02_getEjbLocalHome() {
057: try {
058: EJBLocalHome localHome = ejbLocalObject.getEJBLocalHome();
059: assertNotNull("The EJBHome is null", localHome);
060: } catch (Exception e) {
061: fail("Received Exception " + e.getClass() + " : "
062: + e.getMessage());
063: }
064: }
065:
066: /**
067: * 3.6.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 EJBLocalObject.getPrimaryKey() method results in a
074: * javax.ejb.EJBException, and EJBLocalHome.remove(Object primaryKey) method results
075: * in a javax.ejb.RemoveException. 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_getPrimaryKey() {
080: try {
081: Object key = ejbLocalObject.getPrimaryKey();
082: } catch (javax.ejb.EJBException e) {
083: assertTrue(true);
084: return;
085: } catch (Exception e) {
086: fail("A RuntimeException should have been thrown. Received Exception "
087: + e.getClass() + " : " + e.getMessage());
088: }
089: fail("A RuntimeException should have been thrown.");
090: }
091:
092: public void test04_remove() {
093: try {
094: try {
095: ejbLocalObject.remove();
096: ejbLocalObject
097: .businessMethod("Should throw an exception");
098: assertTrue(
099: "Calling business method after removing the EJBObject does not throw an exception",
100: false);
101: } catch (Exception e) {
102: assertTrue(true);
103: return;
104: }
105: } catch (Exception e) {
106: fail("Received Exception " + e.getClass() + " : "
107: + e.getMessage());
108: }
109: }
110:
111: }
|