Search in sources :

Example 41 with Entity

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

the class DocumentContentBuilderTest method createDocumentDate.

@Test(dataProvider = "createDocumentDate")
public void createDocumentDate(LocalDate localDate, String expectedContent) {
    String attrIdentifier = "attr";
    Entity entity = createEntity(attrIdentifier, AttributeType.DATE);
    when(entity.getLocalDate(attrIdentifier)).thenReturn(localDate);
    Document document = documentContentBuilder.createDocument(entity);
    assertDocumentEquals(document, expectedContent);
}
Also used : Entity(org.molgenis.data.Entity) Document(org.molgenis.data.elasticsearch.generator.model.Document) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 42 with Entity

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

the class ExcelSheetWriterTest method addCellProcessor.

@Test
public void addCellProcessor() throws IOException {
    CellProcessor processor = when(mock(CellProcessor.class).processData()).thenReturn(true).getMock();
    Entity entity = new DynamicEntity(mock(EntityType.class)) {

        @Override
        protected void validateValueType(String attrName, Object value) {
        // noop
        }
    };
    entity.set("col1", "val1");
    entity.set("col2", "val2");
    excelSheetWriter.addCellProcessor(processor);
    excelSheetWriter.add(entity);
    verify(processor).process("val1");
    verify(processor).process("val2");
}
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) CellProcessor(org.molgenis.data.file.processor.CellProcessor) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 43 with Entity

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

the class ElasticsearchServiceTest method testBatchingSearchPageSizeZero.

@Test
@SuppressWarnings("unchecked")
public void testBatchingSearchPageSizeZero() {
    QueryImpl<Entity> query = mock(QueryImpl.class);
    when(query.getPageSize()).thenReturn(0);
    when(query.getOffset()).thenReturn(0);
    SearchHits searchHitsBatch = mock(SearchHits.class);
    when(searchHitsBatch.getHits()).thenReturn(asList(new SearchHit[10000]));
    SearchHits finalSearchHitsBatch = mock(SearchHits.class);
    when(finalSearchHitsBatch.getHits()).thenReturn(asList(new SearchHit[5000]));
    when(clientFacade.search(any(), eq(0), eq(10000), any(), any())).thenReturn(searchHitsBatch);
    when(clientFacade.search(any(), eq(10000), anyInt(), any(), any())).thenReturn(searchHitsBatch);
    when(clientFacade.search(any(), eq(20000), anyInt(), any(), any())).thenReturn(finalSearchHitsBatch);
    elasticsearchService.search(entityType, query);
    verify(clientFacade, times(1)).search(any(), eq(0), eq(MAX_BATCH_SIZE), any(), any());
    verify(clientFacade, times(1)).search(any(), eq(10000), eq(MAX_BATCH_SIZE), any(), any());
    verify(clientFacade, times(1)).search(any(), eq(20000), eq(MAX_BATCH_SIZE), any(), any());
    verifyNoMoreInteractions(clientFacade);
}
Also used : Entity(org.molgenis.data.Entity) SearchHit(org.molgenis.data.elasticsearch.client.model.SearchHit) SearchHits(org.molgenis.data.elasticsearch.client.model.SearchHits) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 44 with Entity

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

the class ElasticsearchServiceTest method testBatchingSearchPageSizeLargerThanMax.

@Test
@SuppressWarnings("unchecked")
public void testBatchingSearchPageSizeLargerThanMax() {
    QueryImpl<Entity> query = mock(QueryImpl.class);
    when(query.getPageSize()).thenReturn(10001);
    when(query.getOffset()).thenReturn(5000);
    SearchHits searchHitsBatch = mock(SearchHits.class);
    when(searchHitsBatch.getHits()).thenReturn(asList(new SearchHit[10000]));
    SearchHits finalSearchHitsBatch = mock(SearchHits.class);
    when(finalSearchHitsBatch.getHits()).thenReturn(asList(new SearchHit[1]));
    when(clientFacade.search(any(), eq(5000), eq(MAX_BATCH_SIZE), any(), any())).thenReturn(searchHitsBatch);
    when(clientFacade.search(any(), eq(15000), eq(1), any(), any())).thenReturn(finalSearchHitsBatch);
    elasticsearchService.search(entityType, query);
    verify(clientFacade, times(1)).search(any(), eq(5000), eq(MAX_BATCH_SIZE), any(), any());
    verify(clientFacade, times(1)).search(any(), eq(15000), eq(1), any(), any());
    verifyNoMoreInteractions(clientFacade);
}
Also used : Entity(org.molgenis.data.Entity) SearchHit(org.molgenis.data.elasticsearch.client.model.SearchHit) SearchHits(org.molgenis.data.elasticsearch.client.model.SearchHits) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 45 with Entity

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

the class TabixRepositoryTest method newEntity.

private Entity newEntity(String chrom, int pos, String ref, String alt, double cadd, double caddScaled) {
    Entity result = new DynamicEntity(repoMetaData);
    result.set(CHROM, chrom);
    result.set(POS, pos);
    result.set(REF, ref);
    result.set(ALT, alt);
    result.set("CADD", cadd);
    result.set("CADD_SCALED", caddScaled);
    return result;
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity)

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