Search in sources :

Example 11 with NameObject

use of com.blazebit.persistence.testsuite.entity.NameObject in project blaze-persistence by Blazebit.

the class AbstractEntityViewUpdateNestedEmbeddableEntityTest method prepareData.

@Override
protected void prepareData(EntityManager em) {
    entity1 = new EmbeddableTestEntity();
    entity1.getId().setKey("e1");
    entity1.getId().setValue("e1");
    entity1.setVersion(1L);
    entity2 = new EmbeddableTestEntity();
    entity2.getId().setKey("e2");
    entity2.getId().setValue("e2");
    entity2.setVersion(1L);
    intIdEntity1 = new IntIdEntity("i1", 1);
    intIdEntity2 = new IntIdEntity("i2", 2);
    em.persist(entity1);
    em.persist(entity2);
    em.persist(intIdEntity1);
    em.persist(intIdEntity2);
    entity1.getEmbeddable().setManyToOne(entity1);
    entity1.getEmbeddable().getManyToMany().put("a", intIdEntity1);
    entity1.getEmbeddable().getOneToMany2().add(entity1);
    entity1.getEmbeddable().getElementCollection().put("a", new NameObject("a", "b", intIdEntity1));
    entity1.getEmbeddable().getNestedEmbeddable().getNestedOneToMany().add(entity1);
}
Also used : EmbeddableTestEntity(com.blazebit.persistence.testsuite.entity.EmbeddableTestEntity) IntIdEntity(com.blazebit.persistence.testsuite.entity.IntIdEntity) NameObject(com.blazebit.persistence.testsuite.entity.NameObject)

Example 12 with NameObject

use of com.blazebit.persistence.testsuite.entity.NameObject in project blaze-persistence by Blazebit.

the class AbstractEntityViewUpdateEmbeddableMapsTest method updateAddToNewCollection.

public T updateAddToNewCollection() {
    // Given
    final T docView = getDoc1View();
    clearQueries();
    // When
    docView.setNameMap(new HashMap<>(docView.getNameMap()));
    docView.getNameMap().put("newPrimaryName", new NameObject("newPrimaryName", "newSecondaryName"));
    return docView;
}
Also used : NameObject(com.blazebit.persistence.testsuite.entity.NameObject)

Example 13 with NameObject

use of com.blazebit.persistence.testsuite.entity.NameObject in project blaze-persistence by Blazebit.

the class AbstractEntityViewUpdateEmbeddableMapsTest method updateAddToCollection.

public T updateAddToCollection() {
    // Given
    final T docView = getDoc1View();
    clearQueries();
    // When
    docView.getNameMap().put("newPrimaryName", new NameObject("newPrimaryName", "newSecondaryName"));
    return docView;
}
Also used : NameObject(com.blazebit.persistence.testsuite.entity.NameObject)

Example 14 with NameObject

use of com.blazebit.persistence.testsuite.entity.NameObject in project blaze-persistence by Blazebit.

the class EntityViewUpdateMutableEmbeddableTest method testUpdateMutable.

@Test
public void testUpdateMutable() {
    // Given & When
    final UpdatableDocumentEmbeddableView docView = updateMutable();
    Long oldVersion = docView.getVersion();
    if (!isFullMode()) {
        SingularChangeModel<UpdatableDocumentEmbeddableView> changeModel = evm.getChangeModel(docView);
        assertTrue(changeModel.isDirty());
        assertEquals(ChangeModel.ChangeKind.MUTATED, changeModel.getKind());
        ChangeModel<?> nameChange = changeModel.get("nameObject");
        assertTrue(nameChange.isDirty());
        if (registerType) {
            assertEquals(ChangeModel.ChangeKind.UPDATED, nameChange.getKind());
        } else {
            assertEquals(ChangeModel.ChangeKind.UPDATED, nameChange.getKind());
        }
        assertEquals(new NameObject("newPrimaryName", "newSecondaryName"), nameChange.getCurrentState());
        assertEquals(Arrays.asList(nameChange), changeModel.getDirtyChanges());
    }
    updateAndAssertChangesFlushed(docView);
    // Then
    assertVersionDiff(oldVersion, docView.getVersion(), 1, 1);
    fullFetchUpdateAndReload(docView);
    assertVersionDiff(oldVersion, docView.getVersion(), 1, registerType && !isQueryStrategy() ? 1 : 2);
    assertEquals("newPrimaryName", doc1.getNameObject().getPrimaryName());
    assertEquals("newSecondaryName", doc1.getNameObject().getSecondaryName());
}
Also used : NameObject(com.blazebit.persistence.testsuite.entity.NameObject) UpdatableDocumentEmbeddableView(com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableView) Test(org.junit.Test) AbstractEntityViewUpdateEmbeddableTest(com.blazebit.persistence.view.testsuite.update.embeddable.simple.AbstractEntityViewUpdateEmbeddableTest)

