Search in sources :

Example 71 with DynamicEntity

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

the class JsMagmaScriptEvaluatorTest method testValueForMrefWithComplexAlgorithm.

@Test
public void testValueForMrefWithComplexAlgorithm() {
    Entity trait = new DynamicEntity(traitEntityType);
    trait.set("id", "1");
    trait.set("name", "Hello");
    Entity person = new DynamicEntity(personTraitEntityType);
    person.set("id", "1");
    person.set("trait", singletonList(trait));
    Object result = jsMagmaScriptEvaluator.eval("var result = [];$('trait').map(function (entity) {result.push(entity.val.name)});result", person, 3);
    assertEquals(result.toString(), "[Hello]");
}
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 72 with DynamicEntity

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

the class JsMagmaScriptEvaluatorTest method combinePlusGroupMapFunctions.

@Test
public void combinePlusGroupMapFunctions() {
    Attribute idAttribute = mock(Attribute.class);
    when(idAttribute.getName()).thenReturn("id");
    when(idAttribute.getDataType()).thenReturn(STRING);
    Attribute food59Attr = when(mock(Attribute.class).getName()).thenReturn("FOOD59A1").getMock();
    when(food59Attr.getDataType()).thenReturn(INT);
    Attribute food60Attr = when(mock(Attribute.class).getName()).thenReturn("FOOD60A1").getMock();
    when(food60Attr.getDataType()).thenReturn(INT);
    EntityType foodPersonEntityType = when(mock(EntityType.class).getId()).thenReturn("person").getMock();
    when(foodPersonEntityType.getIdAttribute()).thenReturn(idAttribute);
    when(foodPersonEntityType.getAttribute("FOOD59A1")).thenReturn(food59Attr);
    when(foodPersonEntityType.getAttribute("FOOD60A1")).thenReturn(food60Attr);
    when(foodPersonEntityType.getAtomicAttributes()).thenReturn(asList(food59Attr, food60Attr));
    Entity entity0 = new DynamicEntity(foodPersonEntityType);
    entity0.set("FOOD59A1", 7);
    entity0.set("FOOD60A1", 6);
    Object result1 = jsMagmaScriptEvaluator.eval("var SUM_WEIGHT = new newValue(0);SUM_WEIGHT.plus($('FOOD59A1').map({\"1\":0,\"2\":0.2,\"3\":0.6,\"4\":1,\"5\":2.5,\"6\":4.5,\"7\":6.5}, null, null).value());SUM_WEIGHT.plus($('FOOD60A1').map({\"1\":0,\"2\":0.2,\"3\":0.6,\"4\":1,\"5\":2.5,\"6\":4.5,\"7\":6.5}, null, null).value());SUM_WEIGHT.group([0,1,2,6,7]).map({\"0-1\":\"4\",\"1-2\":\"3\",\"2-6\":\"2\",\"6-7\":\"1\", \"7+\" : \"1\"},null,null).value();", entity0, 3);
    assertEquals(result1.toString(), "1");
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) Attribute(org.molgenis.data.meta.model.Attribute) DynamicEntity(org.molgenis.data.support.DynamicEntity) Test(org.testng.annotations.Test)

Example 73 with DynamicEntity

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

the class JsMagmaScriptEvaluatorTest method age.

@Test
public void age() {
    Entity person = new DynamicEntity(personBirthDateMeta);
    person.set("birthdate", now().atOffset(UTC).toLocalDate());
    Object result = jsMagmaScriptEvaluator.eval("$('birthdate').age().value()", person, 3);
    assertEquals(result, 0d);
}
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 74 with DynamicEntity

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

the class JsMagmaScriptEvaluatorTest method testLe.

@Test
public void testLe() {
    Entity person0 = new DynamicEntity(personWeightEntityType);
    person0.set("weight", null);
    String script = "$('weight').le(100).value()";
    Object result = jsMagmaScriptEvaluator.eval(script, person0, 3);
    assertEquals(result, false);
    Entity person1 = new DynamicEntity(personWeightEntityType);
    person1.set("weight", 99);
    result = jsMagmaScriptEvaluator.eval(script, person1, 3);
    assertEquals(result, true);
    Entity person2 = new DynamicEntity(personWeightEntityType);
    person2.set("weight", 100);
    result = jsMagmaScriptEvaluator.eval(script, person2, 3);
    assertEquals(result, true);
    Entity person3 = new DynamicEntity(personWeightEntityType);
    person3.set("weight", 101);
    result = jsMagmaScriptEvaluator.eval(script, person3, 3);
    assertEquals(result, false);
}
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 75 with DynamicEntity

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

the class JsMagmaScriptEvaluatorTest method testPlusObject.

@Test
public void testPlusObject() {
    Entity entity0 = new DynamicEntity(personHeightEntityType);
    entity0.set("height", 180);
    Object result1 = jsMagmaScriptEvaluator.eval("$('height').plus(new newValue(100)).value()", entity0, 3);
    assertEquals(result1, (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)

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