1 22 package org.jboss.ejb3.test.factory.unit; 23 24 import org.jboss.ejb3.test.factory.Entity1; 25 import org.jboss.ejb3.test.factory.Entity2; 26 import org.jboss.ejb3.test.factory.MyService; 27 import org.jboss.ejb3.test.factory.Session1; 28 import org.jboss.ejb3.test.factory.Session2; 29 import org.jboss.ejb3.test.factory.Stateful1; 30 import org.jboss.ejb3.test.factory.Util; 31 import org.jboss.test.JBossTestCase; 32 import junit.framework.Test; 33 34 40 41 public class FactoryUnitTestCase 42 extends JBossTestCase 43 { 44 org.jboss.logging.Logger log = getLog(); 45 46 static boolean deployed = false; 47 static int test = 0; 48 49 public FactoryUnitTestCase(String name) 50 { 51 52 super(name); 53 54 } 55 56 public void testMe() throws Exception 57 { 58 Session1 session1 = (Session1) this.getInitialContext().lookup("factory-test/Session1Bean/remote"); 59 Session2 session2 = (Session2) this.getInitialContext().lookup("factory-test/Session2Bean/remote"); 60 MyService service = (MyService) this.getInitialContext().lookup("factory-test/MyServiceBean/remote"); 61 62 int oneF = session1.create1FromFactory(); 63 int oneM = session1.create1FromManager(); 64 int twoF = session1.create2FromFactory(); 65 int twoM = session1.create2FromManager(); 66 session1.doUtil(new Util()); 67 68 session2.find1FromFactory(oneF); 69 assertNotNull(session2.find1FromManager(oneM)); 70 session2.find2FromFactory(twoF); 71 assertNotNull(session2.find2FromManager(twoM)); 72 assertNotNull(service.find2FromManager(twoM)); 73 assertNotNull(session2.findUtil1FromManager(1)); 74 assertNotNull(session2.findUtil2FromManager(2)); 75 76 } 77 78 public void testExtended() throws Exception 79 { 80 Stateful1 stateful1 = (Stateful1) this.getInitialContext().lookup("factory-test/Stateful1Bean/remote"); 81 Session2 session2 = (Session2) this.getInitialContext().lookup("factory-test/Session2Bean/remote"); 82 83 int oneId = stateful1.create1(); 84 int twoId = stateful1.create2(); 85 86 stateful1.update1(); 87 stateful1.update2(); 88 89 { 90 Entity1 one = session2.find1FromManager(oneId); 91 assertEquals(one.getString(), "changed"); 92 93 Entity2 two = session2.find2FromManager(twoId); 94 assertEquals(two.getString(), "changed"); 95 } 96 97 stateful1.never(); 98 99 { 100 Entity1 one = session2.find1FromManager(oneId); 101 assertEquals(one.getString(), "changed"); 102 103 Entity2 two = session2.find2FromManager(twoId); 104 assertEquals(two.getString(), "changed"); 105 } 106 107 stateful1.checkout(); 108 109 { 110 Entity1 one = session2.find1FromManager(oneId); 111 assertEquals(one.getString(), "never"); 112 113 Entity2 two = session2.find2FromManager(twoId); 114 assertEquals(two.getString(), "never"); 115 } 116 } 117 118 public void testExtended2() throws Exception 119 { 120 Stateful1 stateful1 = (Stateful1) this.getInitialContext().lookup("factory-test/Stateful1Bean/remote"); 121 Session2 session2 = (Session2) this.getInitialContext().lookup("factory-test/Session2Bean/remote"); 122 123 int oneId = stateful1.create1(); 124 int twoId = stateful1.create2(); 125 126 stateful1.update1(); 127 stateful1.update2(); 128 129 Entity1 one = session2.find1FromManager(oneId); 130 assertEquals(one.getString(), "changed"); 131 132 Entity2 two = session2.find2FromManager(twoId); 133 assertEquals(two.getString(), "changed"); 134 one.setString("never2"); 135 two.setString("never2"); 136 stateful1.never2(one, two); 137 138 { 139 Entity1 uno = session2.find1FromManager(oneId); 140 assertEquals(uno.getString(), "changed"); 141 142 Entity2 dos = session2.find2FromManager(twoId); 143 assertEquals(dos.getString(), "changed"); 144 } 145 146 stateful1.checkout(); 147 148 { 149 Entity1 uno = session2.find1FromManager(oneId); 150 assertEquals(uno.getString(), "never2"); 151 152 Entity2 dos = session2.find2FromManager(twoId); 153 assertEquals(dos.getString(), "never2"); 154 } 155 } 156 157 public static Test suite() throws Exception 158 { 159 return getDeploySetup(FactoryUnitTestCase.class, "factory-test.ear"); 160 } 161 162 } 163 | Popular Tags |