Search in sources :

Example 66 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class JsMagmaScriptEvaluatorTest method testEvalDefaultDepth$.

@Test
public void testEvalDefaultDepth$() {
    Entity person = new DynamicEntity(personWeightEntityType);
    person.set("weight", 82);
    Object weight = jsMagmaScriptEvaluator.eval("$('weight').value()", person);
    assertEquals(weight, 82);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) Test(org.testng.annotations.Test)

Example 67 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class JsMagmaScriptEvaluatorTest method test$.

@Test
public void test$() {
    Entity person = new DynamicEntity(personWeightEntityType);
    person.set("weight", 82);
    Object weight = jsMagmaScriptEvaluator.eval("$('weight').value()", person, 3);
    assertEquals(weight, 82);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) Test(org.testng.annotations.Test)

Example 68 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class JsMagmaScriptEvaluatorTest method div.

@Test
public void div() {
    Entity entity0 = new DynamicEntity(personHeightEntityType);
    entity0.set("height", 200);
    Object result = jsMagmaScriptEvaluator.eval("$('height').div(100).value()", entity0, 3);
    assertEquals(result, 2d);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) Test(org.testng.annotations.Test)

Example 69 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class JsMagmaScriptEvaluatorTest method testPlusValue.

@Test
public void testPlusValue() {
    Entity entity0 = new DynamicEntity(personHeightEntityType);
    entity0.set("height", 180);
    Object result = jsMagmaScriptEvaluator.eval("$('height').plus(100).value()", entity0, 3);
    assertEquals(result, (double) 280);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) Test(org.testng.annotations.Test)

Example 70 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class JsMagmaScriptEvaluatorTest method testGlucose.

@Test
public void testGlucose() {
    Attribute idAttribute = mock(Attribute.class);
    when(idAttribute.getName()).thenReturn("id");
    when(idAttribute.getDataType()).thenReturn(STRING);
    Attribute gluc1Attr = when(mock(Attribute.class).getName()).thenReturn("GLUC_1").getMock();
    when(gluc1Attr.getDataType()).thenReturn(DECIMAL);
    EntityType personGlucoseMeta = when(mock(EntityType.class).getId()).thenReturn("glucose").getMock();
    when(personGlucoseMeta.getIdAttribute()).thenReturn(idAttribute);
    when(personGlucoseMeta.getAttribute("GLUC_1")).thenReturn(gluc1Attr);
    when(personGlucoseMeta.getAtomicAttributes()).thenReturn(singletonList(gluc1Attr));
    Entity glucose = new DynamicEntity(personGlucoseMeta);
    glucose.set("GLUC_1", 4.1);
    Object bmi = jsMagmaScriptEvaluator.eval("$('GLUC_1').div(100).value()", glucose, 3);
    DecimalFormat df = new DecimalFormat("#.####", new DecimalFormatSymbols(Locale.ENGLISH));
    assertEquals(df.format(bmi), df.format(4.1 / 100));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DecimalFormatSymbols(java.text.DecimalFormatSymbols) Attribute(org.molgenis.data.meta.model.Attribute) DynamicEntity(org.molgenis.data.support.DynamicEntity) DecimalFormat(java.text.DecimalFormat) Test(org.testng.annotations.Test)

Aggregations

DynamicEntity (org.molgenis.data.support.DynamicEntity)161 Entity (org.molgenis.data.Entity)123 Test (org.testng.annotations.Test)104 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)50 EntityType (org.molgenis.data.meta.model.EntityType)48 Attribute (org.molgenis.data.meta.model.Attribute)38 AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)14 BeforeMethod (org.testng.annotations.BeforeMethod)14 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)7 EntityMapping (org.molgenis.semanticmapper.mapping.model.EntityMapping)5 BeforeClass (org.testng.annotations.BeforeClass)5 ArrayList (java.util.ArrayList)4 MolgenisDataException (org.molgenis.data.MolgenisDataException)4 EntityWithComputedAttributes (org.molgenis.data.support.EntityWithComputedAttributes)4 ExplainedQueryString (org.molgenis.semanticsearch.explain.bean.ExplainedQueryString)4 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)4 StringWriter (java.io.StringWriter)3 List (java.util.List)3 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)3 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)3