Example 15 with NameObject

use of com.blazebit.persistence.testsuite.entity.NameObject in project blaze-persistence by Blazebit.

the class EntityViewUpdateMutableEmbeddableTest method testMutateMutable.

@Test
public void testMutateMutable() {
    // Given & When
    final UpdatableDocumentEmbeddableView docView = mutateMutable();
    Long oldVersion = docView.getVersion();
    if (!isFullMode()) {
        SingularChangeModel<UpdatableDocumentEmbeddableView> changeModel = evm.getChangeModel(docView);
        assertTrue(changeModel.isDirty());
        assertEquals(ChangeModel.ChangeKind.MUTATED, changeModel.getKind());
        ChangeModel<?> nameChange = changeModel.get("nameObject");
        assertTrue(nameChange.isDirty());
        if (registerType) {
            assertEquals(ChangeModel.ChangeKind.UPDATED, nameChange.getKind());
        } else {
            assertEquals(ChangeModel.ChangeKind.MUTATED, nameChange.getKind());
        }
        assertEquals(new NameObject("newPrimaryName", "newSecondaryName"), nameChange.getCurrentState());
        assertEquals(Arrays.asList(nameChange), changeModel.getDirtyChanges());
    }
    updateAndAssertChangesFlushed(docView);
    // Then
    assertVersionDiff(oldVersion, docView.getVersion(), 1, 1);
    fullFetchUpdateAndReload(docView);
    assertVersionDiff(oldVersion, docView.getVersion(), 1, registerType && !isQueryStrategy() ? 1 : 2);
    assertEquals("newPrimaryName", doc1.getNameObject().getPrimaryName());
    assertEquals("newSecondaryName", doc1.getNameObject().getSecondaryName());
}
Also used : NameObject(com.blazebit.persistence.testsuite.entity.NameObject) UpdatableDocumentEmbeddableView(com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableView) Test(org.junit.Test) AbstractEntityViewUpdateEmbeddableTest(com.blazebit.persistence.view.testsuite.update.embeddable.simple.AbstractEntityViewUpdateEmbeddableTest)

Aggregations

NameObject (com.blazebit.persistence.testsuite.entity.NameObject)30 Test (org.junit.Test)7 Document (com.blazebit.persistence.testsuite.entity.Document)6 NameObjectContainer (com.blazebit.persistence.testsuite.entity.NameObjectContainer)5 Person (com.blazebit.persistence.testsuite.entity.Person)5 Category (org.junit.experimental.categories.Category)5 UpdatableDocumentEmbeddableView (com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableView)4 Tuple (javax.persistence.Tuple)4 Date (java.util.Date)3 Map (java.util.Map)3 Version (com.blazebit.persistence.testsuite.entity.Version)2 TxVoidWork (com.blazebit.persistence.testsuite.tx.TxVoidWork)2 MapChangeModel (com.blazebit.persistence.view.change.MapChangeModel)2 PluralChangeModel (com.blazebit.persistence.view.change.PluralChangeModel)2 AbstractEntityViewUpdateEmbeddableTest (com.blazebit.persistence.view.testsuite.update.embeddable.simple.AbstractEntityViewUpdateEmbeddableTest)2 UpdatableDocumentEmbeddableWithCollectionsView (com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithCollectionsView)2 UpdatableDocumentEmbeddableWithMapsView (com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithMapsView)2 UpdatableNameObjectView (com.blazebit.persistence.view.testsuite.update.flatview.simple.mutable.model.UpdatableNameObjectView)2 ReadonlyNameObjectView (com.blazebit.persistence.view.testsuite.update.flatview.simple.mutablesubtype.model.ReadonlyNameObjectView)2 HashMap (java.util.HashMap)2