Search in sources :

Example 11 with Person

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

the class ConstructorOnlyFlatViewTest method setUp.

@Before
public void setUp() {
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            Document doc1 = new Document("doc1");
            Document doc2 = new Document("doc2");
            Person o1 = new Person("pers1");
            doc1.setOwner(o1);
            doc2.setOwner(o1);
            em.persist(o1);
            em.persist(doc1);
            em.persist(doc2);
        }
    });
}
Also used : EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) Before(org.junit.Before)

Example 12 with Person

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

the class AbstractFetchTest method setUpOnce.

@Override
public void setUpOnce() {
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            doc1 = new Document("doc1");
            doc2 = new Document("doc2");
            doc3 = new Document("doc3");
            doc4 = new Document("doc4");
            Person o1 = new Person("pers1");
            Person o2 = new Person("pers2");
            Person o3 = new Person("pers3");
            doc1.setOwner(o1);
            doc2.setOwner(o2);
            doc3.setOwner(o2);
            doc4.setOwner(o2);
            doc1.getStrings().add("s1");
            doc1.getStrings().add("s2");
            doc2.getStrings().add("s1");
            doc2.getStrings().add("s2");
            doc3.getStrings().add("s1");
            doc3.getStrings().add("s2");
            doc4.getStrings().add("s1");
            doc4.getStrings().add("s2");
            em.persist(o1);
            em.persist(o2);
            em.persist(o3);
            em.persist(doc1);
            em.persist(doc2);
            em.persist(doc3);
            em.persist(doc4);
            o1.setPartnerDocument(doc1);
            o2.setPartnerDocument(doc2);
            o3.setPartnerDocument(doc3);
        }
    });
}
Also used : EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person)

Example 13 with Person

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

the class AbstractEntityViewUpdateEntityMapsTest method addToCollection.

public T addToCollection() {
    // Given
    final T docView = getDoc1View();
    Person p = p2;
    clearQueries();
    // When
    docView.getContacts().put(2, p);
    update(docView);
    return docView;
}
Also used : Person(com.blazebit.persistence.testsuite.entity.Person)

Example 14 with Person

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

the class AbstractEntityViewUpdateEntityTest method updateWithEntity.

public T updateWithEntity() {
    // Given
    final T docView = getDoc1View();
    Person newOwner = p2;
    clearQueries();
    // When
    docView.setResponsiblePerson(newOwner);
    update(docView);
    return docView;
}
Also used : Person(com.blazebit.persistence.testsuite.entity.Person)

Example 15 with Person

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

the class EntityViewUpdateMutableOnlyEntityMapsTest method testUpdateModifyEntityInCollection.

@Test
public void testUpdateModifyEntityInCollection() {
    // Given & When
    final UpdatableDocumentEntityWithMapsView docView = modifyEntityInCollection();
    // Then
    // Assert that the document and the people are loaded i.e. a full fetch
    // Since only an existing person was update, only a single update is generated
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        builder.select(Person.class);
    } else {
        fullFetch(builder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        versionUpdate(builder);
    }
    builder.update(Person.class).validate();
    // Unfortunately, even after an update, we have to reload the entity to merge again
    AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
    if (isQueryStrategy()) {
        afterBuilder.select(Person.class);
    } else {
        fullFetch(afterBuilder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        versionUpdate(afterBuilder);
    }
    afterBuilder.validate();
    assertEquals(doc1.getContacts(), docView.getContacts());
    assertEquals("newPerson", p1.getName());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) UpdatableDocumentEntityWithMapsView(com.blazebit.persistence.view.testsuite.update.entity.mutableonly.model.UpdatableDocumentEntityWithMapsView) Person(com.blazebit.persistence.testsuite.entity.Person) Test(org.junit.Test) AbstractEntityViewUpdateEntityMapsTest(com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityMapsTest)

Aggregations

Person (com.blazebit.persistence.testsuite.entity.Person)175 Document (com.blazebit.persistence.testsuite.entity.Document)94 EntityManager (javax.persistence.EntityManager)77 TxVoidWork (com.blazebit.persistence.testsuite.tx.TxVoidWork)76 Test (org.junit.Test)50 AssertStatementBuilder (com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder)19 Before (org.junit.Before)19 Version (com.blazebit.persistence.testsuite.entity.Version)18 AbstractEntityViewTest (com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)14 HashMap (java.util.HashMap)14 Map (java.util.Map)14 AbstractEntityViewUpdateDocumentTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)11 Category (org.junit.experimental.categories.Category)11 CriteriaBuilder (com.blazebit.persistence.CriteriaBuilder)10 UpdatablePersonView (com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatablePersonView)7 NameObject (com.blazebit.persistence.testsuite.entity.NameObject)5 Tuple (javax.persistence.Tuple)5 AbstractCoreTest (com.blazebit.persistence.testsuite.AbstractCoreTest)4 NameObjectContainer (com.blazebit.persistence.testsuite.entity.NameObjectContainer)4 QDocument (com.blazebit.persistence.testsuite.entity.QDocument)4