Package org.objectweb.speedo.runtime.cap

Source Code of org.objectweb.speedo.runtime.cap.Test1

/**
* Speedo: an implementation of JDO compliant personality on top of JORM generic
* I/O sub-system.
* 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
*
*
*
* Contact: speedo@objectweb.org
*
*/

package org.objectweb.speedo.runtime.cap;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import javax.jdo.JDOException;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import junit.framework.Assert;

import org.objectweb.speedo.SpeedoTestHelper;
import org.objectweb.speedo.api.ExceptionHelper;
import org.objectweb.speedo.pobjects.cap.JDOAction;
import org.objectweb.speedo.pobjects.cap.JDOAdminUser;
import org.objectweb.speedo.pobjects.cap.JDORole;
import org.objectweb.speedo.pobjects.cap.JDOScope;
import org.objectweb.util.monolog.api.BasicLevel;

/**
* This test aimed at solving a problem due to complicated relationships between objects.
* @author Y.Bersihand
*/
public class Test1 extends SpeedoTestHelper {

 
  public Test1(String s) {
    super(s);
  }

 
  protected String getLoggerName() {
    return null;
  }
 
 
  /**
   * test a particular pattern with collection
   */
  public void testCapGemini(){
    JDOScope scope1 = new JDOScope(1, "scope1");
    JDOScope scope2 = new JDOScope(2, "scope2");
    JDOScope scope3 = new JDOScope(3, "scope3");
    JDOScope scope4 = new JDOScope(4, "scope4");
   
    Collection scopes1 = new ArrayList();
    scopes1.add(scope1);
    scopes1.add(scope3);
   
    Collection scopes2 = new ArrayList();
    scopes2.add(scope2);
    scopes2.add(scope4);
   
    JDOAction action1 = new JDOAction(1,"action1","/action1/");
    JDOAction action2 = new JDOAction(2,"action2","/action2/");
    JDOAction action3 = new JDOAction(3,"action3","/action3/");
    JDOAction action4 = new JDOAction(4,"action4","/action4/");
   
    JDORole role1 = new JDORole(1, "role1", scopes1, new ArrayList());
    JDORole role2 = new JDORole(2, "role2", scopes2, new ArrayList());
   
    role1.addAction(action1, true, 1);
    role1.addAction(action3, true, 1);
   
    role2.addAction(action2, true, 2);
    role2.addAction(action4, true, 2);
   
    Collection roles = new ArrayList();
    roles.add(role1);
    roles.add(role2);
   
    JDOAdminUser adminUser = new JDOAdminUser("id","login", "mail", roles);
   
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    pm.makePersistent(adminUser);
    pm.currentTransaction().commit();
    pm.close();
  }
 
  public void testRemovingOfPersistentObject() {
        PersistenceManager pm = pmf.getPersistenceManager();
        try {
            Class[] cs = new Class[]{JDOAction.class,JDOAdminUser.class,JDORole.class, JDOScope.class};
          pm.currentTransaction().begin();
            for(int i=0; i<cs.length; i++) {
                Query query = pm.newQuery(cs[i]);
                Collection col = (Collection) query.execute();
                Iterator it = col.iterator();
                while(it.hasNext()) {
                    Object o = it.next();
                    Assert.assertNotNull("null object in the query result"
                        + cs[i].getName(), o);
                    pm.deletePersistent(o);

                }
                query.close(col);
            }
          pm.currentTransaction().commit();
        } catch (JDOException e) {
            Exception ie = ExceptionHelper.getNested(e);
            logger.log(BasicLevel.ERROR, "", ie);
            fail(ie.getMessage());
        } finally {
            pm.close();
        }
    }

}
TOP

Related Classes of org.objectweb.speedo.runtime.cap.Test1

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.