Search in sources :

Example 1 with EmbeddableTestEntitySubView

use of com.blazebit.persistence.view.testsuite.basic.model.EmbeddableTestEntitySubView in project blaze-persistence by Blazebit.

the class EmbeddableTestEntityViewTest method assertEqualViewEquals.

private void assertEqualViewEquals(EmbeddableTestEntity2 entity, EmbeddableTestEntityViewWithSubview view) {
    assertEquals(entity.getId(), view.getId());
    if (entity.getId().getIntIdEntity() == null) {
        assertNull(view.getIdIntIdEntity());
    } else {
        assertEquals(entity.getId().getIntIdEntity().getId(), view.getIdIntIdEntity().getId());
    }
    assertEquals(entity.getId().getIntIdEntity().getId(), view.getIdIntIdEntityId());
    assertEquals(entity.getId().getIntIdEntity().getName(), view.getIdIntIdEntityName());
    assertEquals(entity.getId().getKey(), view.getIdKey());
    assertEquals(entity.getEmbeddable().getName(), view.getEmbeddable().getName());
    if (entity.getEmbeddable().getManyToOne() == null) {
        assertNull(view.getEmbeddableManyToOneView());
    } else {
        assertEquals(entity.getEmbeddable().getManyToOne().getId(), view.getEmbeddableManyToOneView().getId());
    }
    assertEquals(entity.getEmbeddable().getOneToMany().size(), view.getEmbeddableOneToManyView().size());
    OUTER: for (EmbeddableTestEntity2 child : entity.getEmbeddable().getOneToMany()) {
        for (EmbeddableTestEntitySubView childView : view.getEmbeddableOneToManyView()) {
            if (child.getId().equals(childView.getId())) {
                continue OUTER;
            }
        }
        fail("Couldn't find child view with id: " + child.getId());
    }
    assertEquals(entity.getEmbeddable().getElementCollection().size(), view.getEmbeddableElementCollectionView().size());
    for (Map.Entry<String, IntIdEntity> childEntry : entity.getEmbeddable().getElementCollection().entrySet()) {
        IntIdEntityView childView = view.getEmbeddableElementCollectionView().get(childEntry.getKey());
        assertEquals(childEntry.getValue().getId(), childView.getId());
    }
    Set<String> set1 = new HashSet<String>();
    for (EmbeddableTestEntitySimpleEmbeddable2 elem : entity.getEmbeddableSet()) {
        set1.add(elem.getName());
    }
    Set<String> set2 = new HashSet<String>();
    for (EmbeddableTestEntitySimpleEmbeddableSubView elem : view.getEmbeddableSet()) {
        set2.add(elem.getName());
    }
    assertEquals(set1, set2);
    Map<String, String> map1 = new HashMap<String, String>();
    for (Map.Entry<String, EmbeddableTestEntitySimpleEmbeddable2> entry : entity.getEmbeddableMap().entrySet()) {
        map1.put(entry.getKey(), entry.getValue().getName());
    }
    Map<String, String> map2 = new HashMap<String, String>();
    for (Map.Entry<String, EmbeddableTestEntitySimpleEmbeddableSubView> entry : view.getEmbeddableMap().entrySet()) {
        map2.put(entry.getKey(), entry.getValue().getName());
    }
    assertEquals(map1, map2);
}
Also used : IntIdEntity(com.blazebit.persistence.testsuite.entity.IntIdEntity) EmbeddableTestEntitySimpleEmbeddableSubView(com.blazebit.persistence.view.testsuite.basic.model.EmbeddableTestEntitySimpleEmbeddableSubView) HashMap(java.util.HashMap) EmbeddableTestEntity2(com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntity2) EmbeddableTestEntitySimpleEmbeddable2(com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntitySimpleEmbeddable2) EmbeddableTestEntitySubView(com.blazebit.persistence.view.testsuite.basic.model.EmbeddableTestEntitySubView) IntIdEntityView(com.blazebit.persistence.view.testsuite.basic.model.IntIdEntityView) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

IntIdEntity (com.blazebit.persistence.testsuite.entity.IntIdEntity)1 EmbeddableTestEntitySimpleEmbeddableSubView (com.blazebit.persistence.view.testsuite.basic.model.EmbeddableTestEntitySimpleEmbeddableSubView)1 EmbeddableTestEntitySubView (com.blazebit.persistence.view.testsuite.basic.model.EmbeddableTestEntitySubView)1 IntIdEntityView (com.blazebit.persistence.view.testsuite.basic.model.IntIdEntityView)1 EmbeddableTestEntity2 (com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntity2)1 EmbeddableTestEntitySimpleEmbeddable2 (com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntitySimpleEmbeddable2)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1