KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > ejb > pb > PersonArticleClient


1 package org.apache.ojb.ejb.pb;
2
3 /* Copyright 2004-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 import javax.ejb.EJBHome JavaDoc;
19 import javax.rmi.PortableRemoteObject JavaDoc;
20 import java.util.List JavaDoc;
21
22 import junit.framework.TestCase;
23 import org.apache.ojb.ejb.ContextHelper;
24 import org.apache.ojb.ejb.VOHelper;
25
26 /**
27  * Test client class using {@link org.apache.ojb.ejb.pb.PersonArticleManagerPBBean}
28  *
29  * @author <a HREF="mailto:armin@codeAuLait.de">Armin Waibel</a>
30  * @version $Id: PersonArticleClient.java,v 1.5.2.3 2005/12/21 22:21:38 tomdz Exp $
31  */

32 public class PersonArticleClient extends TestCase
33 {
34     PersonArticleManagerPBRemote bean;
35
36     public PersonArticleClient(String JavaDoc s)
37     {
38         super(s);
39     }
40
41     public PersonArticleClient()
42     {
43         super(PersonArticleClient.class.getName());
44     }
45
46     public static void main(String JavaDoc[] args)
47     {
48         String JavaDoc[] arr = {PersonArticleClient.class.getName()};
49         junit.textui.TestRunner.main(arr);
50     }
51
52     public void testNestedBrokerStore() throws Exception JavaDoc
53     {
54         int personsBefore = bean.personCount();
55         int articlesBefore = bean.articleCount();
56
57         List JavaDoc articleList = VOHelper.createNewArticleList(6);
58         List JavaDoc 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 JavaDoc
68     {
69         int personsBefore = bean.personCount();
70         int articlesBefore = bean.articleCount();
71
72         List JavaDoc articleList = VOHelper.createNewArticleList(6);
73         List JavaDoc personList = VOHelper.createNewPersonList(4);
74         // storing objects
75
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 JavaDoc
84     {
85         int personsBefore = bean.personCount();
86         int articlesBefore = bean.articleCount();
87
88         List JavaDoc articleList = VOHelper.createNewArticleList(6);
89         List JavaDoc personList = VOHelper.createNewPersonList(4);
90         // storing objects
91
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         //delete objects
100
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 JavaDoc
110     {
111         int count = 100;
112         int articlesBefore = bean.articleCount();
113
114         List JavaDoc articleList = VOHelper.createNewArticleList(count);
115         // storing objects
116
articleList = bean.storeArticlesIntricately(articleList);
117
118         int articlesAfterStore = bean.articleCount();
119         assertEquals("wrong number of articles after store", articlesBefore + count, articlesAfterStore);
120
121         //delete objects
122
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 JavaDoc
129     {
130         super.setUp();
131         init();
132     }
133
134     protected void init() throws Exception JavaDoc
135     {
136         try
137         {
138             Object JavaDoc object = PortableRemoteObject.narrow(
139             ContextHelper.getContext().lookup(PersonArticleManagerPBHome.JNDI_NAME), EJBHome JavaDoc.class);
140             bean = (PersonArticleManagerPBRemote) ((PersonArticleManagerPBHome) object).create();
141             System.out.println("Bean found: " + bean);
142         }
143         catch (Exception JavaDoc e)
144         {
145             e.printStackTrace();
146             throw e;
147         }
148     }
149
150 }
151
Popular Tags