Search in sources :

Example 96 with AssertStatementBuilder

use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.

the class EntityViewUpdateBlobTest method testUpdateBlob.

@Test
// NOTE: No Datanucleus support yet
@Category({ NoDatanucleus.class, NoEclipselink.class, NoOracle.class, NoH2.class })
public void testUpdateBlob() throws Exception {
    // Given
    {
        final UpdatableBlobEntityView docView = getBlobView();
        docView.setBlob(new BlobImpl(new byte[1]));
        update(docView);
        clearPersistenceContextAndReload();
    }
    final UpdatableBlobEntityView docView = getBlobView();
    clearQueries();
    // When
    docView.getBlob().setBytes(1, new byte[2]);
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            em.clear();
            clearQueries();
            evm.save(em, docView);
            em.flush();
        }
    });
    // Then
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (!isQueryStrategy()) {
        fullFetch(builder);
    }
    builder.update(BlobEntity.class);
    builder.validate();
    assertEquals(2, docView.getBlob().length());
    clearPersistenceContextAndReload();
    assertEquals(2, entity.getBlob().length());
}
Also used : EntityManager(javax.persistence.EntityManager) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) UpdatableBlobEntityView(com.blazebit.persistence.view.testsuite.update.converter.model.UpdatableBlobEntityView) Category(org.junit.experimental.categories.Category) AbstractEntityViewUpdateTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest) Test(org.junit.Test)

Example 97 with AssertStatementBuilder

use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.

the class EntityViewUpdateCorrelatedCreatableSubviewTest method testUpdateWithModifyExisting.

@Test
public void testUpdateWithModifyExisting() {
    // Given
    final UpdatableDocumentView docView = getDoc1View();
    clearQueries();
    // When
    docView.getResponsiblePerson().setName("newPerson");
    update(docView);
    // Then
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            fullUpdate(builder);
        }
    } else {
        if (isFullMode()) {
            fullFetch(builder);
        }
    }
    builder.validate();
    assertNoUpdateAndReload(docView);
    assertEquals(p1.getId(), doc1.getResponsiblePerson().getId());
    assertEquals("pers1", p1.getName());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.correlated.creatable.model.UpdatableDocumentView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 98 with AssertStatementBuilder

use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.

the class EntityViewUpdateCorrelatedCreatableSubviewTest method testUpdateWithSubview.

@Test
public void testUpdateWithSubview() {
    // Given
    final UpdatableDocumentView docView = getDoc1View();
    UpdatablePersonView newPerson = getP2View(UpdatablePersonView.class);
    clearQueries();
    // When
    docView.setResponsiblePerson(newPerson);
    update(docView);
    // Then
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isFullMode()) {
        if (!isQueryStrategy()) {
            fullFetch(builder);
        }
        if (isQueryStrategy() || version) {
            builder.update(Document.class);
        }
    }
    builder.validate();
    assertNoUpdateAndReload(docView);
    assertEquals(p1.getId(), doc1.getResponsiblePerson().getId());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.correlated.creatable.model.UpdatableDocumentView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) UpdatablePersonView(com.blazebit.persistence.view.testsuite.update.correlated.creatable.model.UpdatablePersonView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 99 with AssertStatementBuilder

use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.

the class EntityViewUpdateBlobTest method testUpdateNothingWhenExistingBlob.

@Test
public void testUpdateNothingWhenExistingBlob() throws Exception {
    // Given
    {
        final UpdatableBlobEntityView docView = getBlobView();
        docView.setBlob(new BlobImpl(new byte[1]));
        update(docView);
        clearPersistenceContextAndReload();
    }
    final UpdatableBlobEntityView docView = getBlobView();
    clearQueries();
    // When
    update(docView);
    // Then
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isFullMode()) {
        if (!isQueryStrategy()) {
            fullFetch(builder);
        }
        builder.update(BlobEntity.class);
    }
    builder.validate();
    clearPersistenceContextAndReload();
    assertEquals("doc1", docView.getName());
    assertEquals(entity.getName(), docView.getName());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) UpdatableBlobEntityView(com.blazebit.persistence.view.testsuite.update.converter.model.UpdatableBlobEntityView) AbstractEntityViewUpdateTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest) Test(org.junit.Test)

Example 100 with AssertStatementBuilder

use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.

the class EntityViewUpdateMutableBasicTest method fullFetchUpdateAndReload.

private void fullFetchUpdateAndReload(UpdatableDocumentBasicView docView) {
    // Assert that not only the document is loaded and finally also updated
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (!isQueryStrategy()) {
        fullFetch(builder);
    }
    builder.update(Document.class).validate();
    assertNoUpdateAndReload(docView);
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Document(com.blazebit.persistence.testsuite.entity.Document)

Aggregations

AssertStatementBuilder (com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder)330 Test (org.junit.Test)304 Document (com.blazebit.persistence.testsuite.entity.Document)193 AbstractEntityViewUpdateDocumentTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)180 Person (com.blazebit.persistence.testsuite.entity.Person)86 AbstractEntityViewUpdateEntityCollectionsTest (com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityCollectionsTest)26 AbstractEntityViewUpdateEntityMapsTest (com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityMapsTest)26 AbstractEntityViewUpdateEntityTest (com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityTest)20 AbstractEntityViewOrphanRemoveDocumentTest (com.blazebit.persistence.view.testsuite.update.remove.orphan.AbstractEntityViewOrphanRemoveDocumentTest)12 UpdatablePersonView (com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatablePersonView)10 UpdatableDocumentEntityWithCollectionsView (com.blazebit.persistence.view.testsuite.update.entity.mutable.model.UpdatableDocumentEntityWithCollectionsView)9 UpdatableDocumentEntityWithMapsView (com.blazebit.persistence.view.testsuite.update.entity.creatable.model.UpdatableDocumentEntityWithMapsView)8 UpdatableDocumentEntityWithMapsView (com.blazebit.persistence.view.testsuite.update.entity.updatableonly.model.UpdatableDocumentEntityWithMapsView)8 FriendPersonView (com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.FriendPersonView)8 UpdatableDocumentWithMapsView (com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableDocumentWithMapsView)8 UpdatableDocumentWithCollectionsView (com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableDocumentWithCollectionsView)8 UpdatableFriendPersonView (com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableFriendPersonView)8 UpdatableResponsiblePersonView (com.blazebit.persistence.view.testsuite.update.subview.nested.updatableonly.model.UpdatableResponsiblePersonView)8 NaturalIdJoinTableEntity (com.blazebit.persistence.testsuite.entity.NaturalIdJoinTableEntity)6 Version (com.blazebit.persistence.testsuite.entity.Version)6