Search in sources :

Example 31 with Attribute

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();
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) Test(org.testng.annotations.Test)

Example 32 with Attribute

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();
        }
    });
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Entity(org.molgenis.data.Entity) Attribute(org.molgenis.data.meta.model.Attribute) RepositoryCapability(org.molgenis.data.RepositoryCapability) BeforeTest(org.testng.annotations.BeforeTest)

Example 33 with Attribute

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();
}
Also used : MolgenisDataException(org.molgenis.data.MolgenisDataException) Attribute(org.molgenis.data.meta.model.Attribute) Row(org.apache.poi.ss.usermodel.Row) Cell(org.apache.poi.ss.usermodel.Cell)

Example 34 with Attribute

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);
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 35 with Attribute

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);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) Test(org.testng.annotations.Test)

Aggregations

Attribute (org.molgenis.data.meta.model.Attribute)600 Test (org.testng.annotations.Test)351 EntityType (org.molgenis.data.meta.model.EntityType)321 Entity (org.molgenis.data.Entity)109 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)54 DynamicEntity (org.molgenis.data.support.DynamicEntity)53 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)47 Stream (java.util.stream.Stream)39 AttributeType (org.molgenis.data.meta.AttributeType)34 QueryImpl (org.molgenis.data.support.QueryImpl)29 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)29 UnexpectedEnumException (org.molgenis.util.UnexpectedEnumException)28 BeforeMethod (org.testng.annotations.BeforeMethod)20 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)18 WithMockUser (org.springframework.security.test.context.support.WithMockUser)18 Collectors.toList (java.util.stream.Collectors.toList)17 Relation (org.molgenis.data.semantic.Relation)17 Objects.requireNonNull (java.util.Objects.requireNonNull)16 MolgenisDataException (org.molgenis.data.MolgenisDataException)16 Package (org.molgenis.data.meta.model.Package)16