KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > runtime > userid > TestGroupama


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.userid;
19
20 import org.objectweb.speedo.SpeedoTestHelper;
21 import org.objectweb.speedo.pobjects.userid.IntervenantHelper;
22 import org.objectweb.speedo.pobjects.userid.ConventionHelper;
23 import org.objectweb.util.monolog.api.BasicLevel;
24
25 import javax.jdo.PersistenceManager;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Calendar JavaDoc;
28
29 /**
30  *
31  * @author S.Chassande-Barrioz
32  */

33 public class TestGroupama extends SpeedoTestHelper {
34
35     public TestGroupama(String JavaDoc s) {
36         super(s);
37     }
38
39     protected String JavaDoc getLoggerName() {
40         return LOG_NAME + "rt.userid.groupama";
41     }
42     public void testA() {
43         try {
44             PersistenceManager pm = pmf.getPersistenceManager();
45             pm.currentTransaction().begin();
46             for(int i=0; i<5; i++) {
47                 IntervenantHelper ih = new IntervenantHelper();
48                 ih.setNomep(i);
49                 ih.setConventions(new ArrayList JavaDoc());
50                 for(int j=0; j<i; j++) {
51                     ConventionHelper ch = new ConventionHelper();
52                     ch.setCdmec("cdmec" + i + "_" + j);
53                     ch.setCdmem("cdmem" + i + "_" + j);
54                     ch.setCdmed("cdmed" + i + "_" + j);
55                     ch.setNomep(i);
56                     ch.setIntervenant(ih);
57                     ch.setDdmec(Calendar.getInstance().getTime());
58                     ch.setCdmese("cdmese" + i + "_" + j);
59                     ih.getConventions().add(ch);
60                 }
61                 pm.makePersistent(ih);
62             }
63             pm.currentTransaction().commit();
64
65             pm.evictAll(); //clear the L2 cache
66

67             pm.currentTransaction().begin();
68             IntervenantHelper ih = (IntervenantHelper) pm.getObjectById(
69                 pm.newObjectIdInstance(IntervenantHelper.class, "" + 2),
70                 false);
71             assertEquals("Bad convention elements in collection",
72                 2,
73                 ih.getConventions().size());
74             pm.currentTransaction().commit();
75             
76             pm.close();
77         } catch (Exception JavaDoc e) {
78             logger.log(BasicLevel.ERROR, "Exception", e);
79             fail(e.getMessage());
80         }
81     }
82     
83 }
84
Popular Tags