KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cts > ejb > LocalEjbTests


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.cts.ejb;
23
24 import java.util.Properties JavaDoc;
25 import javax.ejb.DuplicateKeyException JavaDoc;
26 import javax.naming.InitialContext JavaDoc;
27
28 import org.jboss.test.util.ejb.EJBTestCase;
29 import org.jboss.test.JBossTestCase;
30 import org.jboss.test.cts.interfaces.CtsCmpLocalHome;
31 import org.jboss.test.cts.interfaces.CtsCmpLocal;
32 import org.jboss.test.cts.keys.AccountPK;
33 import org.jboss.logging.Logger;
34 import junit.framework.Test;
35
36 /** Tests of local ejbs
37  *
38  * @author Scott.Stark@jboss.org
39  * @version $Revision: 37406 $
40  */

41 public class LocalEjbTests extends EJBTestCase
42 {
43    Logger log = Logger.getLogger(LocalEjbTests.class);
44
45    public LocalEjbTests(String JavaDoc methodName)
46    {
47       super(methodName);
48    }
49
50    public static Test suite() throws Exception JavaDoc
51    {
52         return JBossTestCase.getDeploySetup(LocalEjbTests.class, "cts.jar");
53    }
54
55    public void setUpEJB(java.util.Properties JavaDoc props) throws Exception JavaDoc
56    {
57       super.setUpEJB(props);
58    }
59
60    public void tearDownEJB(Properties JavaDoc props) throws Exception JavaDoc
61    {
62       super.tearDownEJB(props);
63    }
64
65    public void testEntityIdentity() throws Exception JavaDoc
66    {
67       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
68       CtsCmpLocalHome home = (CtsCmpLocalHome) ctx.lookup("ejbcts/LocalCMPBean");
69       AccountPK key1 = new AccountPK("1");
70       CtsCmpLocal bean1 = null;
71       try
72       {
73          bean1 = home.create(key1, "testEntityIdentity");
74       }
75       catch(DuplicateKeyException JavaDoc e)
76       {
77          bean1 = home.findByPrimaryKey(key1);
78       }
79       AccountPK key2 = new AccountPK("2");
80       CtsCmpLocal bean2 = null;
81       try
82       {
83          bean2 = home.create(key2, "testEntityIdentity");
84       }
85       catch(DuplicateKeyException JavaDoc e)
86       {
87          bean2 = home.findByPrimaryKey(key2);
88       }
89       CtsCmpLocalHome home2 = (CtsCmpLocalHome) ctx.lookup("ejbcts/LocalCMPBean2");
90       CtsCmpLocal bean12 = null;
91       try
92       {
93          bean12 = home2.create(key1, "testEntityIdentity");
94       }
95       catch(DuplicateKeyException JavaDoc e)
96       {
97          bean12 = home2.findByPrimaryKey(key1);
98       }
99
100       boolean isIdentical = false;
101       isIdentical = bean1.isIdentical(bean1);
102       log.debug(bean1+" isIdentical to "+bean1+" = "+isIdentical);
103       assertTrue(bean1+" isIdentical to "+bean1, isIdentical == true);
104       isIdentical = bean2.isIdentical(bean1);
105       log.debug(bean2+" isIdentical to "+bean1+" = "+isIdentical);
106       assertTrue(bean2+" isIdentical to "+bean1, isIdentical == false);
107       isIdentical = bean1.isIdentical(bean12);
108       log.debug(bean1+" isIdentical to "+bean12+" = "+isIdentical);
109       assertTrue(bean1+" isIdentical to "+bean12, isIdentical == false);
110    }
111 }
112
Popular Tags