Search in sources :

Example 1 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class DataPersisterImplTest method testPersistMetaNoneDataUpsert.

@SuppressWarnings("unchecked")
@Test
public void testPersistMetaNoneDataUpsert() {
    Repository<Entity> repository0 = mock(Repository.class);
    when(dataService.getRepository(entityType0.getId())).thenReturn(repository0);
    Repository<Entity> repository1 = mock(Repository.class);
    when(dataService.getRepository(entityType1.getId())).thenReturn(repository1);
    PersistResult persistResult = dataPersisterImpl.persist(dataProvider, MetadataMode.NONE, DataMode.UPSERT);
    assertEquals(persistResult, PersistResult.create(ImmutableMap.of(entityType0.getId(), 2L, entityType1.getId(), 3L)));
    InOrder inOrder = inOrder(metaDataService, repository0, repository1);
    inOrder.verify(repository1).upsertBatch(anyList());
    inOrder.verify(repository0).upsertBatch(anyList());
    verifyNoMoreInteractions(metaDataService, repository0, repository1);
}
Also used : Entity(org.molgenis.data.Entity) InOrder(org.mockito.InOrder) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 2 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class IndexActionRepositoryDecorator method registerRefEntityIndexActions.

/**
 * Register index actions for the given entity for entity types with bidirectional attribute values.
 *
 * @param entity entity to add or delete
 */
private void registerRefEntityIndexActions(Entity entity) {
    // bidirectional attribute: register indexing actions for other side
    getEntityType().getMappedByAttributes().forEach(mappedByAttr -> {
        EntityType mappedByAttrRefEntity = mappedByAttr.getRefEntity();
        entity.getEntities(mappedByAttr.getName()).forEach(refEntity -> indexActionRegisterService.register(mappedByAttrRefEntity, refEntity.getIdValue()));
    });
    getEntityType().getInversedByAttributes().forEach(inversedByAttr -> {
        Entity refEntity = entity.getEntity(inversedByAttr.getName());
        if (refEntity != null) {
            EntityType inversedByAttrRefEntity = inversedByAttr.getRefEntity();
            indexActionRegisterService.register(inversedByAttrRefEntity, refEntity.getIdValue());
        }
    });
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Entity(org.molgenis.data.Entity)

Example 3 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class DataPersisterImpl method persistSecondPass.

private void persistSecondPass(DataProvider dataProvider, List<EntityType> topologicalSortedEntityTypes) {
    topologicalSortedEntityTypes.forEach(entityType -> {
        EntityType persistedEntityType = persistEntityTypeSecondPass(entityType);
        if (dataProvider.hasEntities(entityType)) {
            Stream<Entity> entities = dataProvider.getEntities(entityType);
            persistEntitiesSecondPass(persistedEntityType, entities);
        }
    });
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Entity(org.molgenis.data.Entity)

Example 4 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class ExcelEntityTest method setEntity.

@Test
public void setEntity() {
    Entity entity = new DynamicEntity(mock(EntityType.class)) {

        @Override
        protected void validateValueType(String attrName, Object value) {
        // noop
        }
    };
    entity.set("attr1", "test1");
    entity.set("attr2", "test2");
    excelEntity.set(entity);
    assertEquals(excelEntity.get("attr1"), "test1");
    assertNull(excelEntity.get("attr2"));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) Test(org.testng.annotations.Test)

Example 5 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class ExcelRepositoryTest method iterator.

@Test
public void iterator() {
    Iterator<Entity> it = excelSheetReader.iterator();
    assertTrue(it.hasNext());
    Entity row1 = it.next();
    assertEquals(row1.get("col1"), "val1");
    assertEquals(row1.get("col2"), "val2");
    assertTrue(it.hasNext());
    Entity row2 = it.next();
    assertEquals(row2.get("col1"), "val3");
    assertEquals(row2.get("col2"), "val4");
    assertTrue(it.hasNext());
    Entity row3 = it.next();
    assertEquals(row3.get("col1"), "XXX");
    assertEquals(row3.get("col2"), "val6");
    assertTrue(it.hasNext());
    // test number cell (col1) and formula cell (col2)
    Entity row4 = it.next();
    assertEquals(row4.get("col1"), "1.2");
    assertEquals(row4.get("col2"), "2.4");
    assertFalse(it.hasNext());
}
Also used : Entity(org.molgenis.data.Entity) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Aggregations

Entity (org.molgenis.data.Entity)448 Test (org.testng.annotations.Test)295 DynamicEntity (org.molgenis.data.support.DynamicEntity)192 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)120 Attribute (org.molgenis.data.meta.model.Attribute)111 EntityType (org.molgenis.data.meta.model.EntityType)110 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)37 MolgenisDataException (org.molgenis.data.MolgenisDataException)20 QueryImpl (org.molgenis.data.support.QueryImpl)20 AttributeType (org.molgenis.data.meta.AttributeType)18 UnexpectedEnumException (org.molgenis.util.UnexpectedEnumException)18 Stream (java.util.stream.Stream)17 QueryRule (org.molgenis.data.QueryRule)16 MultiAllelicResultFilter (org.molgenis.data.annotation.core.filter.MultiAllelicResultFilter)16 RunAsSystem (org.molgenis.security.core.runas.RunAsSystem)16 Objects.requireNonNull (java.util.Objects.requireNonNull)15 DataService (org.molgenis.data.DataService)15 AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)15 WithMockUser (org.springframework.security.test.context.support.WithMockUser)14 Instant (java.time.Instant)13