Package org.objectweb.speedo.runtime.ref.fkId

Source Code of org.objectweb.speedo.runtime.ref.fkId.TestSameCompositeId

/**
* Copyright (C) 2001-2004 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
package org.objectweb.speedo.runtime.ref.fkId;

import javax.jdo.PersistenceManager;

import junit.framework.Assert;

import org.objectweb.speedo.SpeedoTestHelper;
import org.objectweb.speedo.pobjects.ref.fkId.Project;
import org.objectweb.speedo.pobjects.ref.fkId.Release;

/**
*
* Test one to one relationship sharing the smae composite id,
* this composite id being used to describe the reverse field relationship.
* @author Y. Bersihand
*/

public class TestSameCompositeId extends SpeedoTestHelper {

  public TestSameCompositeId(String s) {
    super(s);
  }

  protected String getLoggerName() {
    return LOG_NAME + "rt.ref.fkId.TestSameCompositeId";
  }
 
  /**
   * Make persistent a project and an associated release
   * Retrieve the project and test the id fields of the project and its release.
   */
  public void testRetrieveRelationship() {
   
    PersistenceManager pm = pmf.getPersistenceManager();
    String name_id = "project1";
    String team_id = "dpc";
    Project p1 = new Project(name_id, team_id);
    Release r1 = new Release();
    r1.setProject(p1);
    r1.setVersion(1);
    //make the project persistent
    pm.makePersistent(p1);
    //keep the id of the project
    Object project1ID = pm.getObjectId(p1);
    Assert.assertNotNull("null object identifier", project1ID);
    pm.close();

    p1 = null;
    r1 = null;
    pm = pmf.getPersistenceManager();
    //retrieve the project
    p1 = (Project) pm.getObjectById(project1ID, true);
    Assert.assertNotNull("null instance returned by getObjectById", p1);
    Assert.assertEquals("Bad project name", name_id, p1.getNameId());
    Assert.assertEquals("Bad project name", team_id, p1.getTeamId());
    Assert.assertNotNull("null instance returned by p1.getRelease()", p1.getRelease());
    Assert.assertEquals("Bad project name for release", name_id, p1.getRelease().getNameId());
    Assert.assertEquals("Bad team name for release", team_id, p1.getRelease().getTeamId());
   
    //delete the release and the project
    pm.currentTransaction().begin();
    pm.deletePersistent(p1.getRelease());
    pm.deletePersistent(p1);
    pm.currentTransaction().commit();
    pm.close();
  }
}
TOP

Related Classes of org.objectweb.speedo.runtime.ref.fkId.TestSameCompositeId

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.