Search in sources :

Example 1 with N2oTestDataProvider

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

the class ValidationDialogCompileTest method testValidationDialog.

@Test
public void testValidationDialog() {
    CompiledObject object = compile("net/n2oapp/framework/config/metadata/compile/object/validation/testValidationDialog.object.xml").get(new ObjectContext("testValidationDialog"));
    List<Validation> validations = object.getValidations();
    assertThat(validations.size(), is(2));
    assertThat(validations.get(0).getId(), is("dialog1"));
    assertThat(validations.get(0).getMoment(), is(N2oValidation.ServerMoment.afterFailOperation));
    assertThat(validations.get(0).getMessage(), is("message"));
    N2oTestDataProvider invocation = (N2oTestDataProvider) ((ValidationDialog) validations.get(0)).getInvocation();
    assertThat(invocation.getOperation(), is(N2oTestDataProvider.Operation.create));
    assertThat(invocation.getFile(), is("test.json"));
    List<AbstractParameter> inParametersList = ((ValidationDialog) validations.get(0)).getInParametersList();
    assertThat(inParametersList.size(), is(3));
    List<ObjectSimpleField> outParametersList = ((ValidationDialog) validations.get(0)).getOutParametersList();
    assertThat(outParametersList.size(), is(2));
    assertThat(outParametersList.get(0).getId(), is("name"));
    assertThat(outParametersList.get(1).getId(), is("validation"));
    assertThat(outParametersList.get(1).getMapping(), is("name=='test'"));
    N2oDialog dialog = ((ValidationDialog) validations.get(0)).getDialog();
    assertThat(dialog.getId(), is("dialog1"));
    assertThat(dialog.getTitle(), is("title"));
    assertThat(dialog.getDescription(), is("message"));
    assertThat(dialog.getSize(), is("sm"));
    N2oToolbar toolbar = dialog.getToolbar();
    assertThat(toolbar.getItems().length, is(2));
    assertThat(((N2oButton) toolbar.getItems()[0]).getLabel(), is("Yes"));
    assertThat(((N2oButton) toolbar.getItems()[0]).getAction(), instanceOf(N2oInvokeAction.class));
    assertThat(((N2oButton) toolbar.getItems()[1]).getAction(), instanceOf(N2oCloseAction.class));
    assertThat(validations.get(1).getId(), is("dialog2"));
    assertThat(validations.get(1).getSeverity(), is(SeverityType.danger));
    assertThat(validations.get(1).getMoment(), is(N2oValidation.ServerMoment.afterSuccessOperation));
    outParametersList = ((ValidationDialog) validations.get(1)).getOutParametersList();
    assertThat(outParametersList.size(), is(1));
    assertThat(outParametersList.get(0).getId(), is("validation"));
    assertThat(outParametersList.get(0).getMapping(), nullValue());
}
Also used : N2oValidation(net.n2oapp.framework.api.metadata.global.dao.validation.N2oValidation) Validation(net.n2oapp.framework.api.data.validation.Validation) CompiledObject(net.n2oapp.framework.api.metadata.local.CompiledObject) ValidationDialog(net.n2oapp.framework.api.data.validation.ValidationDialog) N2oCloseAction(net.n2oapp.framework.api.metadata.event.action.N2oCloseAction) N2oInvokeAction(net.n2oapp.framework.api.metadata.event.action.N2oInvokeAction) N2oTestDataProvider(net.n2oapp.framework.api.metadata.dataprovider.N2oTestDataProvider) ObjectSimpleField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSimpleField) N2oDialog(net.n2oapp.framework.api.metadata.global.view.page.N2oDialog) N2oToolbar(net.n2oapp.framework.api.metadata.global.view.widget.toolbar.N2oToolbar) ObjectContext(net.n2oapp.framework.config.metadata.compile.context.ObjectContext) AbstractParameter(net.n2oapp.framework.api.metadata.global.dao.object.AbstractParameter) Test(org.junit.Test)

Example 2 with N2oTestDataProvider

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

the class InvocationProcessorTest method testAdvancedNestingWithMapInvocationProvider.

