001: package org.apache.ojb.ejb.odmg;
002:
003: /* Copyright 2004-2005 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: import javax.ejb.EJBHome;
019: import javax.naming.Context;
020: import javax.rmi.PortableRemoteObject;
021: import java.rmi.RemoteException;
022: import java.util.ArrayList;
023: import java.util.Collection;
024: import java.util.Iterator;
025: import java.util.List;
026:
027: import junit.framework.TestCase;
028: import org.apache.ojb.ejb.ArticleVO;
029: import org.apache.ojb.ejb.ContextHelper;
030: import org.apache.ojb.ejb.VOHelper;
031:
032: /**
033: * Test client using the {@link org.apache.ojb.ejb.odmg.ODMGSessionBean}.
034: *
035: * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
036: * @version $Id: ODMGClient.java,v 1.4.2.2 2005/12/21 22:21:39 tomdz Exp $
037: */
038: public class ODMGClient extends TestCase {
039: ODMGSessionRemote sampleBean;
040: static int loops = 500;
041:
042: public ODMGClient(String s) {
043: super (s);
044: }
045:
046: public ODMGClient() {
047: super (ODMGClient.class.getName());
048: }
049:
050: public static void main(String[] args) {
051: loops = args.length > 0 ? new Integer(args[0]).intValue() : 500;
052: junit.textui.TestRunner.main(new String[] { ODMGClient.class
053: .getName() });
054: }
055:
056: protected void setUp() throws Exception {
057: super .setUp();
058: init();
059: }
060:
061: protected void tearDown() throws Exception {
062: super .tearDown();
063: }
064:
065: protected void init() {
066: Context ctx = ContextHelper.getContext();
067: try {
068: Object object = PortableRemoteObject.narrow(ctx
069: .lookup(ODMGSessionHome.JNDI_NAME), EJBHome.class);
070: sampleBean = ((ODMGSessionHome) object).create();
071: } catch (Exception e) {
072: e.printStackTrace();
073: }
074: }
075:
076: public void testInsertDelete() throws RemoteException {
077: System.out.println("# test: testInsertDelete()");
078: int articlesBefore = sampleBean.getArticleCount();
079: int personsBefore = sampleBean.getPersonCount();
080:
081: List articles = VOHelper.createNewArticleList(10);
082: List persons = VOHelper.createNewPersonList(5);
083: articles = sampleBean.storeObjects(articles);
084: persons = sampleBean.storeObjects(persons);
085:
086: int articlesAfterStore = sampleBean.getArticleCount();
087: int personsAfterStore = sampleBean.getPersonCount();
088: assertEquals("Storing of articles failed", articlesBefore + 10,
089: articlesAfterStore);
090: assertEquals("Storing of persons faile", personsBefore + 5,
091: personsAfterStore);
092:
093: sampleBean.deleteObjects(articles);
094: sampleBean.deleteObjects(persons);
095:
096: int articlesAfterDelete = sampleBean.getArticleCount();
097: int personsAfterDelete = sampleBean.getPersonCount();
098: assertEquals("Deleting of articles failed",
099: articlesAfterStore - 10, articlesAfterDelete);
100: assertEquals("Deleting of persons failed",
101: personsAfterStore - 5, personsAfterDelete);
102: }
103:
104: public void testStress() throws Exception {
105: System.out.println("## ODMG-api testStress");
106: System.out.println("Stress test will be done with " + loops
107: + " loops");
108: System.out.println("# Store #");
109: for (int i = 0; i < loops; i++) {
110: sampleBean.storeObjects(VOHelper.createNewArticleList(1));
111: if (i % 10 == 0)
112: System.out.print(".");
113: if (i % 400 == 0)
114: System.out.println();
115: }
116: Collection col = sampleBean.getAllObjects(ArticleVO.class);
117: System.out.println("\n# Delete #");
118: int i = 0;
119: for (Iterator iterator = col.iterator(); iterator.hasNext();) {
120: ArticleVO article = (ArticleVO) iterator.next();
121: List del = new ArrayList();
122: del.add(article);
123: sampleBean.deleteObjects(del);
124: if (++i % 10 == 0)
125: System.out.print(".");
126: if (i % 400 == 0)
127: System.out.println();
128: }
129: System.out.println("");
130: System.out.println("## ODMG-api testStress END ##");
131: }
132:
133: public void testServerSideMethods() throws RemoteException {
134: System.out.println("## testServerSideMethods");
135: boolean result = sampleBean.allInOne(VOHelper
136: .createNewArticleList(10), VOHelper
137: .createNewPersonList(5));
138: assertTrue(
139: "Something happened on sever side test method - 'allInOne(...)'",
140: result);
141: }
142: }
|