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"));
}
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)));
}
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"))));
}
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);
}
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");
}
Aggregations