コード例 #1
0
  @Test
  public void testProxying() {
    // this is not a bullet proof proxy detection, but it should prove whether or not proxying is
    // correctly
    // inserted into the chain of events.

    String javaAssistMarker = "$$_javassist";

    String aLaunchURI = "http://nasa.dataincubator.org/launch/SATURNSA1";

    Launch aLaunch = mManager.find(Launch.class, aLaunchURI);

    LaunchUsingProxy aProxySupportingLaunch = mManager.find(LaunchUsingProxy.class, aLaunchURI);

    // this object is proxied
    LaunchSite aOrigSite = aProxySupportingLaunch.getLaunchSite();

    // this should be a proxy class...
    // the easy way to check this is via the class name to see if its a javassist created class.
    // this means the proxy was correctly created in RdfGenerator
    // and the proxy *works* if the results of the gets and sets are what is expected.
    assertTrue(aOrigSite.getClass().getName().indexOf(javaAssistMarker) != -1);

    // and the non-proxying version should not return a proxy object
    assertTrue(aLaunch.getLaunchSite().getClass().getName().indexOf(javaAssistMarker) == -1);

    // and the proxied object should be equal to a non proxied version of the same thing
    assertEquals(aOrigSite, aLaunch.getLaunchSite());

    // we want to make sure that get/set operations work via a proxied object fine, that we don't
    // get anything cached
    // or stale proxied objects returned accidentally

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

    assertFalse(aOrigSite.equals(aNewSite));

    assertEquals(aProxySupportingLaunch.getLaunchSite(), aOrigSite);

    aProxySupportingLaunch.setLaunchSite(aNewSite);

    assertEquals(aProxySupportingLaunch.getLaunchSite(), aNewSite);
  }
コード例 #2
0
  @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));
  }