KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cts > test > CmpUnitTestCase


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.test;
23
24
25 import java.util.Properties JavaDoc;
26 import javax.naming.InitialContext JavaDoc;
27 import javax.rmi.PortableRemoteObject JavaDoc;
28
29 import junit.framework.Test;
30
31 import org.jboss.test.JBossTestCase;
32 import org.jboss.test.cts.interfaces.CtsCmp;
33 import org.jboss.test.cts.interfaces.CtsCmpHome;
34 import org.jboss.test.cts.keys.AccountPK;
35
36 /** Basic conformance tests for stateless sessions
37  *
38  * @author kimptoc
39  * @author d_jencks converted to JBossTestCase and logging.
40  * @author Scott.Stark@jboss.org
41  * @version $Revision: 37406 $
42  */

43 public class CmpUnitTestCase
44       extends JBossTestCase
45 {
46    private CtsCmpHome home;
47
48    public CmpUnitTestCase(String JavaDoc name)
49    {
50       super(name);
51    }
52
53    protected void setUp() throws Exception JavaDoc
54    {
55       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
56       Object JavaDoc ref = ctx.lookup("ejbcts/CMPBean");
57       home = (CtsCmpHome) ref;
58    }
59
60    protected void tearDown() throws Exception JavaDoc
61    {
62    }
63
64    /**
65     * Method testBasicStatelessSession
66     * @throws Exception
67     */

68    public void testBasicCmp()
69          throws Exception JavaDoc
70    {
71       getLog().debug("+++ testBasicCmp()");
72       AccountPK pk = new AccountPK("testBasicCmp");
73       CtsCmp bean = home.create(pk, "testBasicCmp unitTest");
74       String JavaDoc result = bean.getPersonsName();
75       // Test response
76
assertTrue(result.equals("testBasicCmp unitTest"));
77       bean.remove();
78    }
79
80    /** Test of accessing the home interface from the remote interface in an env
81     * new InitialContext() will not work.
82     * @throws Exception
83     */

84    public void testHomeFromRemoteNoDefaultJNDI()
85          throws Exception JavaDoc
86    {
87       getLog().debug("+++ testHomeFromRemoteNoDefaultJNDI()");
88
89       // Override the JNDI variables in the System properties
90
Properties JavaDoc sysProps = System.getProperties();
91       Properties JavaDoc newProps = new Properties JavaDoc(sysProps);
92       newProps.setProperty("java.naming.factory.initial", "badFactory");
93       newProps.setProperty("java.naming.provider.url", "jnp://badhost:12345");
94       System.setProperties(newProps);
95
96       // Do a lookup of the home and create a remote using a custom env
97
Properties JavaDoc env = new Properties JavaDoc();
98       env.setProperty("java.naming.factory.initial", super.getJndiInitFactory());
99       env.setProperty("java.naming.provider.url", super.getJndiURL());
100       try
101       {
102          InitialContext JavaDoc ctx = new InitialContext JavaDoc(env);
103          Object JavaDoc ref = ctx.lookup("ejbcts/CMPBean");
104          CtsCmpHome home = (CtsCmpHome)
105                PortableRemoteObject.narrow(ref, CtsCmpHome.class);
106          AccountPK pk1 = new AccountPK("bean1");
107          CtsCmp bean1 = home.create(pk1, "testHomeFromRemoteNoDefaultJNDI");
108          CtsCmpHome home2 = (CtsCmpHome) bean1.getEJBHome();
109          AccountPK pk2 = new AccountPK("bean2");
110          CtsCmp bean2 = home2.create(pk2, "testHomeFromRemoteNoDefaultJNDI");
111          bean2.remove();
112       }
113       finally
114       {
115          System.setProperties(sysProps);
116       }
117    }
118
119    public static Test suite() throws Exception JavaDoc
120    {
121       return getDeploySetup(CmpUnitTestCase.class, "cts.jar");
122    }
123
124 }
125
Popular Tags