KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > ejb > odmg > PersonArticleClientODMG


1 package org.apache.ojb.ejb.odmg;
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.odmg.PersonArticleManagerODMGBean}
28  *
29  * @author <a HREF="mailto:armin@codeAuLait.de">Armin Waibel</a>
30  * @version $Id: PersonArticleClientODMG.java,v 1.4.2.2 2005/12/21 22:21:39 tomdz Exp $
31  */

32 public class PersonArticleClientODMG extends TestCase
33 {
34     PersonArticleManagerODMGRemote bean;
35
36     public PersonArticleClientODMG(String JavaDoc s)
37     {
38         super(s);
39     }
40
41     public PersonArticleClientODMG()
42     {
43         super(PersonArticleClientODMG.class.getName());
44     }
45
46     public static void main(String JavaDoc[] args)
47     {
48         String JavaDoc[] arr = {PersonArticleClientODMG.class.getName()};
49         junit.textui.TestRunner.main(arr);
50     }
51
52     protected void setUp() throws Exception JavaDoc
53     {
54         super.setUp();
55         init();
56     }
57
58     protected void init() throws Exception JavaDoc
59     {
60         try
61         {
62             Object JavaDoc object = PortableRemoteObject.narrow(
63             ContextHelper.getContext().lookup(PersonArticleManagerODMGHome.JNDI_NAME), EJBHome JavaDoc.class);
64             bean = ((PersonArticleManagerODMGHome) object).create();
65         }
66         catch (Exception JavaDoc e)
67         {
68             e.printStackTrace();
69             throw e;
70         }
71     }
72
73     public void testNestedStoreDelete() throws Exception JavaDoc
74     {
75         int personsBefore = bean.personCount();
76         int articlesBefore = bean.articleCount();
77
78         List JavaDoc articleList = VOHelper.createNewArticleList(6);
79         List JavaDoc personList = VOHelper.createNewPersonList(4);
80         // storing objects
81
articleList = bean.storeArticles(articleList);
82         personList = bean.storePersons(personList);
83
84         int personsAfterStore = bean.personCount();
85         int articlesAfterStore = bean.articleCount();
86         assertEquals("wrong number of articles after store", articlesBefore + 6, articlesAfterStore);
87         assertEquals("wrong number of persons after store", personsBefore + 4, personsAfterStore);
88
89         //delete objects
90
bean.deleteArticles(articleList);
91         bean.deletePersons(personList);
92
93         int personsAfterDelete = bean.personCount();
94         int articlesAfterDelete = bean.articleCount();
95         assertEquals("wrong number of articles after delete", articlesBefore, articlesAfterDelete);
96         assertEquals("wrong number of persons after delete", personsBefore, personsAfterDelete);
97     }
98 }
99
Popular Tags