@Test
public void testAdvancedNestingWithMapInvocationProvider() {
    N2oTestDataProvider invocation = new N2oTestDataProvider();
    invocation.setOperation(N2oTestDataProvider.Operation.echo);
    // STRUCTURE
    // Reference
    ObjectReferenceField refParam = new ObjectReferenceField();
    refParam.setId("entity");
    refParam.setEntityClass("net.n2oapp.framework.engine.util.TestEntity");
    refParam.setMapping("['refEntity']");
    // Simple
    ObjectSimpleField simpleParam = new ObjectSimpleField();
    simpleParam.setId("valueStr");
    // List
    ObjectListField listParam = new ObjectListField();
    listParam.setId("entities");
    listParam.setMapping("['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[] { childParam1, childParam2, setParam });
    refParam.setFields(new AbstractParameter[] { simpleParam, listParam });
    // 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 refParamFields = new DataSet();
    refParamFields.put("entities", list);
    refParamFields.put("valueStr", "test");
    DataSet dataSet = new DataSet();
    dataSet.put("entity", refParamFields);
    List<AbstractParameter> inParameters = Arrays.asList(refParam);
    List<ObjectSimpleField> outParameters = new ArrayList<>();
    // Result
    DataSet result = invocationProcessor.invoke(invocation, dataSet, inParameters, outParameters);
    TestEntity entity = (TestEntity) result.get("entity");
    assertThat(entity.getValueInt(), nullValue());
    assertThat(entity.getInnerObj(), nullValue());
    assertThat(entity.getValueStr(), is("test"));
    List<TestEntity.InnerEntity> innerObjList = entity.getInnerObjList();
    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 : TestEntity(net.n2oapp.framework.engine.util.TestEntity) ObjectReferenceField(net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectReferenceField) DataSet(net.n2oapp.criteria.dataset.DataSet) N2oTestDataProvider(net.n2oapp.framework.api.metadata.dataprovider.N2oTestDataProvider) 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 3 with N2oTestDataProvider

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

the class TestDataProviderEngineTest method testFiltersLongValues.

@Test
public void testFiltersLongValues() {
    TestDataProviderEngine engine = new TestDataProviderEngine();
    engine.setResourceLoader(new DefaultResourceLoader());
    N2oTestDataProvider provider = new N2oTestDataProvider();
    provider.setFile("testLongValues.json");
    Map<String, Object> inParams = new LinkedHashMap<>();
    inParams.put("sorting", new ArrayList<>());
    inParams.put("filters", Arrays.asList("id :eq :id"));
    inParams.put("id", 1);
    inParams.put("limit", 10);
    inParams.put("offset", 0);
    inParams.put("page", 1);
    // Фильтр по id "eq"
    // запись типа Integer
    List<Map> result = (List<Map>) engine.invoke(provider, inParams);
    assertThat(result.size(), is(1));
    assertThat(result.get(0).get("id"), is(1L));
    // Фильтр по id "eq"
    // запись типа Long
    inParams.put("id", 9223372036854775807L);
    result = (List<Map>) engine.invoke(provider, inParams);
    assertThat(result.size(), is(1));
    assertThat(result.get(0).get("id"), is(9223372036854775807L));
    // Фильтр по date "eq"
    // запись типа Date
    inParams.put("date", "02.03.2000 00:00:00");
    inParams.put("filters", Arrays.asList("date :eq :date"));
    result = (List<Map>) engine.invoke(provider, inParams);
    assertThat(result.size(), is(1));
    assertThat(result.get(0).get("date"), is("02.03.2000 00:00:00"));
    // Фильтр по id "less"
    inParams.remove("date");
    inParams.put("id", 9223372036854775807L);
    inParams.put("filters", Arrays.asList("id :less :id"));
    result = (List<Map>) engine.invoke(provider, inParams);
    assertThat(result.size(), is(1));
    assertThat(result.get(0).get("id"), is(1L));
    // Фильтр по id "more"
    inParams.put("id", 1);
    inParams.put("filters", Arrays.asList("id :more :id"));
    result = (List<Map>) engine.invoke(provider, inParams);
    assertThat(result.size(), is(1));
    assertThat(result.get(0).get("id"), is(9223372036854775807L));
    // Фильтр по id "id"
    inParams.put("id", Arrays.asList(9223372036854775807L));
    inParams.put("filters", Arrays.asList("id :in :id"));
    result = (List<Map>) engine.invoke(provider, inParams);
    assertThat(result.size(), is(1));
    assertThat(result.get(0).get("id"), is(9223372036854775807L));
    // Фильтр по id "id"
    inParams.put("id", Arrays.asList(1));
    inParams.put("filters", Arrays.asList("id :in :id"));
    result = (List<Map>) engine.invoke(provider, inParams);
    assertThat(result.size(), is(1));
    assertThat(result.get(0).get("id"), is(1L));
}
Also used : N2oTestDataProvider(net.n2oapp.framework.api.metadata.dataprovider.N2oTestDataProvider) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Test(org.junit.Test)

Example 4 with N2oTestDataProvider

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

the class TestDataProviderEngineTest method testCreateOnReadonlyFile.

@Test
public void testCreateOnReadonlyFile() throws IOException {
    TestDataProviderEngine engine = new TestDataProviderEngine();
    engine.setResourceLoader(new DefaultResourceLoader());
    engine.setPathOnDisk(testFolder.getRoot() + "/");
    engine.setReadonly(true);
    N2oTestDataProvider provider = new N2oTestDataProvider();
    provider.setFile(testFile.getName());
    // Добавление новых данных
    provider.setOperation(create);
    Map<String, Object> inParamsForCreate = new LinkedHashMap<>();
    inParamsForCreate.put("id", 9L);
    inParamsForCreate.put("name", "test9");
    inParamsForCreate.put("type", "9");
    engine.invoke(provider, inParamsForCreate);
    ObjectMapper objectMapper = new ObjectMapper();
    TypeFactory typeFactory = objectMapper.getTypeFactory();
    CollectionType collectionType = typeFactory.constructCollectionType(List.class, HashMap.class);
    List<Map> result = objectMapper.readValue(testFile, collectionType);
    // Проверяем, что новые данные не записались в файл
    assertThat(result.size(), is(1));
    provider.setOperation(count);
    Map<String, Object> inParams = Collections.emptyMap();
    Integer resultCount = (Integer) engine.invoke(provider, inParams);
    assertThat(resultCount, is(2));
}
Also used : N2oTestDataProvider(net.n2oapp.framework.api.metadata.dataprovider.N2oTestDataProvider) CollectionType(com.fasterxml.jackson.databind.type.CollectionType) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Test(org.junit.Test)

Example 5 with N2oTestDataProvider

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

the class TestDataProviderEngineTest method testCountAfterChangeInFile.

@Test
public void testCountAfterChangeInFile() throws IOException {
    TestDataProviderEngine engine = new TestDataProviderEngine();
    engine.setResourceLoader(new DefaultResourceLoader());
    engine.setPathOnDisk(testFolder.getRoot() + "/");
    N2oTestDataProvider provider = new N2oTestDataProvider();
    provider.setFile(testFile.getName());
    // Проверка исходных данных в файле
    List<Map> result = (List<Map>) engine.invoke(provider, new LinkedHashMap<>());
    assertThat(result.size(), is(1));
    assertThat(result.get(0).get("id"), is(1L));
    assertThat(result.get(0).get("name"), is("test1"));
    assertThat(result.get(0).get("type"), is("1"));
    // Добавление новых данных
    FileWriter fileWriter = new FileWriter(testFile);
    fileWriter.write("[" + "{\"id\":9, \"name\":\"test9\", \"type\":\"9\"}," + "{\"id\":8, \"name\":\"test8\", \"type\":\"8\"}," + "{\"id\":1, \"name\":\"test1\", \"type\":\"1\"}" + "]");
    fileWriter.close();
    // Проверка, что после изменения json, количество записей корректно
    provider.setOperation(count);
    Map<String, Object> inParams = new LinkedHashMap<>();
    inParams.put("filters", Collections.emptyList());
    Integer resultCount = (Integer) engine.invoke(provider, inParams);
    assertThat(resultCount, is(3));
}
Also used : N2oTestDataProvider(net.n2oapp.framework.api.metadata.dataprovider.N2oTestDataProvider) FileWriter(java.io.FileWriter) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Test(org.junit.Test)

Aggregations

N2oTestDataProvider (net.n2oapp.framework.api.metadata.dataprovider.N2oTestDataProvider)36 Test (org.junit.Test)35 DefaultResourceLoader (org.springframework.core.io.DefaultResourceLoader)32 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)9 CollectionType (com.fasterxml.jackson.databind.type.CollectionType)9 TypeFactory (com.fasterxml.jackson.databind.type.TypeFactory)9 FileWriter (java.io.FileWriter)6 SimpleDateFormat (java.text.SimpleDateFormat)5 AbstractParameter (net.n2oapp.framework.api.metadata.global.dao.object.AbstractParameter)3 ObjectSimpleField (net.n2oapp.framework.api.metadata.global.dao.object.field.ObjectSimpleField)3 DataSet (net.n2oapp.criteria.dataset.DataSet)2 Validation (net.n2oapp.framework.api.data.validation.Validation)2 N2oValidation (net.n2oapp.framework.api.metadata.global.dao.validation.N2oValidation)2 CompiledObject (net.n2oapp.framework.api.metadata.local.CompiledObject)2 ObjectContext (net.n2oapp.framework.config.metadata.compile.context.ObjectContext)2 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 LocalDate (java.time.LocalDate)1