Search in sources :

Example 16 with NameObject

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

the class EntityViewUpdateMutableEmbeddableTest method assertEmptyChangeModel.

protected void assertEmptyChangeModel(UpdatableDocumentEmbeddableView docView) {
    if (!isFullMode()) {
        SingularChangeModel<UpdatableDocumentEmbeddableView> changeModel = evm.getChangeModel(docView);
        ChangeModel<?> nameChange = changeModel.get("nameObject");
        if (registerType) {
            assertFalse(changeModel.isDirty());
            assertEquals(ChangeModel.ChangeKind.NONE, changeModel.getKind());
            assertFalse(nameChange.isDirty());
            assertEquals(ChangeModel.ChangeKind.NONE, nameChange.getKind());
            assertTrue(changeModel.getDirtyChanges().isEmpty());
        } else {
            assertTrue(changeModel.isDirty());
            assertEquals(ChangeModel.ChangeKind.MUTATED, changeModel.getKind());
            assertTrue(nameChange.isDirty());
            assertEquals(ChangeModel.ChangeKind.MUTATED, nameChange.getKind());
            assertEquals(Arrays.asList(nameChange), changeModel.getDirtyChanges());
        }
        assertEquals(new NameObject("newPrimaryName", "newSecondaryName"), nameChange.getCurrentState());
    }
}
Also used : NameObject(com.blazebit.persistence.testsuite.entity.NameObject) UpdatableDocumentEmbeddableView(com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableView)

Example 17 with NameObject

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

the class AbstractEntityViewUpdateDocumentTest method prepareData.

@Override
protected void prepareData(EntityManager em) {
    doc1 = new Document("doc1", 10);
    doc1.setVersion(1L);
    doc1.setLastModified(new Date(EPOCH_2K));
    doc1.getNameObject().setPrimaryName("doc1");
    doc1.getNames().add(new NameObject("doc1", "doc1"));
    doc1.getNameMap().put("doc1", new NameObject("doc1", "doc1"));
    doc1.getNameContainers().add(new NameObjectContainer("doc1", new NameObject("doc1", "doc1")));
    doc1.getNameContainerMap().put("doc1", new NameObjectContainer("doc1", new NameObject("doc1", "doc1")));
    doc2 = new Document("doc2");
    doc2.setVersion(1L);
    doc2.setLastModified(new Date(EPOCH_2K));
    doc2.setNameObject(new NameObject("doc2", "doc2"));
    doc2.getNames().add(new NameObject("doc2", "doc2"));
    doc2.getNameMap().put("doc1", new NameObject("doc2", "doc2"));
    doc2.getNameContainers().add(new NameObjectContainer("doc2", new NameObject("doc2", "doc2")));
    doc2.getNameContainerMap().put("doc2", new NameObjectContainer("doc2", new NameObject("doc2", "doc2")));
    p1 = new Person("pers1");
    p1.getNameObject().setPrimaryName("pers1");
    p1.getLocalized().put(1, "localized1");
    p2 = new Person("pers2");
    p2.getNameObject().setPrimaryName("pers2");
    p2.getLocalized().put(1, "localized2");
    p3 = new Person("pers3");
    p3.getNameObject().setPrimaryName("pers3");
    p3.getLocalized().put(1, "localized3");
    p4 = new Person("pers4");
    p4.getNameObject().setPrimaryName("pers4");
    p4.getLocalized().put(1, "localized4");
    doc1.setOwner(p1);
    doc1.setResponsiblePerson(p1);
    doc1.getPeople().add(p1);
    doc1.getContacts().put(1, p1);
    doc1.getContacts2().put(2, p1);
    doc1.getStrings().add("asd");
    doc1.getStringMap().put("doc1", "doc1");
    doc2.setOwner(p2);
    doc2.setResponsiblePerson(p2);
    em.persist(p1);
    em.persist(p2);
    em.persist(p3);
    em.persist(p4);
    em.persist(doc1);
    em.persist(doc2);
    p1.setPartnerDocument(doc1);
    p1.setFriend(p3);
    p2.setFriend(p4);
}
Also used : NameObject(com.blazebit.persistence.testsuite.entity.NameObject) NameObjectContainer(com.blazebit.persistence.testsuite.entity.NameObjectContainer) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) Date(java.util.Date)

Example 18 with NameObject

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

the class AbstractEntityViewRemoveDocumentTest method prepareData.

