01: package org.apache.ojb.ejb.odmg;
02:
03: /* Copyright 2004-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * 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;
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: /**
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: PersonArticleManagerODMGRemote bean;
34:
35: public PersonArticleClientODMG(String s) {
36: super (s);
37: }
38:
39: public PersonArticleClientODMG() {
40: super (PersonArticleClientODMG.class.getName());
41: }
42:
43: public static void main(String[] args) {
44: String[] arr = { PersonArticleClientODMG.class.getName() };
45: junit.textui.TestRunner.main(arr);
46: }
47:
48: protected void setUp() throws Exception {
49: super .setUp();
50: init();
51: }
52:
53: protected void init() throws Exception {
54: try {
55: Object object = PortableRemoteObject.narrow(ContextHelper
56: .getContext().lookup(
57: PersonArticleManagerODMGHome.JNDI_NAME),
58: EJBHome.class);
59: bean = ((PersonArticleManagerODMGHome) object).create();
60: } catch (Exception e) {
61: e.printStackTrace();
62: throw e;
63: }
64: }
65:
66: public void testNestedStoreDelete() throws Exception {
67: int personsBefore = bean.personCount();
68: int articlesBefore = bean.articleCount();
69:
70: List articleList = VOHelper.createNewArticleList(6);
71: List personList = VOHelper.createNewPersonList(4);
72: // storing objects
73: articleList = bean.storeArticles(articleList);
74: personList = bean.storePersons(personList);
75:
76: int personsAfterStore = bean.personCount();
77: int articlesAfterStore = bean.articleCount();
78: assertEquals("wrong number of articles after store",
79: articlesBefore + 6, articlesAfterStore);
80: assertEquals("wrong number of persons after store",
81: personsBefore + 4, personsAfterStore);
82:
83: //delete objects
84: bean.deleteArticles(articleList);
85: bean.deletePersons(personList);
86:
87: int personsAfterDelete = bean.personCount();
88: int articlesAfterDelete = bean.articleCount();
89: assertEquals("wrong number of articles after delete",
90: articlesBefore, articlesAfterDelete);
91: assertEquals("wrong number of persons after delete",
92: personsBefore, personsAfterDelete);
93: }
94: }
|