1 package org.apache.ojb.ejb.pb; 2 3 17 18 import javax.ejb.EJBHome ; 19 import javax.rmi.PortableRemoteObject ; 20 import java.util.List ; 21 22 import junit.framework.TestCase; 23 import org.apache.ojb.ejb.ContextHelper; 24 import org.apache.ojb.ejb.VOHelper; 25 26 32 public class PersonArticleClient extends TestCase 33 { 34 PersonArticleManagerPBRemote bean; 35 36 public PersonArticleClient(String s) 37 { 38 super(s); 39 } 40 41 public PersonArticleClient() 42 { 43 super(PersonArticleClient.class.getName()); 44 } 45 46 public static void main(String [] args) 47 { 48 String [] arr = {PersonArticleClient.class.getName()}; 49 junit.textui.TestRunner.main(arr); 50 } 51 52 public void testNestedBrokerStore() throws Exception 53 { 54 int personsBefore = bean.personCount(); 55 int articlesBefore = bean.articleCount(); 56 57 List articleList = VOHelper.createNewArticleList(6); 58 List personList = VOHelper.createNewPersonList(4); 59 bean.storeUsingNestedPB(articleList, personList); 60 61 int personsAfterStore = bean.personCount(); 62 int articlesAfterStore = bean.articleCount(); 63 assertEquals("wrong number of articles after store", articlesBefore + 6, articlesAfterStore); 64 assertEquals("wrong number of persons after store", personsBefore + 4, personsAfterStore); 65 } 66 67 public void testNestedBeans() throws Exception 68 { 69 int personsBefore = bean.personCount(); 70 int articlesBefore = bean.articleCount(); 71 72 List articleList = VOHelper.createNewArticleList(6); 73 List personList = VOHelper.createNewPersonList(4); 74 bean.storeUsingSubBeans(articleList, personList); 76 77 int personsAfterStore = bean.personCount(); 78 int articlesAfterStore = bean.articleCount(); 79 assertEquals("wrong number of articles after store", articlesBefore + 6, articlesAfterStore); 80 assertEquals("wrong number of persons after store", personsBefore + 4, personsAfterStore); 81 } 82 83 public void testNestedStoreDelete() throws Exception 84 { 85 int personsBefore = bean.personCount(); 86 int articlesBefore = bean.articleCount(); 87 88 List articleList = VOHelper.createNewArticleList(6); 89 List personList = VOHelper.createNewPersonList(4); 90 articleList = bean.storeArticles(articleList); 92 personList = bean.storePersons(personList); 93 94 int personsAfterStore = bean.personCount(); 95 int articlesAfterStore = bean.articleCount(); 96 assertEquals("wrong number of articles after store", articlesBefore + 6, articlesAfterStore); 97 assertEquals("wrong number of persons after store", personsBefore + 4, personsAfterStore); 98 99 bean.deleteArticles(articleList); 101 bean.deletePersons(personList); 102 103 int personsAfterDelete = bean.personCount(); 104 int articlesAfterDelete = bean.articleCount(); 105 assertEquals("wrong number of articles after delete", articlesBefore, articlesAfterDelete); 106 assertEquals("wrong number of persons after delete", personsBefore, personsAfterDelete); 107 } 108 109 public void testStoreDelete() throws Exception 110 { 111 int count = 100; 112 int articlesBefore = bean.articleCount(); 113 114 List articleList = VOHelper.createNewArticleList(count); 115 articleList = bean.storeArticlesIntricately(articleList); 117 118 int articlesAfterStore = bean.articleCount(); 119 assertEquals("wrong number of articles after store", articlesBefore + count, articlesAfterStore); 120 121 bean.deleteArticlesIntricately(articleList); 123 124 int articlesAfterDelete = bean.articleCount(); 125 assertEquals("wrong number of articles after delete", articlesBefore, articlesAfterDelete); 126 } 127 128 protected void setUp() throws Exception 129 { 130 super.setUp(); 131 init(); 132 } 133 134 protected void init() throws Exception 135 { 136 try 137 { 138 Object object = PortableRemoteObject.narrow( 139 ContextHelper.getContext().lookup(PersonArticleManagerPBHome.JNDI_NAME), EJBHome .class); 140 bean = (PersonArticleManagerPBRemote) ((PersonArticleManagerPBHome) object).create(); 141 System.out.println("Bean found: " + bean); 142 } 143 catch (Exception e) 144 { 145 e.printStackTrace(); 146 throw e; 147 } 148 } 149 150 } 151 | Popular Tags |