Search in sources :

Example 1 with N2oJavaDataProvider

use of net.n2oapp.framework.api.metadata.dataprovider.N2oJavaDataProvider in project n2o-framework by i-novus-llc.

the class ObjectCompileTest method testCompileValidations.

@Test
public void testCompileValidations() {
    CompiledObject object = compile("net/n2oapp/framework/config/metadata/compile/object/utValidation.object.xml").get(new ObjectContext("utValidation"));
    assertThat(object.getValidations().size(), is(3));
    assertThat(object.getValidationsMap().get("v1").getId(), is("v1"));
    assertThat(object.getValidationsMap().get("v2").getId(), is("v2"));
    assertThat(object.getValidationsMap().get("v3").getId(), is("v3"));
    assertThat(object.getOperations().size(), is(2));
    CompiledObject.Operation all = object.getOperations().get("all");
    assertThat(all.getValidationList().size(), is(4));
    assertThat(all.getValidationsMap().get("val1"), instanceOf(ConstraintValidation.class));
    assertThat(all.getValidationsMap().get("v1"), instanceOf(ConditionValidation.class));
    assertThat(all.getValidationsMap().get("v2"), instanceOf(ConstraintValidation.class));
    assertThat(all.getValidationsMap().get("v3"), instanceOf(ValidationDialog.class));
    CompiledObject.Operation black = object.getOperations().get("black");
    assertThat(black.getValidationList().size(), is(2));
    assertThat(black.getValidationsMap().containsKey("v2"), is(true));
    assertThat(black.getValidationsMap().containsKey("v3"), is(true));
    N2oJavaDataProvider val1Provider = (N2oJavaDataProvider) ((ConstraintValidation) all.getValidationsMap().get("val1")).getInvocation();
    assertThat(val1Provider.getClassName(), is("TestService"));
    assertThat(val1Provider.getArguments()[0].getName(), is("arg1"));
    assertThat(val1Provider.getArguments()[0].getClassName(), is("TestEntity"));
    assertThat(val1Provider.getArguments()[0].getType(), is(Argument.Type.ENTITY));
    assertThat(val1Provider.getArguments()[1].getName(), is("arg2"));
    assertThat(val1Provider.getArguments()[1].getClassName(), is("EntityClass"));
    assertThat(val1Provider.getArguments()[1].getType(), is(Argument.Type.ENTITY));
    assertThat(val1Provider.getArguments()[2].getName(), is("arg3"));
    assertThat(val1Provider.getArguments()[2].getClassName(), nullValue());
    assertThat(val1Provider.getArguments()[2].getType(), is(Argument.Type.PRIMITIVE));
    N2oJavaDataProvider v2Provider = (N2oJavaDataProvider) ((ConstraintValidation) all.getValidationsMap().get("v2")).getInvocation();
    assertThat(v2Provider.getClassName(), is("TestService"));
    assertThat(v2Provider.getArguments()[0].getName(), is("arg1"));
    assertThat(v2Provider.getArguments()[0].getClassName(), is("TestEntity"));
    assertThat(v2Provider.getArguments()[0].getType(), is(Argument.Type.ENTITY));
    assertThat(v2Provider.getArguments()[1].getName(), is("arg2"));
    assertThat(v2Provider.getArguments()[1].getClassName(), is("EntityClass"));
    assertThat(v2Provider.getArguments()[1].getType(), is(Argument.Type.ENTITY));
    assertThat(v2Provider.getArguments()[2].getName(), is("arg3"));
    assertThat(v2Provider.getArguments()[2].getClassName(), nullValue());
    assertThat(v2Provider.getArguments()[2].getType(), is(Argument.Type.PRIMITIVE));
    N2oJavaDataProvider v3Provider = (N2oJavaDataProvider) ((ValidationDialog) all.getValidationsMap().get("v3")).getInvocation();
    assertThat(v3Provider.getClassName(), is("TestService"));
    assertThat(v3Provider.getArguments()[0].getName(), is("arg1"));
    assertThat(v3Provider.getArguments()[0].getClassName(), is("TestEntity"));
    assertThat(v3Provider.getArguments()[0].getType(), is(Argument.Type.ENTITY));
    assertThat(v3Provider.getArguments()[1].getName(), is("arg2"));
    assertThat(v3Provider.getArguments()[1].getClassName(), is("EntityClass"));
    assertThat(v3Provider.getArguments()[1].getType(), is(Argument.Type.ENTITY));
    assertThat(v3Provider.getArguments()[2].getName(), is("arg3"));
    assertThat(v3Provider.getArguments()[2].getClassName(), nullValue());
    assertThat(v3Provider.getArguments()[2].getType(), is(Argument.Type.PRIMITIVE));
}
Also used : N2oJavaDataProvider(net.n2oapp.framework.api.metadata.dataprovider.N2oJavaDataProvider) ConditionValidation(net.n2oapp.framework.api.data.validation.ConditionValidation) CompiledObject(net.n2oapp.framework.api.metadata.local.CompiledObject) ValidationDialog(net.n2oapp.framework.api.data.validation.ValidationDialog) ObjectContext(net.n2oapp.framework.config.metadata.compile.context.ObjectContext) ConstraintValidation(net.n2oapp.framework.api.data.validation.ConstraintValidation) Test(org.junit.Test)

