@Test
  public void testPersistCascading() {
    Map<String, String> aMap = new HashMap<String, String>();
    aMap.put(ConfigKeys.FACTORY, MutableTestDataSourceFactory.class.getName());
    aMap.put("files", TestJPA.DATA_FILE);

    EntityManager aManager =
        Empire.get()
            .persistenceProvider()
            .createEntityManagerFactory("test", aMap)
            .createEntityManager();

    // ================= test persist cascade

    LaunchUsingProxy aNewLaunchWithProxy = new LaunchUsingProxy();
    Launch aNewLaunch = new Launch();

    Spacecraft aNewOtherSpacecraft = new Spacecraft();
    aNewOtherSpacecraft.setRdfId(
        new SupportsRdfId.URIKey(
            URI.create("http://empire.clarkparsia.com/test/persist/cascade/aNewOtherSpacecraft")));
    aNewOtherSpacecraft.setAgency("agency");

    aNewLaunchWithProxy.setOtherSpacecraft(aNewOtherSpacecraft);
    aNewLaunch.setOtherSpacecraft(aNewOtherSpacecraft);

    aManager.persist(aNewLaunch);

    assertTrue(aManager.contains(aNewLaunch));

    // it was persisted as a relation...
    assertTrue(
        aManager
            .find(Launch.class, aNewLaunch.getRdfId())
            .getOtherSpacecraft()
            .getRdfId()
            .equals(aNewOtherSpacecraft.getRdfId()));

    // but persist does not cascade
    assertFalse(aManager.contains(aNewOtherSpacecraft));

    aManager.persist(aNewLaunchWithProxy);

    assertTrue(aManager.contains(aNewLaunchWithProxy));

    // it was persisted as a relation...
    assertTrue(
        aManager
            .find(LaunchUsingProxy.class, aNewLaunchWithProxy.getRdfId())
            .getOtherSpacecraft()
            .equals(aNewOtherSpacecraft));

    // and this should be true now because the persist was cascaded
    assertTrue(aManager.contains(aNewOtherSpacecraft));
  }
  @Test
  public void testMergeCascading() {
    String aLaunchURI = "http://nasa.dataincubator.org/launch/SATURNSA1";
    String aOtherLaunchURI = "http://nasa.dataincubator.org/launch/PION2";

    // =============== test merge cascade
    LaunchUsingProxy aExistingLaunchWithProxy = mManager.find(LaunchUsingProxy.class, aLaunchURI);
    Launch aExistingLaunch = mManager.find(Launch.class, aOtherLaunchURI);

    Spacecraft aNewSpacecraft = new Spacecraft();
    aNewSpacecraft.setRdfId(
        new SupportsRdfId.URIKey(
            URI.create("http://empire.clarkparsia.com/test/merge/cascade/aNewOtherSpacecraft")));
    aNewSpacecraft.setAgency("agency");

    aExistingLaunch.setOtherSpacecraft(aNewSpacecraft);
    aExistingLaunchWithProxy.setOtherSpacecraft(aNewSpacecraft);

    mManager.merge(aExistingLaunch);

    assertTrue(mManager.contains(aExistingLaunch));
    // it was merged as a relation...
    assertTrue(
        mManager
            .find(Launch.class, aOtherLaunchURI)
            .getOtherSpacecraft()
            .getRdfId()
            .equals(aNewSpacecraft.getRdfId()));

    // but merge does not cascade
    assertFalse(mManager.contains(aNewSpacecraft));

    mManager.merge(aExistingLaunchWithProxy);

    assertTrue(mManager.contains(aExistingLaunchWithProxy));

    // this should be true now because the merge was cascaded
    assertTrue(mManager.contains(aNewSpacecraft));
  }