001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.cts.ejb;
023:
024: import java.util.Properties;
025: import javax.ejb.DuplicateKeyException;
026: import javax.naming.InitialContext;
027:
028: import org.jboss.test.util.ejb.EJBTestCase;
029: import org.jboss.test.JBossTestCase;
030: import org.jboss.test.cts.interfaces.CtsCmpLocalHome;
031: import org.jboss.test.cts.interfaces.CtsCmpLocal;
032: import org.jboss.test.cts.keys.AccountPK;
033: import org.jboss.logging.Logger;
034: import junit.framework.Test;
035:
036: /** Tests of local ejbs
037: *
038: * @author Scott.Stark@jboss.org
039: * @version $Revision: 57211 $
040: */
041: public class LocalEjbTests extends EJBTestCase {
042: Logger log = Logger.getLogger(LocalEjbTests.class);
043:
044: public LocalEjbTests(String methodName) {
045: super (methodName);
046: }
047:
048: public static Test suite() throws Exception {
049: return JBossTestCase.getDeploySetup(LocalEjbTests.class,
050: "cts.jar");
051: }
052:
053: public void setUpEJB(java.util.Properties props) throws Exception {
054: super .setUpEJB(props);
055: }
056:
057: public void tearDownEJB(Properties props) throws Exception {
058: super .tearDownEJB(props);
059: }
060:
061: public void testEntityIdentity() throws Exception {
062: InitialContext ctx = new InitialContext();
063: CtsCmpLocalHome home = (CtsCmpLocalHome) ctx
064: .lookup("ejbcts/LocalCMPBean");
065: AccountPK key1 = new AccountPK("1");
066: CtsCmpLocal bean1 = null;
067: try {
068: bean1 = home.create(key1, "testEntityIdentity");
069: } catch (DuplicateKeyException e) {
070: bean1 = home.findByPrimaryKey(key1);
071: }
072: AccountPK key2 = new AccountPK("2");
073: CtsCmpLocal bean2 = null;
074: try {
075: bean2 = home.create(key2, "testEntityIdentity");
076: } catch (DuplicateKeyException e) {
077: bean2 = home.findByPrimaryKey(key2);
078: }
079: CtsCmpLocalHome home2 = (CtsCmpLocalHome) ctx
080: .lookup("ejbcts/LocalCMPBean2");
081: CtsCmpLocal bean12 = null;
082: try {
083: bean12 = home2.create(key1, "testEntityIdentity");
084: } catch (DuplicateKeyException e) {
085: bean12 = home2.findByPrimaryKey(key1);
086: }
087:
088: boolean isIdentical = false;
089: isIdentical = bean1.isIdentical(bean1);
090: log.debug(bean1 + " isIdentical to " + bean1 + " = "
091: + isIdentical);
092: assertTrue(bean1 + " isIdentical to " + bean1,
093: isIdentical == true);
094: isIdentical = bean2.isIdentical(bean1);
095: log.debug(bean2 + " isIdentical to " + bean1 + " = "
096: + isIdentical);
097: assertTrue(bean2 + " isIdentical to " + bean1,
098: isIdentical == false);
099: isIdentical = bean1.isIdentical(bean12);
100: log.debug(bean1 + " isIdentical to " + bean12 + " = "
101: + isIdentical);
102: assertTrue(bean1 + " isIdentical to " + bean12,
103: isIdentical == false);
104: }
105: }
|