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());
}
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));
}
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));
}
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));
}
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));
}
Aggregations