Search in sources :

Example 81 with DynamicEntity

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

the class JsMagmaScriptEvaluatorTest method mapSimple.

@Test
public void mapSimple() {
    Entity gender = new DynamicEntity(genderEntityType);
    gender.set("id", "m");
    gender.set("label", "Male");
    Entity person = new DynamicEntity(personGenderEntityType);
    person.set("gender", gender);
    Object result = jsMagmaScriptEvaluator.eval("$('gender').map({'m':'Male'}).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 82 with DynamicEntity

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

the class JsMagmaScriptEvaluatorTest method testValueForXrefDefaultDepth.

@Test
public void testValueForXrefDefaultDepth() {
    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);
    assertEquals(result.toString(), "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 83 with DynamicEntity

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

the class JsMagmaScriptEvaluatorTest method testUnitConversion.

@Test
public void testUnitConversion() {
    Entity person = new DynamicEntity(personWeightEntityType);
    person.set("weight", 82);
    Object weight = jsMagmaScriptEvaluator.eval("$('weight').unit('kg').toUnit('poundmass').value()", person, 3);
    assertEquals(weight, 180.7790549915996);
}
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 84 with DynamicEntity

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

the class JsMagmaScriptEvaluatorTest method testIsNull.

@Test
public void testIsNull() {
    Entity person0 = new DynamicEntity(personWeightEntityType);
    person0.set("weight", null);
    String script = "$('weight').isNull().value()";
    Object result = jsMagmaScriptEvaluator.eval(script, person0, 3);
    assertEquals(result, true);
    Entity person1 = new DynamicEntity(personWeightEntityType);
    person1.set("weight", 99);
    result = jsMagmaScriptEvaluator.eval(script, person1, 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 85 with DynamicEntity

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

the class JsMagmaScriptEvaluatorTest method testNot.

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