Search in sources :

Example 11 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class EntityUtilsTest method getMockAttr.

private Attribute getMockAttr(String toString) {
    Attribute attr = getMockAttr();
    when(attr.toString()).thenReturn(toString);
    return attr;
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute)

Example 12 with Attribute

use of org.molgenis.data.meta.model.Attribute 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 13 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class EntityTypeUtilsTest method isMultipleReferenceTypeProvider.

@DataProvider(name = "isMultipleReferenceTypeProvider")
public static Iterator<Object[]> isMultipleReferenceTypeProvider() {
    List<Object[]> dataList = Lists.newArrayList();
    for (AttributeType attrType : AttributeType.values()) {
        Attribute attr = mock(Attribute.class);
        when(attr.getDataType()).thenReturn(attrType);
        when(attr.toString()).thenReturn("attr_" + attrType.toString());
        boolean isMultipleRefAttr = attrType == CATEGORICAL_MREF || attrType == MREF || attrType == ONE_TO_MANY;
        dataList.add(new Object[] { attr, isMultipleRefAttr });
    }
    return dataList.iterator();
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) AttributeType(org.molgenis.data.meta.AttributeType) DataProvider(org.testng.annotations.DataProvider)

Example 14 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class EntityTypeUtilsTest method getAttributeNames.

@Test
public void getAttributeNames() {
    Attribute attr0 = when(mock(Attribute.class).getName()).thenReturn("attr0").getMock();
    Attribute attr1 = when(mock(Attribute.class).getName()).thenReturn("attr1").getMock();
    assertEquals(newArrayList(EntityTypeUtils.getAttributeNames(asList(attr0, attr1))), asList("attr0", "attr1"));
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) Test(org.testng.annotations.Test)

Example 15 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class MapOfStringsExpressionEvaluatorTest method testMapOfStringsEvaluatorConstructorChecksIfAttributeHasRefEntity.

@Test
public void testMapOfStringsEvaluatorConstructorChecksIfAttributeHasRefEntity() {
    Attribute amd = when(mock(Attribute.class).getName()).thenReturn("location").getMock();
    when(amd.getDataType()).thenReturn(XREF);
    when(amd.getExpression()).thenReturn("{'a':b}");
    try {
        new MapOfStringsExpressionEvaluator(amd, emd);
        fail("Expected IllegalArgumentException.");
    } catch (NullPointerException expected) {
        assertEquals(expected.getMessage(), "refEntity not specified.");
    }
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

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