KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > runtime > collection > TestMMB


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * 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  */

18 package org.objectweb.speedo.runtime.collection;
19
20 import org.objectweb.speedo.SpeedoTestHelper;
21 import org.objectweb.speedo.pobjects.collection.AMMB;
22 import org.objectweb.speedo.pobjects.collection.BMMB;
23
24 import javax.jdo.PersistenceManager;
25 import java.util.Collection JavaDoc;
26 import java.util.ArrayList JavaDoc;
27
28 import junit.framework.Assert;
29
30
31 /**
32  *
33  * @author S.Chassande-Barrioz
34  */

35 public class TestMMB extends SpeedoTestHelper {
36
37     public TestMMB(String JavaDoc s) {
38         super(s);
39     }
40
41     protected String JavaDoc getLoggerName() {
42         return LOG_NAME + ".rt.collection.TestMMB";
43     }
44
45     public void test1() {
46         AMMB[] as = new AMMB[3];
47         BMMB[] bs = new BMMB[3];
48         for(int i=0; i<as.length; i++) {
49             as[i] = new AMMB(i);
50             bs[i] = new BMMB(i);
51         }
52         Collection JavaDoc as0 = new ArrayList JavaDoc(2);
53         as0.add(bs[0]);
54         as0.add(bs[1]);
55         as[0].setBs(as0);
56         Collection JavaDoc as1 = new ArrayList JavaDoc(3);
57         as1.add(bs[0]);
58         as1.add(bs[1]);
59         as1.add(bs[2]);
60         as[1].setBs(as1);
61         Collection JavaDoc as2 = new ArrayList JavaDoc(2);
62         as2.add(bs[1]);
63         as2.add(bs[2]);
64         as[2].setBs(as2);
65
66         Collection JavaDoc bs0 = new ArrayList JavaDoc(2);
67         bs0.add(as[0]);
68         bs0.add(as[1]);
69         bs[0].setAs(bs0);
70         Collection JavaDoc bs1 = new ArrayList JavaDoc(3);
71         bs1.add(as[0]);
72         bs1.add(as[1]);
73         bs1.add(as[2]);
74         bs[1].setAs(bs1);
75         Collection JavaDoc bs2 = new ArrayList JavaDoc(2);
76         bs2.add(as[1]);
77         bs2.add(as[2]);
78         bs[2].setAs(bs2);
79
80         PersistenceManager pm = pmf.getPersistenceManager();
81         pm.currentTransaction().begin();
82         pm.makePersistent(as[0]);
83         pm.currentTransaction().commit();
84         Object JavaDoc[] a_ids = new Object JavaDoc[3];
85         Object JavaDoc[] b_ids = new Object JavaDoc[3];
86         for(int i=0; i<as.length; i++) {
87             a_ids[i] = pm.getObjectId(as[i]);
88             b_ids[i] = pm.getObjectId(bs[i]);
89         }
90         as = null;
91         bs = null;
92         pm.close();
93
94         pm = pmf.getPersistenceManager();
95         for(int i=0; i<a_ids.length; i++) {
96             Object JavaDoc o = pm.getObjectById(a_ids[i], true);
97             Assert.assertNotNull(o);
98             pm.currentTransaction().begin();
99             pm.deletePersistent(o);
100             o = pm.getObjectById(b_ids[i], true);
101             Assert.assertNotNull(o);
102             pm.deletePersistent(o);
103             pm.currentTransaction().commit();
104         }
105         pm.close();
106     }
107 }
108
Popular Tags