1 25 26 package org.objectweb.speedo.runtime.sequence.id.speedoExtension; 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 import javax.jdo.datastore.Sequence; 36 37 import junit.framework.Assert; 38 39 import org.objectweb.speedo.SpeedoTestHelper; 40 import org.objectweb.speedo.api.ExceptionHelper; 41 import org.objectweb.speedo.pobjects.sequence.id.speedoExtension.Card; 42 import org.objectweb.speedo.pobjects.sequence.id.speedoExtension.Maps; 43 import org.objectweb.util.monolog.api.BasicLevel; 44 45 52 public class TestSequenceSE extends SpeedoTestHelper { 53 54 public TestSequenceSE(String s) { 55 super(s); 56 } 57 58 protected String getLoggerName() { 59 return LOG_NAME + ".rt.sequence.TestSequence"; 60 } 61 62 public static final String CARD_SEQ = "org.objectweb.speedo.pobjects.sequence.id.speedoExtension.card_sequence"; 63 public static final String MAP_SEQ = "org.objectweb.speedo.pobjects.sequence.id.speedoExtension.map_sequence"; 64 65 68 public void testSequenceId() { 69 logger.log(BasicLevel.DEBUG, "***************testSequenceId*****************"); 70 PersistenceManager pm = pmf.getPersistenceManager(); 71 pm.getObjectIdClass(Card.class); 72 Sequence s = pm.getSequence(CARD_SEQ); 74 assertNotNull("Sequence " + CARD_SEQ + " should not be null.", s); 75 Card c1 = new Card(); 76 c1.setName("card 1"); 77 Card c2 = new Card(); 78 c2.setName("card 2"); 79 80 Collection c = new ArrayList (); 81 c.add(c1); 82 c.add(c2); 83 pm.currentTransaction().begin(); 85 pm.makePersistentAll(c); 86 pm.currentTransaction().commit(); 87 assertTrue(c1.getId() < c2.getId()); 88 pm.close(); 89 } 90 91 94 public void testSequenceHiddenField() { 95 logger.log(BasicLevel.DEBUG, "***************testSequenceHiddenField*****************"); 96 PersistenceManager pm = pmf.getPersistenceManager(); 97 pm.getObjectIdClass(Maps.class); 98 Sequence s = pm.getSequence(MAP_SEQ); 100 assertNotNull("Sequence " + MAP_SEQ + " should not be null.", s); 101 Maps m1 = new Maps(); 102 m1.setName("map 1"); 103 Maps m2 = new Maps(); 104 m2.setName("map 2"); 105 106 Collection c = new ArrayList (); 107 c.add(m1); 108 c.add(m2); 109 pm.currentTransaction().begin(); 111 pm.makePersistentAll(c); 112 pm.currentTransaction().commit(); 113 pm.close(); 114 } 115 116 119 public void _testRemovingOfPersistentObject() { 120 PersistenceManager pm = pmf.getPersistenceManager(); 121 try { 122 Class [] cs = new Class []{Maps.class, Card.class}; 123 pm.currentTransaction().begin(); 124 for(int i=0; i<cs.length; i++) { 125 Query query = pm.newQuery(cs[i]); 126 Collection col = (Collection ) query.execute(); 127 Iterator it = col.iterator(); 128 while(it.hasNext()) { 129 Object o = it.next(); 130 Assert.assertNotNull("null object in the query result" 131 + cs[i].getName(), o); 132 pm.deletePersistent(o); 133 134 } 135 query.close(col); 136 } 137 pm.currentTransaction().commit(); 138 } catch (JDOException e) { 139 Exception ie = ExceptionHelper.getNested(e); 140 logger.log(BasicLevel.ERROR, "", ie); 141 fail(ie.getMessage()); 142 } finally { 143 pm.close(); 144 } 145 } 146 } 147 | Popular Tags |