@Test public void testTargetEntity() { String aLaunchURI = "http://nasa.dataincubator.org/launch/SATURNSA1"; Launch aLaunch = mManager.find(Launch.class, aLaunchURI); LaunchUsingProxy aProxySupportingLaunch = mManager.find(LaunchUsingProxy.class, aLaunchURI); assertTrue(aProxySupportingLaunch.getSpacecraft().size() > 0); // the values for this are all space craft in the data // but the mapping just specifies an uptyped collection (a List). // we're using the targetEntity property of the OneToMany annotation to // specify the type, so we want to make sure that everything returned by this // function is a space craft. The fact that it returns at all pretty much // guarantees that, but we want to make sure. for (Object aObj : aProxySupportingLaunch.getSpacecraft()) { assertTrue(aObj instanceof Spacecraft); } // "normal" mapping should be equal to the proxied, targetEntity mapped version assertTrue(contentsEqual(aLaunch.getSpacecraft(), aProxySupportingLaunch.getSpacecraft())); }
@Test public void testRemoveCascading() { String aLaunchURI = "http://nasa.dataincubator.org/launch/SATURNSA1"; String aOtherLaunchURI = "http://nasa.dataincubator.org/launch/PION2"; // ================= test remove cascade LaunchUsingProxy aExistingLaunchWithProxy = mManager.find(LaunchUsingProxy.class, aLaunchURI); Launch aExistingLaunch = mManager.find(Launch.class, aOtherLaunchURI); List<Spacecraft> aExistingSpacecraft = aExistingLaunch.getSpacecraft(); assertTrue(aExistingSpacecraft.size() > 0); aExistingLaunch.getSpacecraft().clear(); mManager.remove(aExistingLaunch); // delete shoudl have worked... assertFalse(mManager.contains(aExistingLaunch)); // but not cascaded for (Spacecraft aCraft : aExistingSpacecraft) { assertTrue(mManager.contains(aCraft)); } aExistingSpacecraft = aExistingLaunchWithProxy.getSpacecraft(); assertTrue(aExistingSpacecraft.size() > 0); mManager.remove(aExistingLaunchWithProxy); // delete should have worked... assertFalse(mManager.contains(aExistingLaunchWithProxy)); // and delete should have cascaded for (Spacecraft aCraft : aExistingSpacecraft) { assertFalse(mManager.contains(aCraft)); } }