01: /**
02: * Copyright (C) 2001-2004 France Telecom R&D
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */package org.objectweb.speedo.runtime.ref.fkId;
18:
19: import javax.jdo.PersistenceManager;
20:
21: import junit.framework.Assert;
22:
23: import org.objectweb.speedo.SpeedoTestHelper;
24: import org.objectweb.speedo.pobjects.ref.fkId.Project;
25: import org.objectweb.speedo.pobjects.ref.fkId.Release;
26:
27: /**
28: *
29: * Test one to one relationship sharing the smae composite id,
30: * this composite id being used to describe the reverse field relationship.
31: * @author Y. Bersihand
32: */
33:
34: public class TestSameCompositeId extends SpeedoTestHelper {
35:
36: public TestSameCompositeId(String s) {
37: super (s);
38: }
39:
40: protected String getLoggerName() {
41: return LOG_NAME + "rt.ref.fkId.TestSameCompositeId";
42: }
43:
44: /**
45: * Make persistent a project and an associated release
46: * Retrieve the project and test the id fields of the project and its release.
47: */
48: public void testRetrieveRelationship() {
49:
50: PersistenceManager pm = pmf.getPersistenceManager();
51: String name_id = "project1";
52: String team_id = "dpc";
53: Project p1 = new Project(name_id, team_id);
54: Release r1 = new Release();
55: r1.setProject(p1);
56: r1.setVersion(1);
57: //make the project persistent
58: pm.makePersistent(p1);
59: //keep the id of the project
60: Object project1ID = pm.getObjectId(p1);
61: Assert.assertNotNull("null object identifier", project1ID);
62: pm.close();
63:
64: p1 = null;
65: r1 = null;
66: pm = pmf.getPersistenceManager();
67: //retrieve the project
68: p1 = (Project) pm.getObjectById(project1ID, true);
69: Assert.assertNotNull("null instance returned by getObjectById",
70: p1);
71: Assert
72: .assertEquals("Bad project name", name_id, p1
73: .getNameId());
74: Assert
75: .assertEquals("Bad project name", team_id, p1
76: .getTeamId());
77: Assert.assertNotNull(
78: "null instance returned by p1.getRelease()", p1
79: .getRelease());
80: Assert.assertEquals("Bad project name for release", name_id, p1
81: .getRelease().getNameId());
82: Assert.assertEquals("Bad team name for release", team_id, p1
83: .getRelease().getTeamId());
84:
85: //delete the release and the project
86: pm.currentTransaction().begin();
87: pm.deletePersistent(p1.getRelease());
88: pm.deletePersistent(p1);
89: pm.currentTransaction().commit();
90: pm.close();
91: }
92: }
|