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.test;
023:
024: import java.util.Properties;
025: import javax.naming.InitialContext;
026: import javax.rmi.PortableRemoteObject;
027:
028: import junit.framework.Test;
029:
030: import org.jboss.test.JBossTestCase;
031: import org.jboss.test.cts.interfaces.CtsCmp;
032: import org.jboss.test.cts.interfaces.CtsCmpHome;
033: import org.jboss.test.cts.keys.AccountPK;
034:
035: /** Basic conformance tests for stateless sessions
036: *
037: * @author kimptoc
038: * @author d_jencks converted to JBossTestCase and logging.
039: * @author Scott.Stark@jboss.org
040: * @version $Revision: 57211 $
041: */
042: public class CmpUnitTestCase extends JBossTestCase {
043: private CtsCmpHome home;
044:
045: public CmpUnitTestCase(String name) {
046: super (name);
047: }
048:
049: protected void setUp() throws Exception {
050: InitialContext ctx = new InitialContext();
051: Object ref = ctx.lookup("ejbcts/CMPBean");
052: home = (CtsCmpHome) ref;
053: }
054:
055: protected void tearDown() throws Exception {
056: }
057:
058: /**
059: * Method testBasicStatelessSession
060: * @throws Exception
061: */
062: public void testBasicCmp() throws Exception {
063: getLog().debug("+++ testBasicCmp()");
064: AccountPK pk = new AccountPK("testBasicCmp");
065: CtsCmp bean = home.create(pk, "testBasicCmp unitTest");
066: String result = bean.getPersonsName();
067: // Test response
068: assertTrue(result.equals("testBasicCmp unitTest"));
069: bean.remove();
070: }
071:
072: /** Test of accessing the home interface from the remote interface in an env
073: * new InitialContext() will not work.
074: * @throws Exception
075: */
076: public void testHomeFromRemoteNoDefaultJNDI() throws Exception {
077: getLog().debug("+++ testHomeFromRemoteNoDefaultJNDI()");
078:
079: // Override the JNDI variables in the System properties
080: Properties sysProps = System.getProperties();
081: Properties newProps = new Properties(sysProps);
082: newProps.setProperty("java.naming.factory.initial",
083: "badFactory");
084: newProps.setProperty("java.naming.provider.url",
085: "jnp://badhost:12345");
086: System.setProperties(newProps);
087:
088: // Do a lookup of the home and create a remote using a custom env
089: Properties env = new Properties();
090: env.setProperty("java.naming.factory.initial", super
091: .getJndiInitFactory());
092: env.setProperty("java.naming.provider.url", super .getJndiURL());
093: try {
094: InitialContext ctx = new InitialContext(env);
095: Object ref = ctx.lookup("ejbcts/CMPBean");
096: CtsCmpHome home = (CtsCmpHome) PortableRemoteObject.narrow(
097: ref, CtsCmpHome.class);
098: AccountPK pk1 = new AccountPK("bean1");
099: CtsCmp bean1 = home.create(pk1,
100: "testHomeFromRemoteNoDefaultJNDI");
101: CtsCmpHome home2 = (CtsCmpHome) bean1.getEJBHome();
102: AccountPK pk2 = new AccountPK("bean2");
103: CtsCmp bean2 = home2.create(pk2,
104: "testHomeFromRemoteNoDefaultJNDI");
105: bean2.remove();
106: } finally {
107: System.setProperties(sysProps);
108: }
109: }
110:
111: public static Test suite() throws Exception {
112: return getDeploySetup(CmpUnitTestCase.class, "cts.jar");
113: }
114:
115: }
|