Search in sources :

Example 1 with UpdatableDocumentView

use of com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentView in project blaze-persistence by Blazebit.

the class EntityViewUpdateSimpleMutableSubviewTest method testSimpleUpdate.

@Test
public void testSimpleUpdate() {
    // Given
    final UpdatableDocumentView docView = getDoc1View();
    clearQueries();
    // When
    docView.setName("newDoc");
    update(docView);
    // Then
    // Since only the document changed we don't need to load the owner
    // Just assert the update is properly done
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            builder.update(Person.class);
        }
    } else {
        if (isFullMode()) {
            fullFetch(builder);
        } else {
            builder.select(Document.class);
        }
    }
    builder.update(Document.class).validate();
    assertNoUpdateAndReload(docView);
    assertEquals("newDoc", docView.getName());
    assertEquals(doc1.getName(), docView.getName());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Document(com.blazebit.persistence.testsuite.entity.Document) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 2 with UpdatableDocumentView

use of com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentView in project blaze-persistence by Blazebit.

the class EntityViewUpdateSimpleMutableSubviewTest method testUpdateToNull.

@Test
public void testUpdateToNull() {
    // Given
    final UpdatableDocumentView docView = getDoc1View();
    clearQueries();
    // When
    docView.setResponsiblePerson(null);
    update(docView);
    // Then
    // Assert that only the document is loaded and finally also updated
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (!isQueryStrategy()) {
        if (isFullMode()) {
            fullFetch(builder);
        } else {
            builder.select(Document.class);
        }
    }
    builder.update(Document.class).validate();
    AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
    if (isFullMode()) {
        if (isQueryStrategy()) {
            afterBuilder.update(Document.class);
        } else {
            fullFetch(afterBuilder);
        }
    }
    afterBuilder.validate();
    Assert.assertNull(doc1.getResponsiblePerson());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Document(com.blazebit.persistence.testsuite.entity.Document) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 3 with UpdatableDocumentView

use of com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentView in project blaze-persistence by Blazebit.

the class EntityViewUpdateSimpleMutableSubviewTest method testUpdateWithModifyExisting.

@Test
public void testUpdateWithModifyExisting() {
    // Given
    final UpdatableDocumentView docView = getDoc1View();
    clearQueries();
    // When
    docView.getResponsiblePerson().setName("newPerson");
    update(docView);
    // Then
    // Since we update the old responsiblePerson, load it along with the document for updating it later
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        builder.update(Person.class);
        if (isFullMode() || version) {
            builder.update(Document.class);
        }
    } else {
        fullFetch(builder);
        if (version) {
            builder.update(Document.class);
        }
        builder.update(Person.class);
    }
    builder.validate();
    assertNoUpdateAndReload(docView);
    assertEquals("newPerson", doc1.getResponsiblePerson().getName());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 4 with UpdatableDocumentView

use of com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentView in project blaze-persistence by Blazebit.

the class EntityViewUpdateSimpleMutableSubviewTest method testUpdateWithModifySubview.

@Test
public void testUpdateWithModifySubview() {
    // Given
    final UpdatableDocumentView docView = getDoc1View();
    UpdatablePersonView newOwner = getP2View(UpdatablePersonView.class);
    clearQueries();
    // When
    newOwner.setName("newPerson");
    docView.setResponsiblePerson(newOwner);
    update(docView);
    // Then
    // Since the owner changed we don't need to load the old owner
    // Now the new owner has to be loaded as it is updated as well
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        builder.update(Person.class).update(Document.class);
    } else {
        if (isFullMode()) {
            fullFetch(builder);
        } else {
            builder.select(Document.class);
        }
        builder.select(Person.class).update(Document.class).update(Person.class);
    }
    builder.validate();
    assertNoUpdateAndReload(docView);
    assertEquals(p2.getId(), doc1.getResponsiblePerson().getId());
    assertEquals("newPerson", doc1.getResponsiblePerson().getName());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) UpdatablePersonView(com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatablePersonView) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 5 with UpdatableDocumentView

use of com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentView in project blaze-persistence by Blazebit.

the class EntityViewUpdateSimpleMutableSubviewTest method testUpdateWithSubview.

@Test
public void testUpdateWithSubview() {
    // Given
    final UpdatableDocumentView docView = getDoc1View();
    UpdatablePersonView newOwner = getP2View(UpdatablePersonView.class);
    clearQueries();
    // When
    docView.setResponsiblePerson(newOwner);
    update(docView);
    // Then
    // Since the owner changed we don't need to load the old owner
    // The new owner also doesn't have to be loaded, except in full mode
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    ;
    if (isQueryStrategy()) {
        if (isFullMode()) {
            builder.update(Person.class);
        }
    } else {
        if (isFullMode()) {
            fullFetch(builder).select(Person.class);
        } else {
            builder.select(Document.class);
        }
    }
    builder.update(Document.class).validate();
    assertNoUpdateAndReload(docView);
    assertEquals(p2.getId(), doc1.getResponsiblePerson().getId());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) UpdatablePersonView(com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatablePersonView) Document(com.blazebit.persistence.testsuite.entity.Document) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Aggregations

AssertStatementBuilder (com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder)5 AbstractEntityViewUpdateDocumentTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)5 UpdatableDocumentView (com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentView)5 Test (org.junit.Test)5 Document (com.blazebit.persistence.testsuite.entity.Document)4 UpdatablePersonView (com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatablePersonView)2 Person (com.blazebit.persistence.testsuite.entity.Person)1