1 package org.apache.ojb.ejb.odmg; 2 3 17 18 import javax.ejb.EJBHome ; 19 import javax.naming.Context ; 20 import javax.rmi.PortableRemoteObject ; 21 import java.rmi.RemoteException ; 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 27 import junit.framework.TestCase; 28 import org.apache.ojb.ejb.ArticleVO; 29 import org.apache.ojb.ejb.ContextHelper; 30 import org.apache.ojb.ejb.VOHelper; 31 32 38 public class ODMGClient extends TestCase 39 { 40 ODMGSessionRemote sampleBean; 41 static int loops = 500; 42 43 public ODMGClient(String s) 44 { 45 super(s); 46 } 47 48 public ODMGClient() 49 { 50 super(ODMGClient.class.getName()); 51 } 52 53 public static void main(String [] args) 54 { 55 loops = args.length > 0 ? new Integer (args[0]).intValue(): 500; 56 junit.textui.TestRunner.main(new String [] {ODMGClient.class.getName()}); 57 } 58 59 protected void setUp() throws Exception 60 { 61 super.setUp(); 62 init(); 63 } 64 65 protected void tearDown() throws Exception 66 { 67 super.tearDown(); 68 } 69 70 protected void init() 71 { 72 Context ctx = ContextHelper.getContext(); 73 try 74 { 75 Object object = PortableRemoteObject.narrow(ctx.lookup(ODMGSessionHome.JNDI_NAME), EJBHome .class); 76 sampleBean = ((ODMGSessionHome) object).create(); 77 } 78 catch (Exception e) 79 { 80 e.printStackTrace(); 81 } 82 } 83 84 public void testInsertDelete() throws RemoteException 85 { 86 System.out.println("# test: testInsertDelete()"); 87 int articlesBefore = sampleBean.getArticleCount(); 88 int personsBefore = sampleBean.getPersonCount(); 89 90 List articles = VOHelper.createNewArticleList(10); 91 List persons = VOHelper.createNewPersonList(5); 92 articles = sampleBean.storeObjects(articles); 93 persons = sampleBean.storeObjects(persons); 94 95 int articlesAfterStore = sampleBean.getArticleCount(); 96 int personsAfterStore = sampleBean.getPersonCount(); 97 assertEquals("Storing of articles failed", articlesBefore + 10, articlesAfterStore); 98 assertEquals("Storing of persons faile", personsBefore + 5, personsAfterStore); 99 100 101 sampleBean.deleteObjects(articles); 102 sampleBean.deleteObjects(persons); 103 104 int articlesAfterDelete = sampleBean.getArticleCount(); 105 int personsAfterDelete = sampleBean.getPersonCount(); 106 assertEquals("Deleting of articles failed", articlesAfterStore - 10, articlesAfterDelete); 107 assertEquals("Deleting of persons failed", personsAfterStore - 5, personsAfterDelete); 108 } 109 110 public void testStress() throws Exception 111 { 112 System.out.println("## ODMG-api testStress"); 113 System.out.println("Stress test will be done with " + loops + " loops"); 114 System.out.println("# Store #"); 115 for (int i = 0; i < loops; i++) 116 { 117 sampleBean.storeObjects(VOHelper.createNewArticleList(1)); 118 if(i%10==0)System.out.print("."); 119 if(i%400==0)System.out.println(); 120 } 121 Collection col = sampleBean.getAllObjects(ArticleVO.class); 122 System.out.println("\n# Delete #"); 123 int i =0; 124 for (Iterator iterator = col.iterator(); iterator.hasNext();) 125 { 126 ArticleVO article = (ArticleVO) iterator.next(); 127 List del = new ArrayList (); 128 del.add(article); 129 sampleBean.deleteObjects(del); 130 if(++i%10==0)System.out.print("."); 131 if(i%400==0)System.out.println(); 132 } 133 System.out.println(""); 134 System.out.println("## ODMG-api testStress END ##"); 135 } 136 137 public void testServerSideMethods() throws RemoteException 138 { 139 System.out.println("## testServerSideMethods"); 140 boolean result = sampleBean.allInOne(VOHelper.createNewArticleList(10), VOHelper.createNewPersonList(5)); 141 assertTrue("Something happened on sever side test method - 'allInOne(...)'", result); 142 } 143 } 144 | Popular Tags |