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.ejb3.test.factoryxml.unit;
023:
024: import org.jboss.ejb3.test.factoryxml.Entity1;
025: import org.jboss.ejb3.test.factoryxml.Entity2;
026: import org.jboss.ejb3.test.factoryxml.MyService;
027: import org.jboss.ejb3.test.factoryxml.Session1;
028: import org.jboss.ejb3.test.factoryxml.Session2;
029: import org.jboss.ejb3.test.factoryxml.Stateful1;
030: import org.jboss.ejb3.test.factoryxml.Util;
031: import org.jboss.test.JBossTestCase;
032: import junit.framework.Test;
033:
034: /**
035: * Sample client for the jboss container.
036: *
037: * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
038: * @version $Id: FactoryUnitTestCase.java 60233 2007-02-03 10:13:23Z wolfc $
039: */
040:
041: public class FactoryUnitTestCase extends JBossTestCase {
042: org.apache.log4j.Logger log = getLog();
043:
044: static boolean deployed = false;
045: static int test = 0;
046:
047: public FactoryUnitTestCase(String name) {
048:
049: super (name);
050:
051: }
052:
053: public void testMe() throws Exception {
054: Session1 session1 = (Session1) this .getInitialContext().lookup(
055: "factoryxml-test/Session1Bean/remote");
056: Session2 session2 = (Session2) this .getInitialContext().lookup(
057: "factoryxml-test/Session2Bean/remote");
058: MyService service = (MyService) this .getInitialContext()
059: .lookup("factoryxml-test/MyServiceBean/remote");
060: assertNotNull(service);
061:
062: int oneF = session1.create1FromFactory();
063: int oneM = session1.create1FromManager();
064: int twoF = session1.create2FromFactory();
065: int twoM = session1.create2FromManager();
066: session1.doUtil(new Util());
067:
068: session2.find1FromFactory(oneF);
069: assertNotNull(session2.find1FromManager(oneM));
070: session2.find2FromFactory(twoF);
071: assertNotNull(session2.find2FromManager(twoM));
072: assertNotNull(service.find2FromManager(twoM));
073: assertNotNull(session2.findUtil1FromManager(1));
074: assertNotNull(session2.findUtil2FromManager(2));
075:
076: }
077:
078: public void testExtended() throws Exception {
079: Stateful1 stateful1 = (Stateful1) this .getInitialContext()
080: .lookup("factoryxml-test/Stateful1Bean/remote");
081: Session2 session2 = (Session2) this .getInitialContext().lookup(
082: "factoryxml-test/Session2Bean/remote");
083:
084: int oneId = stateful1.create1();
085: int twoId = stateful1.create2();
086:
087: stateful1.update1();
088: stateful1.update2();
089:
090: {
091: Entity1 one = session2.find1FromManager(oneId);
092: assertEquals(one.getString(), "changed");
093:
094: Entity2 two = session2.find2FromManager(twoId);
095: assertEquals(two.getString(), "changed");
096: }
097:
098: stateful1.never();
099:
100: {
101: Entity1 one = session2.find1FromManager(oneId);
102: assertEquals(one.getString(), "changed");
103:
104: Entity2 two = session2.find2FromManager(twoId);
105: assertEquals(two.getString(), "changed");
106: }
107:
108: stateful1.checkout();
109:
110: {
111: Entity1 one = session2.find1FromManager(oneId);
112: assertEquals(one.getString(), "never");
113:
114: Entity2 two = session2.find2FromManager(twoId);
115: assertEquals(two.getString(), "never");
116: }
117: }
118:
119: public static Test suite() throws Exception {
120: return getDeploySetup(FactoryUnitTestCase.class,
121: "factoryxml-test.ear");
122: }
123:
124: }
|