/**
* Copyright (C) 2001-2004 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.objectweb.speedo.runtime.collection;
import org.objectweb.speedo.SpeedoTestHelper;
import org.objectweb.speedo.pobjects.collection.AMMB;
import org.objectweb.speedo.pobjects.collection.BMMB;
import javax.jdo.PersistenceManager;
import java.util.Collection;
import java.util.ArrayList;
import junit.framework.Assert;
/**
*
* @author S.Chassande-Barrioz
*/
public class TestMMB extends SpeedoTestHelper {
public TestMMB(String s) {
super(s);
}
protected String getLoggerName() {
return LOG_NAME + ".rt.collection.TestMMB";
}
public void test1() {
AMMB[] as = new AMMB[3];
BMMB[] bs = new BMMB[3];
for(int i=0; i<as.length; i++) {
as[i] = new AMMB(i);
bs[i] = new BMMB(i);
}
Collection as0 = new ArrayList(2);
as0.add(bs[0]);
as0.add(bs[1]);
as[0].setBs(as0);
Collection as1 = new ArrayList(3);
as1.add(bs[0]);
as1.add(bs[1]);
as1.add(bs[2]);
as[1].setBs(as1);
Collection as2 = new ArrayList(2);
as2.add(bs[1]);
as2.add(bs[2]);
as[2].setBs(as2);
Collection bs0 = new ArrayList(2);
bs0.add(as[0]);
bs0.add(as[1]);
bs[0].setAs(bs0);
Collection bs1 = new ArrayList(3);
bs1.add(as[0]);
bs1.add(as[1]);
bs1.add(as[2]);
bs[1].setAs(bs1);
Collection bs2 = new ArrayList(2);
bs2.add(as[1]);
bs2.add(as[2]);
bs[2].setAs(bs2);
PersistenceManager pm = pmf.getPersistenceManager();
pm.currentTransaction().begin();
pm.makePersistent(as[0]);
pm.currentTransaction().commit();
Object[] a_ids = new Object[3];
Object[] b_ids = new Object[3];
for(int i=0; i<as.length; i++) {
a_ids[i] = pm.getObjectId(as[i]);
b_ids[i] = pm.getObjectId(bs[i]);
}
as = null;
bs = null;
pm.close();
pm = pmf.getPersistenceManager();
for(int i=0; i<a_ids.length; i++) {
Object o = pm.getObjectById(a_ids[i], true);
Assert.assertNotNull(o);
pm.currentTransaction().begin();
pm.deletePersistent(o);
o = pm.getObjectById(b_ids[i], true);
Assert.assertNotNull(o);
pm.deletePersistent(o);
pm.currentTransaction().commit();
}
pm.close();
}
}