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