Example 2 with N2oJavaDataProvider

use of net.n2oapp.framework.api.metadata.dataprovider.N2oJavaDataProvider in project n2o-framework by i-novus-llc.

the class InvocationProcessorTest method testNameMappingWithArgumentsInvocationProvider.

/**
 * Тестирование маппинга аргументов java провайдера с использованием name аргументов, а не через заданный порядок
 */
@Test
public void testNameMappingWithArgumentsInvocationProvider() {
    N2oJavaDataProvider invocation = new N2oJavaDataProvider();
    invocation.setClassName("net.n2oapp.framework.engine.test.source.StaticInvocationTestClass");
    invocation.setMethod("methodWithThreeArguments");
    Argument argument1 = new Argument();
    argument1.setName("first");
    argument1.setType(Argument.Type.PRIMITIVE);
    Argument argument2 = new Argument();
    argument2.setName("second");
    argument2.setType(Argument.Type.PRIMITIVE);
    Argument argument3 = new Argument();
    argument3.setName("third");
    argument3.setType(Argument.Type.PRIMITIVE);
    invocation.setArguments(new Argument[] { argument1, argument2, argument3 });
    // STRUCTURE
    ObjectSimpleField firstArg = new ObjectSimpleField();
    firstArg.setId("a");
    firstArg.setMapping("['first']");
    ObjectSimpleField secondArg = new ObjectSimpleField();
    secondArg.setId("b");
    secondArg.setMapping("[second]");
    ObjectSimpleField thirdArg = new ObjectSimpleField();
    thirdArg.setId("c");
    thirdArg.setMapping("['third']");
    List<AbstractParameter> inParameters = Arrays.asList(secondArg, firstArg, thirdArg);
    // DATASET
    DataSet dataSet = new DataSet();
    dataSet.put("c", true);
    dataSet.put("b", 123);
    dataSet.put("a", "test");
    ObjectSimpleField response = new ObjectSimpleField();
    response.setId("result");
    response.setMapping("#this");
    List<ObjectSimpleField> outParameters = Arrays.asList(response);
    // Result
    DataSet result = invocationProcessor.invoke(invocation, dataSet, inParameters, outParameters);
    assertThat(result.get("result"), is("Invocation success. First argument: test, Second argument: 123, Third argument: true"));
}
Also used : N2oJavaDataProvider(net.n2oapp.framework.api.metadata.dataprovider.N2oJavaDataProvider) ObjectSimpleField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSimpleField) Argument(net.n2oapp.framework.api.metadata.global.dao.invocation.model.Argument) DataSet(net.n2oapp.criteria.dataset.DataSet) AbstractParameter(net.n2oapp.framework.api.metadata.global.dao.object.AbstractParameter) Test(org.junit.Test)

Example 3 with N2oJavaDataProvider

use of net.n2oapp.framework.api.metadata.dataprovider.N2oJavaDataProvider in project n2o-framework by i-novus-llc.

the class InvocationProcessorTest method testAdvancedNestingWithArgumentsInvocationProvider.

