1 27 28 package org.objectweb.speedo.runtime.map; 29 30 import org.objectweb.speedo.SpeedoTestHelper; 31 import org.objectweb.speedo.pobjects.map.Registry; 32 import org.objectweb.speedo.pobjects.map.A; 33 import org.objectweb.speedo.pobjects.map.B; 34 35 import javax.jdo.PersistenceManager; 36 import javax.jdo.JDOException; 37 38 import junit.framework.Assert; 39 40 import java.util.Collection ; 41 42 public class TestMap extends SpeedoTestHelper { 43 44 public TestMap(String s) { 45 super(s); 46 } 47 48 protected String getLoggerName() { 49 return LOG_NAME + ".rt.map.TestMap"; 50 } 51 52 public void testCreation1() { 53 Registry r1 = new Registry("r1"); 54 Registry r2 = new Registry("r2"); 55 Registry r3 = new Registry("r3"); 56 r1.bind("a", r2); 57 r1.bind("b", r3); 58 59 PersistenceManager pm = pmf.getPersistenceManager(); 60 pm.makePersistent(r1); 61 Object oid1 = pm.getObjectId(r1); 62 Assert.assertNotNull("null object identifier of r1", r1); 63 pm.close(); 64 65 r1 = null; 66 r2 = null; 67 r3 = null; 68 pm = pmf.getPersistenceManager(); 69 pm.evictAll(); 70 r1 = (Registry) pm.getObjectById(oid1, true); 71 Assert.assertNotNull("null instance returned by getObjectById(oid1)", r1); 72 r2 = (Registry) r1.lookup("a"); 73 Assert.assertNotNull("null instance returned by r1.lookup(a)", r2); 74 r3 = (Registry) r1.lookup("b"); 75 Assert.assertNotNull("null instance returned by r1.lookup(b)", r3); 76 pm.currentTransaction().begin(); 77 pm.deletePersistent(r1); 78 pm.deletePersistent(r2); 79 pm.deletePersistent(r3); 80 pm.currentTransaction().commit(); 81 pm.close(); 82 } 83 84 public void testA() { 85 86 PersistenceManager pm = pmf.getPersistenceManager(); 88 A a = new A(0); 89 pm.makePersistent(a); 90 pm.close(); 91 92 final int NB_B = 10; 94 final String IDX_PREFIX = "index2B"; 95 final String F1_PREFIX = "toto"; 96 pm = pmf.getPersistenceManager(); 97 for(int i=0; i<NB_B; i++) { 98 a.add(IDX_PREFIX + i, new B(i, F1_PREFIX + i)); 99 } 100 pm.close(); 101 102 a = null; pm = pmf.getPersistenceManager(); 105 pm.evictAll(); 106 pm.close(); 107 108 pm = pmf.getPersistenceManager(); 110 try { 111 a = (A) pm.getObjectById(pm.newObjectIdInstance(A.class, "" + 0), false); 112 } catch (JDOException e) { 113 fail("The A instance is not found on the data support"); 114 } 115 Collection names = a.names(); 116 assertNotNull("name collection is null", names); 117 assertEquals("Bad name collection size", NB_B, names.size()); 118 B[] bs = new B[NB_B]; 119 for(int i=0; i<NB_B; i++) { 120 String idx = IDX_PREFIX + i; 121 assertTrue("The name collection does not contain the index: " + idx, 122 names.contains(idx)); 123 bs[i] = a.getB(idx); 124 assertNotNull("Null element assocaited to the index " + idx, bs[i]); 125 assertEquals("Bad F1 value for the element assocaited to the index " 126 + idx, F1_PREFIX + i, bs[i].getF1()); 127 } 128 a.clear(); 129 pm.currentTransaction().begin(); 130 pm.deletePersistentAll(bs); 131 pm.deletePersistent(a); 132 pm.currentTransaction().commit(); 133 pm.close(); 134 } 135 } 136 | Popular Tags |