1 25 26 package org.objectweb.speedo.runtime.cap; 27 28 import java.util.ArrayList ; 29 import java.util.Collection ; 30 import java.util.Iterator ; 31 32 import javax.jdo.JDOException; 33 import javax.jdo.PersistenceManager; 34 import javax.jdo.Query; 35 36 import junit.framework.Assert; 37 38 import org.objectweb.speedo.SpeedoTestHelper; 39 import org.objectweb.speedo.api.ExceptionHelper; 40 import org.objectweb.speedo.pobjects.cap.JDOAction; 41 import org.objectweb.speedo.pobjects.cap.JDOAdminUser; 42 import org.objectweb.speedo.pobjects.cap.JDORole; 43 import org.objectweb.speedo.pobjects.cap.JDOScope; 44 import org.objectweb.util.monolog.api.BasicLevel; 45 46 50 public class Test1 extends SpeedoTestHelper { 51 52 53 public Test1(String s) { 54 super(s); 55 } 56 57 58 protected String getLoggerName() { 59 return null; 60 } 61 62 63 66 public void testCapGemini(){ 67 JDOScope scope1 = new JDOScope(1, "scope1"); 68 JDOScope scope2 = new JDOScope(2, "scope2"); 69 JDOScope scope3 = new JDOScope(3, "scope3"); 70 JDOScope scope4 = new JDOScope(4, "scope4"); 71 72 Collection scopes1 = new ArrayList (); 73 scopes1.add(scope1); 74 scopes1.add(scope3); 75 76 Collection scopes2 = new ArrayList (); 77 scopes2.add(scope2); 78 scopes2.add(scope4); 79 80 JDOAction action1 = new JDOAction(1,"action1","/action1/"); 81 JDOAction action2 = new JDOAction(2,"action2","/action2/"); 82 JDOAction action3 = new JDOAction(3,"action3","/action3/"); 83 JDOAction action4 = new JDOAction(4,"action4","/action4/"); 84 85 JDORole role1 = new JDORole(1, "role1", scopes1, new ArrayList ()); 86 JDORole role2 = new JDORole(2, "role2", scopes2, new ArrayList ()); 87 88 role1.addAction(action1, true, 1); 89 role1.addAction(action3, true, 1); 90 91 role2.addAction(action2, true, 2); 92 role2.addAction(action4, true, 2); 93 94 Collection roles = new ArrayList (); 95 roles.add(role1); 96 roles.add(role2); 97 98 JDOAdminUser adminUser = new JDOAdminUser("id","login", "mail", roles); 99 100 PersistenceManager pm = pmf.getPersistenceManager(); 101 pm.currentTransaction().begin(); 102 pm.makePersistent(adminUser); 103 pm.currentTransaction().commit(); 104 pm.close(); 105 } 106 107 public void testRemovingOfPersistentObject() { 108 PersistenceManager pm = pmf.getPersistenceManager(); 109 try { 110 Class [] cs = new Class []{JDOAction.class,JDOAdminUser.class,JDORole.class, JDOScope.class}; 111 pm.currentTransaction().begin(); 112 for(int i=0; i<cs.length; i++) { 113 Query query = pm.newQuery(cs[i]); 114 Collection col = (Collection ) query.execute(); 115 Iterator it = col.iterator(); 116 while(it.hasNext()) { 117 Object o = it.next(); 118 Assert.assertNotNull("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 } 136 | Popular Tags |