@Test
public void testAdvancedNestingWithArgumentsInvocationProvider() {
    N2oJavaDataProvider invocation = new N2oJavaDataProvider();
    invocation.setClassName("net.n2oapp.framework.engine.test.source.StaticInvocationTestClass");
    invocation.setMethod("methodReturnedEntity");
    Argument argument = new Argument();
    argument.setClassName("net.n2oapp.framework.engine.util.TestEntity");
    argument.setType(Argument.Type.ENTITY);
    invocation.setArguments(new Argument[] { argument });
    // STRUCTURE
    // Simple
    ObjectSimpleField simpleParam = new ObjectSimpleField();
    simpleParam.setId("valueStr");
    simpleParam.setMapping("[0].valueStr");
    // List
    ObjectListField listParam = new ObjectListField();
    listParam.setId("entities");
    listParam.setMapping("[0].innerObjList");
    listParam.setEntityClass("net.n2oapp.framework.engine.util.TestEntity$InnerEntity");
    ObjectSimpleField childParam1 = new ObjectSimpleField();
    childParam1.setId("id");
    childParam1.setMapping("valueInt");
    ObjectSimpleField childParam2 = new ObjectSimpleField();
    childParam2.setId("name");
    childParam2.setMapping("valueStr");
    // List Set
    ObjectSetField setParam = new ObjectSetField();
    setParam.setId("set");
    setParam.setEntityClass("net.n2oapp.framework.engine.util.TestEntity$InnerEntity$InnerInnerEntity");
    setParam.setMapping("innerInnerObjSet");
    ObjectSimpleField setChildParam = new ObjectSimpleField();
    setChildParam.setId("name");
    setChildParam.setMapping("innerName");
    setParam.setFields(new AbstractParameter[] { setChildParam });
    listParam.setFields(new AbstractParameter[] { setParam, childParam2, childParam1 });
    // DATASET
    DataSet innerDataSet1 = new DataSet();
    innerDataSet1.put("id", 666);
    innerDataSet1.put("name", "testStr1");
    HashSet innerInnerDataSet = new HashSet();
    innerDataSet1.put("set", innerInnerDataSet);
    innerInnerDataSet.add(new DataSet("name", "code1"));
    innerInnerDataSet.add(new DataSet("name", "code2"));
    DataSet innerDataSet2 = new DataSet();
    innerDataSet2.put("id", 777);
    innerDataSet2.put("name", "testStr2");
    innerInnerDataSet = new HashSet();
    innerDataSet2.put("set", innerInnerDataSet);
    innerInnerDataSet.add(new DataSet("name", "code3"));
    List list = Arrays.asList(innerDataSet1, innerDataSet2);
    DataSet dataSet = new DataSet();
    dataSet.put("entities", list);
    dataSet.put("valueStr", "test");
    List<AbstractParameter> inParameters = Arrays.asList(listParam, simpleParam);
    List<ObjectSimpleField> outParameters = new ArrayList<>();
    // Result
    DataSet result = invocationProcessor.invoke(invocation, dataSet, inParameters, outParameters);
    assertThat(result.size(), is(2));
    assertThat(result.get("valueStr"), is("test"));
    List<TestEntity.InnerEntity> innerObjList = (List<TestEntity.InnerEntity>) result.get("entities");
    assertThat(innerObjList.size(), is(2));
    assertThat(innerObjList.get(0).getValueInt(), is(666));
    assertThat(innerObjList.get(0).getValueStr(), is("testStr1"));
    Set<TestEntity.InnerEntity.InnerInnerEntity> innerInnerObjSet = innerObjList.get(0).getInnerInnerObjSet();
    assertThat(innerInnerObjSet.size(), is(2));
    assertThat(innerInnerObjSet.contains(new TestEntity.InnerEntity.InnerInnerEntity("code1")), is(true));
    assertThat(innerInnerObjSet.contains(new TestEntity.InnerEntity.InnerInnerEntity("code2")), is(true));
    assertThat(innerObjList.get(1).getValueInt(), is(777));
    assertThat(innerObjList.get(1).getValueStr(), is("testStr2"));
    innerInnerObjSet = innerObjList.get(1).getInnerInnerObjSet();
    assertThat(innerInnerObjSet.size(), is(1));
    assertThat(innerInnerObjSet.contains(new TestEntity.InnerEntity.InnerInnerEntity("code3")), is(true));
}
Also used : N2oJavaDataProvider(net.n2oapp.framework.api.metadata.dataprovider.N2oJavaDataProvider) TestEntity(net.n2oapp.framework.engine.util.TestEntity) Argument(net.n2oapp.framework.api.metadata.global.dao.invocation.model.Argument) DataSet(net.n2oapp.criteria.dataset.DataSet) ObjectSimpleField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSimpleField) ObjectSetField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSetField) AbstractParameter(net.n2oapp.framework.api.metadata.global.dao.object.AbstractParameter) ObjectListField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectListField) Test(org.junit.Test)

