/**********************************************************************
Copyright (c) 2011 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
**********************************************************************/
package com.google.appengine.datanucleus.jdo;

import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.datanucleus.test.UnownedJDOOneToOneBiSideA;
import com.google.appengine.datanucleus.test.UnownedJDOOneToOneBiSideB;
import com.google.appengine.datanucleus.test.UnownedJDOOneToOneUniSideA;
import com.google.appengine.datanucleus.test.UnownedJDOOneToOneUniSideB;

/**
 * Tests for 1-1 unowned JDO relations.
 */
public class JDOUnownedOneToOneTest extends JDOTestCase {

  public void testPersistUniNewOwnerNonOwner() throws EntityNotFoundException {
    // Persist A-B as unowned
    UnownedJDOOneToOneUniSideA a = new UnownedJDOOneToOneUniSideA();
    a.setName("Side A");
    UnownedJDOOneToOneUniSideB b = new UnownedJDOOneToOneUniSideB();
    b.setName("Side B");
    a.setOther(b);

    pm.makePersistent(a);
    // TODO Enable this when we default to latest storage version
    /*Object aId = pm.getObjectId(a);
    Object bId = pm.getObjectId(b);

    pm.evictAll(); // Make sure we go to the datastore

    // Retrieve by id and check
    UnownedJDOOneToOneUniSideA a2 = (UnownedJDOOneToOneUniSideA)pm.getObjectById(aId);
    assertNotNull(a2);
    assertEquals("Side A", a2.getName());
    UnownedJDOOneToOneUniSideB b2 = a.getOther();
    assertNotNull(b2);
    assertNotNull("Side B", b2.getName());
    assertEquals(bId, pm.getObjectId(b2));*/
  }

  public void testPersistBiNewOwnerNonOwner() throws EntityNotFoundException {
    // Persist A-B as unowned
    UnownedJDOOneToOneBiSideA a = new UnownedJDOOneToOneBiSideA();
    a.setName("Side A");
    UnownedJDOOneToOneBiSideB b = new UnownedJDOOneToOneBiSideB();
    b.setName("Side B");
    a.setOther(b);
    b.setOther(a);

    pm.makePersistent(a);
    // TODO Enable this when we default to latest storage version
    /*Object aId = pm.getObjectId(a);
    Object bId = pm.getObjectId(b);

    pm.evictAll(); // Make sure we go to the datastore

    // Retrieve by id and check
    UnownedJDOOneToOneUniSideA a2 = (UnownedJDOOneToOneUniSideA)pm.getObjectById(aId);
    assertNotNull(a2);
    assertEquals("Side A", a2.getName());
    UnownedJDOOneToOneUniSideB b2 = a.getOther();
    assertNotNull(b2);
    assertNotNull("Side B", b2.getName());
    assertEquals(bId, pm.getObjectId(b2));*/
  }
}

@@ -1228,37 +1228,28 @@
 ersistUniNew
-OwnerNonOwner
+Both
 () throws En
@@ -2117,16 +2117,16 @@
 iNew
-OwnerNon
+BothFrom
 Owne
@@ -2411,24 +2411,24 @@
 tOther(a);%0A%0A
-
     pm.makeP
@@ -2630,32 +2630,940 @@
  the datastore%0A%0A
+    // Retrieve by id and check%0A    UnownedJDOOneToOneUniSideA a2 = (UnownedJDOOneToOneUniSideA)pm.getObjectById(aId);%0A    assertNotNull(a2);%0A    assertEquals(%22Side A%22, a2.getName());%0A    UnownedJDOOneToOneUniSideB b2 = a.getOther();%0A    assertNotNull(b2);%0A    assertNotNull(%22Side B%22, b2.getName());%0A    assertEquals(bId, pm.getObjectId(b2));*/%0A  %7D%0A%0A  public void testPersistBiNewBothFromNonowner() throws EntityNotFoundException %7B%0A    // Persist A-B as unowned%0A    UnownedJDOOneToOneBiSideA a = new UnownedJDOOneToOneBiSideA();%0A    a.setName(%22Side A%22);%0A    UnownedJDOOneToOneBiSideB b = new UnownedJDOOneToOneBiSideB();%0A    b.setName(%22Side B%22);%0A    a.setOther(b);%0A    b.setOther(a);%0A%0A    pm.makePersistent(b);%0A    // TODO Enable this when we default to latest storage version%0A    /*Object aId = pm.getObjectId(a);%0A    Object bId = pm.getObjectId(b);%0A%0A    pm.evictAll(); // Make sure we go to the datastore%0A%0A
     // Retrieve 

test for 1-1 bi persisted from other side