Search in sources :

Example 76 with DynamicEntity

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

the class JsMagmaScriptEvaluatorTest method combineGroupMapFunctions.

@Test
public void combineGroupMapFunctions() {
    Entity entity1 = new DynamicEntity(personAgeEntityType);
    entity1.set("age", 29);
    Object result1 = jsMagmaScriptEvaluator.eval("$('age').group([18, 35, 56]).map({'-18':'0','18-35':'1','35-56':'2','56+':'3'}).value();", entity1, 3);
    assertEquals(result1.toString(), "1");
    Entity entity2 = new DynamicEntity(personAgeEntityType);
    entity2.set("age", 17);
    Object result2 = jsMagmaScriptEvaluator.eval("$('age').group([18, 35, 56]).map({'-18':'0','18-35':'1','35-56':'2','56+':'3'}).value();", entity2, 3);
    assertEquals(result2.toString(), "0");
    Entity entity3 = new DynamicEntity(personAgeEntityType);
    entity3.set("age", 40);
    Object result3 = jsMagmaScriptEvaluator.eval("$('age').group([18, 35, 56]).map({'-18':'0','18-35':'1','35-56':'2','56+':'3'}).value();", entity3, 3);
    assertEquals(result3.toString(), "2");
    Entity entity4 = new DynamicEntity(personAgeEntityType);
    entity4.set("age", 70);
    Object result4 = jsMagmaScriptEvaluator.eval("$('age').group([18, 35, 56]).map({'-18':'0','18-35':'1','35-56':'2','56+':'3'}).value();", entity4, 3);
    assertEquals(result4.toString(), "3");
    Entity entity5 = new DynamicEntity(personAgeEntityType);
    entity5.set("age", 999);
    Object result5 = jsMagmaScriptEvaluator.eval("$('age').group([18, 35, 56], [999]).map({'-18':0,'18-35':1,'35-56':2,'56+':3,'999':'9'}).value();", entity5, 3);
    assertEquals(result5.toString(), "9");
}
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 77 with DynamicEntity

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

the class JsMagmaScriptEvaluatorTest method testTimes.

@Test
public void testTimes() {
    Entity entity0 = new DynamicEntity(personHeightEntityType);
    entity0.set("height", 2);
    Object result = jsMagmaScriptEvaluator.eval("$('height').times(100).value()", entity0, 3);
    assertEquals(result, (double) 200);
}
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 78 with DynamicEntity

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

the class JsMagmaScriptEvaluatorTest method testValueForXref.

@Test
public void testValueForXref() {
    Entity gender = new DynamicEntity(genderEntityType);
    gender.set("id", "1");
    gender.set("label", "male");
    Entity person = new DynamicEntity(personGenderEntityType);
    person.set("gender", gender);
    Object result = jsMagmaScriptEvaluator.eval("$('gender.label').value()", person, 3);
    assertEquals(result.toString(), "male");
}
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 79 with DynamicEntity

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

the class JsMagmaScriptEvaluatorTest method testValueForNestedXrefDefaultDepth.

@Test
public void testValueForNestedXrefDefaultDepth() {
    Entity gender = new DynamicEntity(genderEntityType);
    gender.set("id", "1");
    gender.set("label", "male");
    Entity person = new DynamicEntity(personGenderEntityType);
    person.set("gender", gender);
    Object scriptExceptionObj = jsMagmaScriptEvaluator.eval("$('gender.xref.label').value()", person);
    assertEquals(scriptExceptionObj.toString(), "org.molgenis.script.core.ScriptException: <eval>:502 TypeError: Cannot read property \"label\" from undefined");
}
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 80 with DynamicEntity

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

the class JsMagmaScriptEvaluatorTest method testGe.

@Test
public void testGe() {
    Entity person0 = new DynamicEntity(personWeightEntityType);
    person0.set("weight", null);
    String script = "$('weight').ge(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, false);
    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, true);
}
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