Example 4 with N2oJavaDataProvider

use of net.n2oapp.framework.api.metadata.dataprovider.N2oJavaDataProvider in project n2o-framework by i-novus-llc.

the class InvocationProcessorTest method testNormalizing.

@Test
public void testNormalizing() {
    N2oJavaDataProvider method = new N2oJavaDataProvider();
    method.setMethod("methodReturnedEntity");
    method.setClassName("net.n2oapp.framework.engine.test.source.StaticInvocationTestClass");
    Argument entityTypeArgument = new Argument();
    entityTypeArgument.setClassName("net.n2oapp.framework.engine.util.TestEntity");
    entityTypeArgument.setType(Argument.Type.ENTITY);
    method.setArguments(new Argument[] { entityTypeArgument });
    ObjectSimpleField childParam = new ObjectSimpleField();
    childParam.setId("name");
    childParam.setMapping("[0].valueStr");
    childParam.setNormalize("#this.toLowerCase()");
    DataSet innerDataSet = new DataSet();
    innerDataSet.put("name", "TESTSTRING");
    ObjectSimpleField outField = new ObjectSimpleField();
    outField.setId("entity");
    outField.setMapping("#this");
    Collection<ObjectSimpleField> outMapping = Arrays.asList(outField);
    DataSet resultDataSet = invocationProcessor.invoke(method, innerDataSet, Arrays.asList(childParam), outMapping);
    assertThat(((TestEntity) resultDataSet.get("entity")).getValueStr(), is("teststring"));
}
Also used : N2oJavaDataProvider(net.n2oapp.framework.api.metadata.dataprovider.N2oJavaDataProvider) ObjectSimpleField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSimpleField) Argument(net.n2oapp.framework.api.metadata.global.dao.invocation.model.Argument) DataSet(net.n2oapp.criteria.dataset.DataSet) Test(org.junit.Test)

Example 5 with N2oJavaDataProvider

use of net.n2oapp.framework.api.metadata.dataprovider.N2oJavaDataProvider in project n2o-framework by i-novus-llc.

the class InvocationProcessorTest method fullMappingTest.

