1 22 package org.jboss.test.cache.test.aop; 23 24 import junit.framework.Test; 25 import junit.framework.TestSuite; 26 import org.jboss.test.JBossTestCase; 27 import org.jboss.test.cache.bean.TreeCacheAopMBeanTester; 28 import org.jboss.test.cache.bean.TreeCacheAopMBeanTesterHome; 29 30 import javax.naming.Context ; 31 import javax.naming.InitialContext ; 32 import javax.rmi.PortableRemoteObject ; 33 import javax.transaction.UserTransaction ; 34 import java.util.Properties ; 35 36 41 public class MBeanUnitTestCase extends JBossTestCase 42 { 43 TreeCacheAopMBeanTesterHome cache_home; 44 TreeCacheAopMBeanTester cache1 = null, cache2 = null; 45 Properties p_ = new Properties (); 46 47 48 public MBeanUnitTestCase(String name) 49 { 50 super(name); 51 } 52 53 public void setUp() throws Exception 54 { 55 super.setUp(); 56 mySetup(); 57 } 58 59 public void tearDown() throws Exception 60 { 61 if (cache2 != null) 62 cache2.remove(); if (cache1 != null) 64 cache1.remove(); 65 } 66 67 public void mySetup() throws Exception 68 { 69 Object obj; 70 71 p_.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); 72 p_.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces"); 73 p_.put(Context.PROVIDER_URL, "localhost:1099"); 74 obj = new InitialContext (p_).lookup(TreeCacheAopMBeanTesterHome.JNDI_NAME); 75 cache_home = (TreeCacheAopMBeanTesterHome) PortableRemoteObject.narrow(obj, TreeCacheAopMBeanTesterHome.class); 76 } 77 78 79 public void testSetup() 80 { 81 assertNotNull("TreeCacheAopTesterHome ", cache_home); 82 } 83 84 public void testPutObjectTx() 85 { 86 UserTransaction tx = null; 87 88 try { 89 tx = (UserTransaction ) new InitialContext (p_).lookup("UserTransaction"); 90 assertNotNull("UserTransaction should not be null ", tx); 91 cache1 = cache_home.create(); 94 95 log("Create person ..."); 97 cache1.createPerson("/aop/person", "Benito", 38); 98 100 log("check equalityu ..."); 102 assertEquals(38, cache1.getAge("/aop/person")); 103 105 } catch (Throwable t) { 106 fail(t.toString()); 107 try { 108 tx.rollback(); 109 } catch (Throwable t2) { 110 ; 111 } 112 fail(t.toString()); 113 } 114 } 115 116 117 void _sleep(long timeout) 118 { 119 try { 120 Thread.sleep(timeout); 121 } catch (InterruptedException e) { 122 } 123 } 124 125 void log(String msg) 126 { 127 getLog().info("-- [" + Thread.currentThread() + "]: " + msg); 128 } 129 130 131 public static Test suite() throws Exception 132 { 133 return getDeploySetup(getDeploySetup(MBeanUnitTestCase.class, "cachetest.jar"), 137 "cacheAoptest.sar"); 138 } 140 141 public static void main(String [] args) throws Exception 142 { 143 junit.textui.TestRunner.run(suite()); 144 } 145 146 147 } 148 | Popular Tags |