1 22 package org.jboss.test.cts.test; 23 24 import java.util.Properties ; 25 import javax.naming.Context ; 26 import javax.naming.InitialContext ; 27 import javax.transaction.UserTransaction ; 28 29 import junit.framework.Test; 30 31 import org.jboss.test.JBossTestCase; 32 import org.jboss.test.cts.interfaces.CtsCmpHome; 33 import org.jboss.test.cts.interfaces.CtsCmp; 34 import org.jboss.test.cts.keys.AccountPK; 35 36 41 public class UserTransactionLookupTestCase extends JBossTestCase 42 { 43 44 public UserTransactionLookupTestCase(String name) 45 { 46 super(name); 47 } 48 49 56 public void testWithInvalidDefaultJndiContext() throws Exception 57 { 58 System.setProperty(Context.PROVIDER_URL, "localhost:65535"); 59 Properties env = new Properties (System.getProperties()); 60 env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.NamingContextFactory"); 61 env.setProperty(Context.PROVIDER_URL, "localhost:1099"); 62 env.setProperty("jnp.disableDiscovery", "true"); 63 InitialContext ctx = new InitialContext (env); 64 UserTransaction ut = (UserTransaction ) ctx.lookup("UserTransaction"); 65 ut.getStatus(); 66 67 ut.begin(); 68 CtsCmpHome home = (CtsCmpHome) ctx.lookup("ejbcts/CMPBean"); 69 AccountPK pk = new AccountPK("testWithInvalidDefaultJndiContext"); 70 CtsCmp bean = home.create(pk, "Scott"); 71 bean.setPersonsAge(40); 72 ut.commit(); 73 74 assertTrue("age == 40", bean.getPersonsAge() == 40); 75 76 ut.begin(); 77 bean.setPersonsAge(100); 78 ut.rollback(); 79 assertTrue("age == 40", bean.getPersonsAge() == 40); 80 81 bean.remove(); 82 ctx.close(); 83 } 84 85 public void testWithDefaultJndiContext() throws Exception 86 { 87 log.info("+++ testWithDefaultJndiContext"); 88 System.setProperty(Context.PROVIDER_URL, "localhost:1099"); 89 InitialContext ctx = new InitialContext (); 90 UserTransaction ut = (UserTransaction ) ctx.lookup("UserTransaction"); 91 ut.getStatus(); 92 93 ut.begin(); 94 CtsCmpHome home = (CtsCmpHome) ctx.lookup("ejbcts/CMPBean"); 95 AccountPK pk = new AccountPK("testWithDefaultJndiContext"); 96 CtsCmp bean = home.create(pk, "Scott"); 97 bean.setPersonsAge(40); 98 ut.commit(); 99 100 assertTrue("age == 40", bean.getPersonsAge() == 40); 101 102 ut.begin(); 103 bean.setPersonsAge(100); 104 ut.rollback(); 105 assertTrue("age == 40", bean.getPersonsAge() == 40); 106 107 bean.remove(); 108 ctx.close(); 109 } 110 111 public static Test suite() throws Exception 112 { 113 return getDeploySetup(UserTransactionLookupTestCase.class, "cts.jar"); 114 } 115 116 } 117 | Popular Tags |