001: /**
002: * Speedo: an implementation of JDO compliant personality on top of JORM generic
003: * I/O sub-system.
004: * Copyright (C) 2001-2004 France Telecom R&D
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: *
021: *
022: * Contact: speedo@objectweb.org
023: *
024: */package org.objectweb.speedo.runtime.cap;
025:
026: import java.util.ArrayList;
027: import java.util.Collection;
028: import java.util.Iterator;
029:
030: import javax.jdo.JDOException;
031: import javax.jdo.PersistenceManager;
032: import javax.jdo.Query;
033:
034: import junit.framework.Assert;
035:
036: import org.objectweb.speedo.SpeedoTestHelper;
037: import org.objectweb.speedo.api.ExceptionHelper;
038: import org.objectweb.speedo.pobjects.cap.JDOAction;
039: import org.objectweb.speedo.pobjects.cap.JDOAdminUser;
040: import org.objectweb.speedo.pobjects.cap.JDORole;
041: import org.objectweb.speedo.pobjects.cap.JDOScope;
042: import org.objectweb.util.monolog.api.BasicLevel;
043:
044: /**
045: * This test aimed at solving a problem due to complicated relationships between objects.
046: * @author Y.Bersihand
047: */
048: public class Test1 extends SpeedoTestHelper {
049:
050: public Test1(String s) {
051: super (s);
052: }
053:
054: protected String getLoggerName() {
055: return null;
056: }
057:
058: /**
059: * test a particular pattern with collection
060: */
061: public void testCapGemini() {
062: JDOScope scope1 = new JDOScope(1, "scope1");
063: JDOScope scope2 = new JDOScope(2, "scope2");
064: JDOScope scope3 = new JDOScope(3, "scope3");
065: JDOScope scope4 = new JDOScope(4, "scope4");
066:
067: Collection scopes1 = new ArrayList();
068: scopes1.add(scope1);
069: scopes1.add(scope3);
070:
071: Collection scopes2 = new ArrayList();
072: scopes2.add(scope2);
073: scopes2.add(scope4);
074:
075: JDOAction action1 = new JDOAction(1, "action1", "/action1/");
076: JDOAction action2 = new JDOAction(2, "action2", "/action2/");
077: JDOAction action3 = new JDOAction(3, "action3", "/action3/");
078: JDOAction action4 = new JDOAction(4, "action4", "/action4/");
079:
080: JDORole role1 = new JDORole(1, "role1", scopes1,
081: new ArrayList());
082: JDORole role2 = new JDORole(2, "role2", scopes2,
083: new ArrayList());
084:
085: role1.addAction(action1, true, 1);
086: role1.addAction(action3, true, 1);
087:
088: role2.addAction(action2, true, 2);
089: role2.addAction(action4, true, 2);
090:
091: Collection roles = new ArrayList();
092: roles.add(role1);
093: roles.add(role2);
094:
095: JDOAdminUser adminUser = new JDOAdminUser("id", "login",
096: "mail", roles);
097:
098: PersistenceManager pm = pmf.getPersistenceManager();
099: pm.currentTransaction().begin();
100: pm.makePersistent(adminUser);
101: pm.currentTransaction().commit();
102: pm.close();
103: }
104:
105: public void testRemovingOfPersistentObject() {
106: PersistenceManager pm = pmf.getPersistenceManager();
107: try {
108: Class[] cs = new Class[] { JDOAction.class,
109: JDOAdminUser.class, JDORole.class, JDOScope.class };
110: pm.currentTransaction().begin();
111: for (int i = 0; i < cs.length; i++) {
112: Query query = pm.newQuery(cs[i]);
113: Collection col = (Collection) query.execute();
114: Iterator it = col.iterator();
115: while (it.hasNext()) {
116: Object o = it.next();
117: Assert.assertNotNull(
118: "null object in the query result"
119: + cs[i].getName(), o);
120: pm.deletePersistent(o);
121:
122: }
123: query.close(col);
124: }
125: pm.currentTransaction().commit();
126: } catch (JDOException e) {
127: Exception ie = ExceptionHelper.getNested(e);
128: logger.log(BasicLevel.ERROR, "", ie);
129: fail(ie.getMessage());
130: } finally {
131: pm.close();
132: }
133: }
134:
135: }
|