01: /**
02: * Copyright (C) 2001-2006 France Telecom R&D
03: */package org.objectweb.speedo.runtime.basic;
04:
05: import org.objectweb.speedo.SpeedoTestHelper;
06: import org.objectweb.speedo.pobjects.multitable.Address;
07:
08: import java.util.ArrayList;
09: import java.util.Collection;
10: import java.util.List;
11:
12: import javax.jdo.PersistenceManager;
13: import javax.jdo.Query;
14:
15: public class TestMultitable extends SpeedoTestHelper {
16:
17: public TestMultitable(String s) {
18: super (s);
19: }
20:
21: protected String getLoggerName() {
22: return LOG_NAME + ".rt.basic.TestMultitable";
23: }
24:
25: public void testAddress() {
26: final int size = 5;
27: List as = getData(size);
28: PersistenceManager pm = pmf.getPersistenceManager();
29: pm.currentTransaction().begin();
30: pm.makePersistentAll(as);
31: pm.currentTransaction().commit();
32:
33: as = null;
34: pm.evictAll();
35:
36: pm.currentTransaction().begin();
37: Query q = pm.newQuery(Address.class);
38: Collection c = (Collection) q.execute();
39: assertSameCollection(
40: "Bad collection of address from the query",
41: getData(size), c);
42: as = new ArrayList(c);
43: q.closeAll();
44: pm.currentTransaction().commit();
45:
46: pm.currentTransaction().begin();
47: pm.deletePersistentAll(as);
48: pm.currentTransaction().commit();
49: pm.close();
50:
51: }
52:
53: private List getData(final int size) {
54: List as = new ArrayList(size);
55: for (int i = 0; i < size; i++) {
56: Address a = new Address();
57: a.setCity("city_" + i);
58: a.setDeliveryInstructions("deliv_" + i);
59: byte[] map = new byte[20 * (i + 1)];
60: for (int j = 0; j < map.length; j++) {
61: map[j] = (byte) i;
62: }
63: a.setMapJPG(map);
64: a.setSignatureRequired(i % 2 == 1);
65: a.setState("state_" + i);
66: a.setStreet("street_" + i);
67: a.setZip("zip_" + i);
68: as.add(a);
69: }
70: return as;
71: }
72: }
|