@Override
protected void prepareData(EntityManager em) {
    doc1 = new Document("doc1", null, new Version());
    doc1.setVersion(1L);
    doc1.setLastModified(new Date(EPOCH_2K));
    doc1.getNameObject().setPrimaryName("doc1");
    doc1.getNames().add(new NameObject("doc1", "doc1"));
    doc1.getNameMap().put("doc1", new NameObject("doc1", "doc1"));
    doc1.getNameContainers().add(new NameObjectContainer("doc1", new NameObject("doc1", "doc1")));
    doc1.getNameContainerMap().put("doc1", new NameObjectContainer("doc1", new NameObject("doc1", "doc1")));
    doc2 = new Document("doc2");
    doc2.setVersion(1L);
    doc2.setLastModified(new Date(EPOCH_2K));
    doc2.setNameObject(new NameObject("doc2", "doc2"));
    doc2.getNames().add(new NameObject("doc2", "doc2"));
    doc2.getNameMap().put("doc1", new NameObject("doc2", "doc2"));
    doc2.getNameContainers().add(new NameObjectContainer("doc2", new NameObject("doc2", "doc2")));
    doc2.getNameContainerMap().put("doc2", new NameObjectContainer("doc2", new NameObject("doc2", "doc2")));
    p1 = new Person("pers1");
    p1.getNameObject().setPrimaryName("pers1");
    p1.getLocalized().put(1, "localized1");
    p2 = new Person("pers2");
    p2.getNameObject().setPrimaryName("pers2");
    p2.getLocalized().put(1, "localized2");
    p3 = new Person("pers3");
    p3.getNameObject().setPrimaryName("pers3");
    p3.getLocalized().put(1, "localized3");
    p4 = new Person("pers4");
    p4.getNameObject().setPrimaryName("pers4");
    p4.getLocalized().put(1, "localized4");
    p5 = new Person("pers3");
    p5.getNameObject().setPrimaryName("pers3");
    p5.getLocalized().put(1, "localized3");
    p6 = new Person("pers4");
    p6.getNameObject().setPrimaryName("pers4");
    p6.getLocalized().put(1, "localized4");
    doc1.setOwner(p5);
    doc1.setResponsiblePerson(p1);
    doc1.getPeople().add(p1);
    doc1.getContacts().put(1, p1);
    doc1.getContacts2().put(2, p1);
    doc1.getStrings().add("asd");
    doc1.getStringMap().put("doc1", "doc1");
    doc1.getVersions().iterator().next().getLocalized().put(1, "1");
    doc2.setOwner(p6);
    doc2.setResponsiblePerson(p2);
    em.persist(p1);
    em.persist(p2);
    em.persist(p3);
    em.persist(p4);
    em.persist(p5);
    em.persist(p6);
    em.persist(doc1);
    em.persist(doc2);
    p1.setFriend(p3);
    p2.setFriend(p4);
}
Also used : NameObject(com.blazebit.persistence.testsuite.entity.NameObject) Version(com.blazebit.persistence.testsuite.entity.Version) NameObjectContainer(com.blazebit.persistence.testsuite.entity.NameObjectContainer) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) Date(java.util.Date)

Example 19 with NameObject

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

the class EntityViewUpdateSimpleMutableSubtypeFlatViewMapsTest method assertSubviewEquals.

public static void assertSubviewEquals(Map<String, NameObject> persons, Map<String, ? extends ReadonlyNameObjectView> personSubviews) {
    if (persons == null) {
        assertNull(personSubviews);
        return;
    }
    assertNotNull(personSubviews);
    assertEquals(persons.size(), personSubviews.size());
    for (Map.Entry<String, NameObject> entry : persons.entrySet()) {
        NameObject p = entry.getValue();
        boolean found = false;
        ReadonlyNameObjectView pSub = personSubviews.get(entry.getKey());
        if (pSub != null) {
            if (p.getPrimaryName().equals(pSub.getPrimaryName())) {
                found = true;
                break;
            }
        }
        if (!found) {
            Assert.fail("Could not find a UpdatableNameObjectView with the name: " + p.getPrimaryName());
        }
    }
}
Also used : NameObject(com.blazebit.persistence.testsuite.entity.NameObject) Map(java.util.Map) ReadonlyNameObjectView(com.blazebit.persistence.view.testsuite.update.flatview.simple.mutablesubtype.model.ReadonlyNameObjectView)

Example 20 with NameObject

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

the class EntityViewUpdateSimpleMutableFlatViewCollectionsTest method assertSubviewEquals.

public static void assertSubviewEquals(Collection<NameObject> persons, Collection<? extends UpdatableNameObjectView> personSubviews) {
    if (persons == null) {
        assertNull(personSubviews);
        return;
    }
    assertNotNull(personSubviews);
    assertEquals(persons.size(), personSubviews.size());
    for (NameObject p : persons) {
        boolean found = false;
        for (UpdatableNameObjectView pSub : personSubviews) {
            if (p.getPrimaryName().equals(pSub.getPrimaryName())) {
                found = true;
                break;
            }
        }
        if (!found) {
            Assert.fail("Could not find a UpdatableNameObjectView with the name: " + p.getPrimaryName());
        }
    }
}
Also used : NameObject(com.blazebit.persistence.testsuite.entity.NameObject) UpdatableNameObjectView(com.blazebit.persistence.view.testsuite.update.flatview.simple.mutable.model.UpdatableNameObjectView)

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