@Test
public void fullMappingTest() {
    N2oJavaDataProvider method = new N2oJavaDataProvider();
    method.setMethod("methodReturnedEntity");
    method.setClassName("net.n2oapp.framework.engine.test.source.StaticInvocationTestClass");
    Argument entityTypeArgument = new Argument();
    entityTypeArgument.setName("argument");
    entityTypeArgument.setClassName("net.n2oapp.framework.engine.util.TestEntity");
    entityTypeArgument.setType(Argument.Type.ENTITY);
    method.setArguments(new Argument[] { entityTypeArgument });
    DataSet dataSet = new DataSet();
    DataSet inDataSet = new DataSet();
    inDataSet.put("name", "testName");
    inDataSet.put("id", 123);
    dataSet.put("entity", inDataSet);
    List<DataSet> list = new ArrayList<>();
    inDataSet = new DataSet();
    inDataSet.put("id", 1234);
    inDataSet.put("name", "testName1");
    list.add(inDataSet);
    inDataSet = new DataSet();
    inDataSet.put("name", "testName2");
    inDataSet.put("id", 12345);
    list.add(inDataSet);
    dataSet.put("entities", list);
    List<AbstractParameter> inMapping = new ArrayList<>();
    ObjectReferenceField param = new ObjectReferenceField();
    param.setId("entity");
    param.setMapping("[0].innerObj");
    param.setEntityClass("net.n2oapp.framework.engine.util.TestEntity$InnerEntity");
    ObjectSimpleField inParam1 = new ObjectSimpleField();
    inParam1.setId("name");
    inParam1.setMapping("valueStr");
    ObjectSimpleField inParam2 = new ObjectSimpleField();
    inParam2.setId("id");
    inParam2.setMapping("valueInt");
    param.setFields(new AbstractParameter[] { inParam1, inParam2 });
    inMapping.add(param);
    ObjectListField listParam = new ObjectListField();
    listParam.setId("entities");
    listParam.setMapping("[0].innerObjList");
    listParam.setEntityClass("net.n2oapp.framework.engine.util.TestEntity$InnerEntity");
    inParam1 = new ObjectSimpleField();
    inParam1.setId("name");
    inParam1.setMapping("valueStr");
    inParam1.setDefaultValue("testName1");
    inParam1.setNormalize("#this.toLowerCase()");
    inParam2 = new ObjectSimpleField();
    inParam2.setId("id");
    inParam2.setMapping("valueInt");
    listParam.setFields(new AbstractParameter[] { inParam1, inParam2 });
    inMapping.add(listParam);
    List<ObjectSimpleField> outMapping = new ArrayList<>();
    ObjectSimpleField outParam = new ObjectSimpleField();
    outParam.setId("testValue");
    outParam.setMapping("#this");
    outMapping.add(outParam);
    DataSet resultDataSet = invocationProcessor.invoke(method, dataSet, inMapping, outMapping);
    assertThat(resultDataSet.size(), is(3));
    assertThat(((TestEntity.InnerEntity) resultDataSet.get("entity")).getValueInt(), is(123));
    assertThat(((TestEntity.InnerEntity) resultDataSet.get("entity")).getValueStr(), is("testName"));
    assertThat(((List<TestEntity.InnerEntity>) resultDataSet.get("entities")).get(0).getValueStr(), is("testname1"));
    assertThat(((List<TestEntity.InnerEntity>) resultDataSet.get("entities")).get(1).getValueInt(), is(12345));
    assertThat(((List<TestEntity.InnerEntity>) resultDataSet.get("entities")).get(1).getValueStr(), is("testname2"));
}
Also used : N2oJavaDataProvider(net.n2oapp.framework.api.metadata.dataprovider.N2oJavaDataProvider) TestEntity(net.n2oapp.framework.engine.util.TestEntity) ObjectReferenceField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectReferenceField) Argument(net.n2oapp.framework.api.metadata.global.dao.invocation.model.Argument) DataSet(net.n2oapp.criteria.dataset.DataSet) ObjectSimpleField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSimpleField) AbstractParameter(net.n2oapp.framework.api.metadata.global.dao.object.AbstractParameter) ObjectListField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectListField) Test(org.junit.Test)

Aggregations

N2oJavaDataProvider (net.n2oapp.framework.api.metadata.dataprovider.N2oJavaDataProvider)23 Test (org.junit.Test)23 Argument (net.n2oapp.framework.api.metadata.global.dao.invocation.model.Argument)17 DataSet (net.n2oapp.criteria.dataset.DataSet)8 ObjectSimpleField (net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSimpleField)8 SpringProvider (net.n2oapp.framework.api.metadata.dataprovider.SpringProvider)6 AbstractParameter (net.n2oapp.framework.api.metadata.global.dao.object.AbstractParameter)6 TestEntity (net.n2oapp.framework.engine.util.TestEntity)4 ObjectReferenceField (net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectReferenceField)3 ObjectListField (net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectListField)2 CompiledObject (net.n2oapp.framework.api.metadata.local.CompiledObject)2 ObjectContext (net.n2oapp.framework.config.metadata.compile.context.ObjectContext)2 StaticInvocationTestClass (net.n2oapp.framework.engine.test.source.StaticInvocationTestClass)2 ConditionValidation (net.n2oapp.framework.api.data.validation.ConditionValidation)1 ConstraintValidation (net.n2oapp.framework.api.data.validation.ConstraintValidation)1 ValidationDialog (net.n2oapp.framework.api.data.validation.ValidationDialog)1 ObjectSetField (net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSetField)1 SpringInvocationTestClass (net.n2oapp.framework.engine.test.source.SpringInvocationTestClass)1