Пример #1
0
  @Test
  public void testLoadingOfRefThroughInheritanceInField() throws Exception {
    // TODO us: exclusion does not work properly with maven + junit4
    if (!LazyFeatureDependencies.testDependencyFullFilled()) {
      return;
    }

    morphia.map(ContainerWithRefInField.class);
    morphia.map(OtherEntityChild.class);

    OtherEntityChild otherEntity = new OtherEntityChild();
    ContainerWithRefInField containerWithRefInField = new ContainerWithRefInField();

    ds.save(otherEntity, containerWithRefInField);

    otherEntity = ds.get(otherEntity);
    final ContainerWithRefInField reload = ds.get(containerWithRefInField);
    Assert.assertNotNull(otherEntity);
    Assert.assertNotNull(reload);

    EmbedWithRef embedWithRef = new EmbedWithRef();
    embedWithRef.otherEntity = otherEntity;
    reload.embedWithRef = embedWithRef;

    ds.save(reload);
    ds.get(reload);
    containerWithRefInField = ds.get(containerWithRefInField);
    Assert.assertNotNull(containerWithRefInField);
  }
Пример #2
0
  @Test
  public void testLoadingOfRefInList() throws Exception {
    // TODO us: exclusion does not work properly with maven + junit4
    if (!LazyFeatureDependencies.testDependencyFullFilled()) {
      return;
    }

    morphia.map(ContainerWithRefList.class);
    morphia.map(OtherEntity.class);

    OtherEntity otherEntity = new OtherEntity();
    ContainerWithRefList containerWithRefInList = new ContainerWithRefList();

    ds.save(otherEntity, containerWithRefInList);

    otherEntity = ds.get(otherEntity);
    containerWithRefInList = ds.get(containerWithRefInList);
    Assert.assertNotNull(otherEntity);
    Assert.assertNotNull(containerWithRefInList);

    EmbedWithRef embedWithRef = new EmbedWithRef();
    embedWithRef.otherEntity = otherEntity;
    containerWithRefInList.embedWithRef.add(embedWithRef);

    ds.save(otherEntity, containerWithRefInList);

    containerWithRefInList = ds.get(containerWithRefInList);
    Assert.assertNotNull(containerWithRefInList);

    Query<ContainerWithRefList> createQuery = ds.createQuery(ContainerWithRefList.class);
    containerWithRefInList = createQuery.get();
    Assert.assertNotNull(containerWithRefInList);
  }