Search in sources :

Example 1 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity 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 2 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class EntityUtilsTest method isEmptyNoAttributes.

@Test
public void isEmptyNoAttributes() {
    EntityType entityType = when(mock(EntityType.class).getId()).thenReturn("entity").getMock();
    when(entityType.getAtomicAttributes()).thenReturn(emptyList());
    assertTrue(EntityUtils.isEmpty(new DynamicEntity(entityType)));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Test(org.testng.annotations.Test)

Example 3 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class EntityUtilsTest method isEmptyAttributeValuesNotNull.

@Test
public void isEmptyAttributeValuesNotNull() {
    EntityType entityType = when(mock(EntityType.class).getId()).thenReturn("entity").getMock();
    Attribute attr = when(mock(Attribute.class).getName()).thenReturn("attr").getMock();
    when(attr.getDataType()).thenReturn(STRING);
    when(entityType.getAtomicAttributes()).thenReturn(singletonList(attr));
    when(entityType.getAttribute("attr")).thenReturn(attr);
    assertFalse(EntityUtils.isEmpty(new DynamicEntity(entityType, of("attr", "val"))));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) DynamicEntity(org.molgenis.data.support.DynamicEntity) Test(org.testng.annotations.Test)

Example 4 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class QueryGeneratorTest method generateOneQueryRuleInCategorical_Entities.

@Test
public void generateOneQueryRuleInCategorical_Entities() {
    Entity ref0 = new DynamicEntity(refEntityType);
    ref0.set(idAttrName, "id0");
    Entity ref1 = new DynamicEntity(refEntityType);
    ref1.set(idAttrName, "id1");
    Entity ref2 = new DynamicEntity(refEntityType);
    ref2.set(idAttrName, "id2");
    Iterable<Object> values = Arrays.asList(ref0, ref1, ref2);
    Query<Entity> q = new QueryImpl<>().in(categoricalAttrName, values);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = constantScoreQuery(nestedQuery(categoricalAttrName, termsQuery(categoricalAttrName + '.' + idAttrName + '.' + FIELD_NOT_ANALYZED, new Object[] { "id0", "id1", "id2" }), ScoreMode.Avg));
    assertQueryBuilderEquals(query, expectedQuery);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) DynamicEntity(org.molgenis.data.support.DynamicEntity) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Example 5 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity 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)

Aggregations

DynamicEntity (org.molgenis.data.support.DynamicEntity)161 Entity (org.molgenis.data.Entity)123 Test (org.testng.annotations.Test)104 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)50 EntityType (org.molgenis.data.meta.model.EntityType)48 Attribute (org.molgenis.data.meta.model.Attribute)38 AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)14 BeforeMethod (org.testng.annotations.BeforeMethod)14 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)7 EntityMapping (org.molgenis.semanticmapper.mapping.model.EntityMapping)5 BeforeClass (org.testng.annotations.BeforeClass)5 ArrayList (java.util.ArrayList)4 MolgenisDataException (org.molgenis.data.MolgenisDataException)4 EntityWithComputedAttributes (org.molgenis.data.support.EntityWithComputedAttributes)4 ExplainedQueryString (org.molgenis.semanticsearch.explain.bean.ExplainedQueryString)4 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)4 StringWriter (java.io.StringWriter)3 List (java.util.List)3 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)3 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)3