Search in sources :

Example 16 with Attribute

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

the class MapOfStringsExpressionEvaluatorTest method testMapOfStringsEvaluatorConstructorChecksThatExpressionIsMapOfStrings.

@Test
public void testMapOfStringsEvaluatorConstructorChecksThatExpressionIsMapOfStrings() {
    Attribute amd = when(mock(Attribute.class).getName()).thenReturn("#CHROM").getMock();
    when(amd.getDataType()).thenReturn(XREF);
    when(amd.getRefEntity()).thenReturn(refEmd);
    when(amd.getExpression()).thenReturn("{'Chromosome':{'hallo1':'bla'}}");
    try {
        new MapOfStringsExpressionEvaluator(amd, emd);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
        assertEquals(expected.getMessage(), "Nested expressions not supported, expression must be Map<String,String>.");
    }
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 17 with Attribute

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

the class StringExpressionEvaluatorTest method testStringEvaluatorLookupAttributeAndConvertFromIntToString.

@Test
public void testStringEvaluatorLookupAttributeAndConvertFromIntToString() {
    Attribute amd = when(mock(Attribute.class).getName()).thenReturn("#CHROM").getMock();
    when(amd.getDataType()).thenReturn(STRING);
    when(amd.getExpression()).thenReturn("Int");
    assertEquals(new StringExpressionEvaluator(amd, entityType).evaluate(entity), "1");
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 18 with Attribute

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

the class StringExpressionEvaluatorTest method createEntity.

@BeforeTest
public void createEntity() {
    entityType = when(mock(EntityType.class).getId()).thenReturn("Source").getMock();
    Attribute idAttr = when(mock(Attribute.class).getName()).thenReturn("Identifier").getMock();
    when(idAttr.getDataType()).thenReturn(INT);
    Attribute intAttr = when(mock(Attribute.class).getName()).thenReturn("Int").getMock();
    when(intAttr.getDataType()).thenReturn(INT);
    Attribute stringAttr = when(mock(Attribute.class).getName()).thenReturn("String").getMock();
    when(stringAttr.getDataType()).thenReturn(STRING);
    Attribute nonNumericStringAttr = when(mock(Attribute.class).getName()).thenReturn("NonNumericString").getMock();
    when(nonNumericStringAttr.getDataType()).thenReturn(STRING);
    Attribute longAttr = when(mock(Attribute.class).getName()).thenReturn("Long").getMock();
    when(longAttr.getDataType()).thenReturn(LONG);
    when(entityType.getIdAttribute()).thenReturn(idAttr);
    when(entityType.getId()).thenReturn("test");
    when(entityType.getAttribute("Identifier")).thenReturn(idAttr);
    when(entityType.getAttribute("Int")).thenReturn(intAttr);
    when(entityType.getAttribute("String")).thenReturn(stringAttr);
    when(entityType.getAttribute("NonNumericString")).thenReturn(nonNumericStringAttr);
    when(entityType.getAttribute("Long")).thenReturn(longAttr);
    entity = new DynamicEntity(entityType);
    entity.set("Int", 1);
    entity.set("String", "12");
    entity.set("Long", 10L);
    entity.set("NonNumericString", "Hello World!");
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) BeforeTest(org.testng.annotations.BeforeTest)

Example 19 with Attribute

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

the class StringExpressionEvaluatorTest method testStringEvaluatorLookupAttributeAndConvertFromStringToLong.

@Test
public void testStringEvaluatorLookupAttributeAndConvertFromStringToLong() {
    Attribute amd = when(mock(Attribute.class).getName()).thenReturn("#POS").getMock();
    when(amd.getDataType()).thenReturn(LONG);
    when(amd.getExpression()).thenReturn("String");
    assertEquals(new StringExpressionEvaluator(amd, entityType).evaluate(entity), 12L);
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 20 with Attribute

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

the class StringExpressionEvaluatorTest method testStringEvaluatorLookupAttributeAndConvertFromNonNumericStringToLongFails.

@Test(expectedExceptions = MolgenisDataException.class, expectedExceptionsMessageRegExp = "Conversion failure in entity type \\[test\\] attribute \\[id\\]; Failed to convert from type \\[java.lang.String\\] to type \\[java.lang.Long\\] for value 'Hello World!'; nested exception is java.lang.NumberFormatException: For input string: \"HelloWorld!\"")
public void testStringEvaluatorLookupAttributeAndConvertFromNonNumericStringToLongFails() {
    Attribute amd = when(mock(Attribute.class).getName()).thenReturn("#POS").getMock();
    when(amd.getName()).thenReturn("id");
    when(amd.getDataType()).thenReturn(LONG);
    when(amd.getExpression()).thenReturn("NonNumericString");
    when(amd.getEntity()).thenReturn(entityType);
    new StringExpressionEvaluator(amd, entityType).evaluate(entity);
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) BeforeTest(org.testng.annotations.BeforeTest) 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