@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 testAllCascade() {
    // ============ test all cascade
    Launch aNewLaunch = new Launch();
    LaunchUsingProxy aNewLaunchWithProxy = new LaunchUsingProxy();

    LaunchSite aNewSiteOne = new LaunchSite();
    aNewSiteOne.setLabel(Arrays.asList("new launch site one"));

    LaunchSite aNewSiteTwo = new LaunchSite();
    aNewSiteTwo.setLabel(Arrays.asList("new launch site two"));

    aNewLaunch.setLaunchSite(aNewSiteOne);
    aNewLaunchWithProxy.setLaunchSite(aNewSiteOne);

    mManager.persist(aNewLaunch);

    assertTrue(mManager.contains(aNewLaunch));
    assertTrue(
        mManager
            .find(Launch.class, aNewLaunch.getRdfId())
            .getLaunchSite()
            .getRdfId()
            .equals(aNewSiteOne.getRdfId()));
    assertFalse(mManager.contains(aNewSiteOne));

    mManager.persist(aNewLaunchWithProxy);

    assertTrue(mManager.contains(aNewLaunchWithProxy));
    assertTrue(
        mManager
            .find(LaunchUsingProxy.class, aNewLaunchWithProxy.getRdfId())
            .getLaunchSite()
            .equals(aNewSiteOne));
    assertTrue(mManager.contains(aNewSiteOne));

    aNewLaunch.setLaunchSite(aNewSiteTwo);
    aNewLaunchWithProxy.setLaunchSite(aNewSiteTwo);

    mManager.merge(aNewLaunch);

    assertTrue(mManager.contains(aNewLaunch));
    assertTrue(
        mManager
            .find(Launch.class, aNewLaunch.getRdfId())
            .getLaunchSite()
            .getRdfId()
            .equals(aNewSiteTwo.getRdfId()));
    assertFalse(mManager.contains(aNewSiteTwo));

    mManager.merge(aNewLaunchWithProxy);

    assertTrue(mManager.contains(aNewLaunchWithProxy));
    assertTrue(
        mManager
            .find(LaunchUsingProxy.class, aNewLaunchWithProxy.getRdfId())
            .getLaunchSite()
            .equals(aNewSiteTwo));
    assertTrue(mManager.contains(aNewSiteTwo));

    mManager.remove(aNewLaunch);

    assertFalse(mManager.contains(aNewLaunch));
    assertTrue(mManager.contains(aNewSiteTwo));

    mManager.remove(aNewLaunchWithProxy);

    assertFalse(mManager.contains(aNewLaunchWithProxy));
    assertFalse(mManager.contains(aNewSiteTwo));
  }