001: /**
002: * Copyright (C) 2001-2004 France Telecom R&D
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package org.objectweb.speedo.runtime.collection;
018:
019: import org.objectweb.speedo.SpeedoTestHelper;
020: import org.objectweb.speedo.pobjects.collection.AMMB;
021: import org.objectweb.speedo.pobjects.collection.BMMB;
022:
023: import javax.jdo.PersistenceManager;
024: import java.util.Collection;
025: import java.util.ArrayList;
026:
027: import junit.framework.Assert;
028:
029: /**
030: *
031: * @author S.Chassande-Barrioz
032: */
033: public class TestMMB extends SpeedoTestHelper {
034:
035: public TestMMB(String s) {
036: super (s);
037: }
038:
039: protected String getLoggerName() {
040: return LOG_NAME + ".rt.collection.TestMMB";
041: }
042:
043: public void test1() {
044: AMMB[] as = new AMMB[3];
045: BMMB[] bs = new BMMB[3];
046: for (int i = 0; i < as.length; i++) {
047: as[i] = new AMMB(i);
048: bs[i] = new BMMB(i);
049: }
050: Collection as0 = new ArrayList(2);
051: as0.add(bs[0]);
052: as0.add(bs[1]);
053: as[0].setBs(as0);
054: Collection as1 = new ArrayList(3);
055: as1.add(bs[0]);
056: as1.add(bs[1]);
057: as1.add(bs[2]);
058: as[1].setBs(as1);
059: Collection as2 = new ArrayList(2);
060: as2.add(bs[1]);
061: as2.add(bs[2]);
062: as[2].setBs(as2);
063:
064: Collection bs0 = new ArrayList(2);
065: bs0.add(as[0]);
066: bs0.add(as[1]);
067: bs[0].setAs(bs0);
068: Collection bs1 = new ArrayList(3);
069: bs1.add(as[0]);
070: bs1.add(as[1]);
071: bs1.add(as[2]);
072: bs[1].setAs(bs1);
073: Collection bs2 = new ArrayList(2);
074: bs2.add(as[1]);
075: bs2.add(as[2]);
076: bs[2].setAs(bs2);
077:
078: PersistenceManager pm = pmf.getPersistenceManager();
079: pm.currentTransaction().begin();
080: pm.makePersistent(as[0]);
081: pm.currentTransaction().commit();
082: Object[] a_ids = new Object[3];
083: Object[] b_ids = new Object[3];
084: for (int i = 0; i < as.length; i++) {
085: a_ids[i] = pm.getObjectId(as[i]);
086: b_ids[i] = pm.getObjectId(bs[i]);
087: }
088: as = null;
089: bs = null;
090: pm.close();
091:
092: pm = pmf.getPersistenceManager();
093: for (int i = 0; i < a_ids.length; i++) {
094: Object o = pm.getObjectById(a_ids[i], true);
095: Assert.assertNotNull(o);
096: pm.currentTransaction().begin();
097: pm.deletePersistent(o);
098: o = pm.getObjectById(b_ids[i], true);
099: Assert.assertNotNull(o);
100: pm.deletePersistent(o);
101: pm.currentTransaction().commit();
102: }
103: pm.close();
104: }
105: }
|