use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class EntityReferenceTest method testGetLabelValue.
@Test(expectedExceptions = UnsupportedOperationException.class)
public void testGetLabelValue() {
Attribute labelAttribute = when(mock(Attribute.class).getName()).thenReturn(LABEL_ATTR_NAME).getMock();
when(entityType.getLabelAttribute()).thenReturn(labelAttribute);
entityReference.getLabelValue();
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class AbstractRepositoryTest method beforeTest.
@BeforeTest
public void beforeTest() {
MockitoAnnotations.initMocks(this);
Attribute idAttr = when(mock(Attribute.class).getName()).thenReturn("id").getMock();
entityType = when(mock(EntityType.class).getId()).thenReturn("entity").getMock();
when(entityType.getIdAttribute()).thenReturn(idAttr);
abstractRepository = Mockito.spy(new AbstractRepository() {
@Override
public Iterator<Entity> iterator() {
return null;
}
public EntityType getEntityType() {
return entityType;
}
@Override
public Set<RepositoryCapability> getCapabilities() {
return Collections.emptySet();
}
});
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class ExcelSheetWriter method add.
/**
* Add a new row to the sheet
*/
@Override
public void add(Entity entity) {
if (entity == null)
throw new IllegalArgumentException("Entity cannot be null");
if (cachedAttributes == null)
throw new MolgenisDataException("The attribute names are not defined, call writeAttributeNames first");
int i = 0;
Row poiRow = sheet.createRow(row++);
for (Attribute attribute : cachedAttributes) {
Cell cell = poiRow.createCell(i++, CellType.STRING);
cell.setCellValue(toValue(entity.get(attribute.getName())));
}
entity.getIdValue();
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class QueryGeneratorTest method setUp.
@BeforeMethod
public void setUp() {
refEntityType = entityTypeFactory.create("ref_entity");
refEntityType.addAttribute(attrFactory.create().setName(idAttrName), ROLE_ID);
refEntityType.addAttribute(attrFactory.create().setName(refStringAttrName).setUnique(true), ROLE_LABEL);
refEntityType.addAttribute(attrFactory.create().setName(refMrefAttrName).setDataType(MREF).setNillable(true).setRefEntity(refEntityType));
entityType = entityTypeFactory.create("entity");
entityType.addAttribute(attrFactory.create().setName(idAttrName), ROLE_ID);
entityType.addAttribute(attrFactory.create().setName(boolAttrName).setDataType(BOOL));
entityType.addAttribute(attrFactory.create().setName(categoricalAttrName).setDataType(CATEGORICAL).setRefEntity(refEntityType));
Attribute compoundAttr = attrFactory.create().setName(compoundAttrName).setDataType(COMPOUND);
Attribute compoundPart0Attr = attrFactory.create().setName(compoundPart0AttrName).setDataType(STRING).setParent(compoundAttr);
Attribute compoundPart1Attr = attrFactory.create().setName(compoundPart1AttrName).setDataType(STRING).setParent(compoundAttr);
entityType.addAttribute(compoundAttr).addAttribute(compoundPart0Attr).addAttribute(compoundPart1Attr);
entityType.addAttribute(attrFactory.create().setName(dateAttrName).setDataType(DATE));
entityType.addAttribute(attrFactory.create().setName(dateTimeAttrName).setDataType(DATE_TIME));
entityType.addAttribute(attrFactory.create().setName(decimalAttrName).setDataType(DECIMAL));
entityType.addAttribute(attrFactory.create().setName(emailAttrName).setDataType(EMAIL));
entityType.addAttribute(attrFactory.create().setName(enumAttrName).setDataType(ENUM).setEnumOptions(asList("enum0", "enum1", "enum2")));
entityType.addAttribute(attrFactory.create().setName(htmlAttrName).setDataType(HTML));
entityType.addAttribute(attrFactory.create().setName(hyperlinkAttrName).setDataType(HYPERLINK));
entityType.addAttribute(attrFactory.create().setName(intAttrName).setDataType(INT));
entityType.addAttribute(attrFactory.create().setName(longAttrName).setDataType(LONG));
entityType.addAttribute(attrFactory.create().setName(mrefAttrName).setDataType(MREF).setRefEntity(refEntityType));
entityType.addAttribute(attrFactory.create().setName(scriptAttrName).setDataType(SCRIPT));
entityType.addAttribute(attrFactory.create().setName(stringAttrName).setDataType(STRING));
entityType.addAttribute(attrFactory.create().setName(textAttrName).setDataType(TEXT));
entityType.addAttribute(attrFactory.create().setName(xrefAttrName).setDataType(XREF).setRefEntity(refEntityType));
DocumentIdGenerator documentIdGenerator = mock(DocumentIdGenerator.class);
when(documentIdGenerator.generateId(any(Attribute.class))).thenAnswer(invocation -> ((Attribute) invocation.getArguments()[0]).getName());
queryGenerator = new QueryGenerator(documentIdGenerator);
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class DocumentIdGeneratorTest method testGenerateIdAttribute.
@Test(dataProvider = "generateIdAttributeTypeProvider")
public void testGenerateIdAttribute(String entityTypeId, String attrId, String attrName, String expectedId) {
EntityType entityType = mock(EntityType.class);
when(entityType.getId()).thenReturn(entityTypeId);
Attribute attr = mock(Attribute.class);
when(attr.getEntity()).thenReturn(entityType);
when(attr.getIdentifier()).thenReturn(attrId);
when(attr.getName()).thenReturn(attrName);
String id = documentIdGenerator.generateId(attr);
assertEquals(id, expectedId);
}
Aggregations