01: /**
02: * Copyright (C) 2001-2004 France Telecom R&D
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */package org.objectweb.speedo.runtime.collection;
18:
19: import org.objectweb.speedo.SpeedoTestHelper;
20: import org.objectweb.speedo.api.ExceptionHelper;
21: import org.objectweb.speedo.pobjects.collection.Ref2AMMB;
22: import org.objectweb.speedo.pobjects.collection.Ref2Ref2AMMB;
23: import org.objectweb.speedo.pobjects.collection.AMMB;
24: import org.objectweb.speedo.pobjects.collection.BMMB;
25: import org.objectweb.speedo.pobjects.collection.AllCollection;
26: import org.objectweb.util.monolog.api.BasicLevel;
27:
28: import javax.jdo.PersistenceManager;
29: import javax.jdo.Query;
30: import javax.jdo.JDOException;
31: import java.util.Collection;
32: import java.util.Iterator;
33:
34: import junit.framework.Assert;
35:
36: /**
37: *
38: * @author S.Chassande-Barrioz
39: */
40: public class PORemover extends SpeedoTestHelper {
41:
42: public PORemover(String name) {
43: super (name);
44: }
45:
46: protected String getLoggerName() {
47: return LOG_NAME + ".rt.query";
48: }
49:
50: public void testRemovingOfPersistentObject() {
51: PersistenceManager pm = pmf.getPersistenceManager();
52: try {
53: Class[] cs = new Class[] { AllCollection.class,
54: Ref2AMMB.class, Ref2Ref2AMMB.class, AMMB.class,
55: BMMB.class };
56: for (int i = 0; i < cs.length; i++) {
57: Query query = pm.newQuery(cs[i]);
58: Collection col = (Collection) query.execute();
59: Iterator it = col.iterator();
60: while (it.hasNext()) {
61: Object o = it.next();
62: Assert.assertNotNull(
63: "null object in the query result"
64: + cs[i].getName(), o);
65: if (o instanceof AMMB) {
66: AMMB a = (AMMB) o;
67: a.getBs().clear();
68: }
69: pm.currentTransaction().begin();
70: pm.deletePersistent(o);
71: pm.currentTransaction().commit();
72: }
73:
74: query.close(col);
75:
76: }
77: } catch (JDOException e) {
78: Exception ie = ExceptionHelper.getNested(e);
79: logger.log(BasicLevel.ERROR, "", ie);
80: fail(ie.getMessage());
81: } finally {
82: pm.close();
83: }
84: }
85: }
|