use of net.n2oapp.framework.engine.data.json.TestDataProviderEngine in project n2o-framework by i-novus-llc.
the class InvocationProcessorTest method setUp.
@Before
public void setUp() throws Exception {
N2oInvocationFactory actionInvocationFactory = mock(N2oInvocationFactory.class);
javaDataProviderEngine = new JavaDataProviderEngine();
when(actionInvocationFactory.produce(N2oJavaDataProvider.class)).thenReturn(javaDataProviderEngine);
SqlInvocationEngine sqlInvocationEngine = new SqlInvocationEngine();
when(actionInvocationFactory.produce(N2oSqlDataProvider.class)).thenReturn(sqlInvocationEngine);
TestDataProviderEngine testDataProviderEngine = new TestDataProviderEngine();
when(actionInvocationFactory.produce(N2oTestDataProvider.class)).thenReturn(testDataProviderEngine);
ContextProcessor processor = mock(ContextProcessor.class);
when(processor.resolve(anyMap())).thenAnswer((Answer<DataSet>) invocation -> (DataSet) invocation.getArguments()[0]);
when(processor.resolve(anyString())).thenAnswer((Answer<String>) invocation -> (String) invocation.getArguments()[0]);
when(processor.resolve(anyInt())).thenAnswer((Answer<Integer>) invocation -> (Integer) invocation.getArguments()[0]);
when(processor.resolve(anyList())).thenAnswer((Answer<List>) invocation -> (List) invocation.getArguments()[0]);
when(processor.resolve(anyBoolean())).thenAnswer((Answer<Boolean>) invocation -> (Boolean) invocation.getArguments()[0]);
N2oEnvironment env = new N2oEnvironment();
env.setContextProcessor(processor);
invocationProcessor = new N2oInvocationProcessor(actionInvocationFactory);
invocationProcessor.setEnvironment(env);
}
use of net.n2oapp.framework.engine.data.json.TestDataProviderEngine in project n2o-framework by i-novus-llc.
the class CopyValuesControllerTest method testQuery.
private GetDataResponse testQuery(String path, ReadCompileTerminalPipeline<ReadCompileBindTerminalPipeline> pipeline, Map<String, String[]> params) {
N2oInvocationFactory invocationFactory = Mockito.mock(N2oInvocationFactory.class);
TestDataProviderEngine testDataProviderEngine = new TestDataProviderEngine();
testDataProviderEngine.setResourceLoader(new DefaultResourceLoader());
Mockito.when(invocationFactory.produce(Mockito.any(Class.class))).thenReturn(testDataProviderEngine);
ContextEngine contextEngine = Mockito.mock(ContextEngine.class);
UserContext userContext = new UserContext(contextEngine);
ContextProcessor contextProcessor = new ContextProcessor(userContext);
N2oQueryProcessor queryProcessor = new N2oQueryProcessor(invocationFactory, new N2oQueryExceptionHandler());
N2oEnvironment env = new N2oEnvironment();
env.setContextProcessor(contextProcessor);
queryProcessor.setEnvironment(env);
N2oSubModelsProcessor subModelsProcessor = Mockito.mock(N2oSubModelsProcessor.class);
Mockito.doNothing().when(subModelsProcessor);
DataProcessingStack dataProcessingStack = Mockito.mock(SpringDataProcessingStack.class);
CopyValuesController copyValuesController = new CopyValuesController(dataProcessingStack, queryProcessor, subModelsProcessor, null, null);
Map<String, Object> map = new HashMap<>();
map.put("CopyValuesController", copyValuesController);
N2oRouter router = new N2oRouter(builder.getEnvironment(), pipeline);
N2oControllerFactory factory = new N2oControllerFactory(map);
factory.setEnvironment(builder.getEnvironment());
DataController controller = new DataController(factory, builder.getEnvironment(), router);
return controller.getData(path, params, userContext);
}
use of net.n2oapp.framework.engine.data.json.TestDataProviderEngine in project n2o-framework by i-novus-llc.
the class DataControllerExceptionTest method buildController.
private DataController buildController(DataProcessingStack dataProcessingStack) {
N2oInvocationFactory invocationFactory = Mockito.mock(N2oInvocationFactory.class);
TestDataProviderEngine testDataProviderEngine = new TestDataProviderEngine();
testDataProviderEngine.setResourceLoader(new DefaultResourceLoader());
Mockito.when(invocationFactory.produce(Mockito.any(Class.class))).thenReturn(testDataProviderEngine);
N2oInvocationProcessor invocationProcessor = new N2oInvocationProcessor(invocationFactory);
N2oValidationModule validationModule = new N2oValidationModule(new ValidationProcessor(invocationProcessor));
Map<String, DataProcessing> moduleMap = new HashMap<>();
moduleMap.put("validationModule", validationModule);
N2oOperationProcessor operationProcessor = new N2oOperationProcessor(invocationProcessor, new N2oOperationExceptionHandler());
ApplicationContext context = Mockito.mock(ApplicationContext.class);
Mockito.when(context.getBeansOfType(DataProcessing.class)).thenReturn(moduleMap);
ReadCompileTerminalPipeline<ReadCompileBindTerminalPipeline> pipeline = compile("net/n2oapp/framework/ui/controller/testObject.object.xml", "net/n2oapp/framework/ui/controller/testPage.page.xml", "net/n2oapp/framework/ui/controller/testQuery.query.xml");
pipeline.get(new PageContext("testPage"));
N2oRouter router = new N2oRouter(builder.getEnvironment(), pipeline);
ContextEngine contextEngine = Mockito.mock(ContextEngine.class);
QueryProcessor queryProcessor = mock(QueryProcessor.class);
Map<String, Object> map = new HashMap<>();
AlertMessageBuilder messageBuilder = new AlertMessageBuilder(builder.getEnvironment().getMessageSource(), null);
OperationController operationController = new OperationController(dataProcessingStack, operationProcessor, messageBuilder, builder.getEnvironment());
QueryController queryController = new QueryController(dataProcessingStack, queryProcessor, null, messageBuilder, builder.getEnvironment());
map.put("operationController", operationController);
map.put("queryController", queryController);
N2oControllerFactory factory = new N2oControllerFactory(map);
factory.setEnvironment(builder.getEnvironment());
DataController controller = new DataController(factory, builder.getEnvironment(), router);
return controller;
}
use of net.n2oapp.framework.engine.data.json.TestDataProviderEngine in project n2o-framework by i-novus-llc.
the class DefaultValuesControllerTest method testQuery.
private GetDataResponse testQuery(String path, ReadCompileTerminalPipeline<ReadCompileBindTerminalPipeline> pipeline, Map<String, String[]> params) {
N2oInvocationFactory invocationFactory = Mockito.mock(N2oInvocationFactory.class);
TestDataProviderEngine testDataProviderEngine = new TestDataProviderEngine();
testDataProviderEngine.setResourceLoader(new DefaultResourceLoader());
Mockito.when(invocationFactory.produce(Mockito.any(Class.class))).thenReturn(testDataProviderEngine);
ContextEngine contextEngine = Mockito.mock(ContextEngine.class);
UserContext userContext = new UserContext(contextEngine);
ContextProcessor contextProcessor = new ContextProcessor(userContext);
N2oQueryProcessor queryProcessor = new N2oQueryProcessor(invocationFactory, new N2oQueryExceptionHandler());
N2oEnvironment env = new N2oEnvironment();
env.setContextProcessor(contextProcessor);
queryProcessor.setEnvironment(env);
N2oSubModelsProcessor subModelsProcessor = Mockito.mock(N2oSubModelsProcessor.class);
Mockito.doNothing().when(subModelsProcessor);
DataProcessingStack dataProcessingStack = Mockito.mock(SpringDataProcessingStack.class);
SimpleDefaultValuesController valuesController = new SimpleDefaultValuesController(dataProcessingStack, queryProcessor, subModelsProcessor, null, null);
Map<String, Object> map = new HashMap<>();
map.put("SimpleDefaultValuesController", valuesController);
N2oRouter router = new N2oRouter(builder.getEnvironment(), pipeline);
N2oControllerFactory factory = new N2oControllerFactory(map);
factory.setEnvironment(builder.getEnvironment());
DataController controller = new DataController(factory, builder.getEnvironment(), router);
return controller.getData(path, params, userContext);
}
use of net.n2oapp.framework.engine.data.json.TestDataProviderEngine in project n2o-framework by i-novus-llc.
the class QueryProcessorTest method query4Unique.
@Test
public void query4Unique() {
TestDataProviderEngine testDataprovider = new TestDataProviderEngine();
when(factory.produce(any())).thenReturn(testDataprovider);
CompiledQuery query = builder.read().compile().get(new QueryContext("testQueryProcessorUnique"));
// case unique selection
N2oPreparedCriteria criteria = new N2oPreparedCriteria();
criteria.setSize(1);
criteria.addRestriction(new Restriction("id", 1));
CollectionPage<DataSet> result = queryProcessor.execute(query, criteria);
assertThat(result.getCount(), is(1));
DataSet first = result.getCollection().iterator().next();
assertThat(first.get("id"), is(1L));
// case list filter by code selection
criteria = new N2oPreparedCriteria();
criteria.setSize(1);
criteria.addRestriction(new Restriction("code", "test1"));
result = queryProcessor.execute(query, criteria);
assertThat(result.getCount(), is(1));
first = result.getCollection().iterator().next();
assertThat(first.get("code"), is("test1"));
// case list any filters selection
criteria = new N2oPreparedCriteria();
criteria.setSize(1);
criteria.addRestriction(new Restriction("type", 10));
result = queryProcessor.execute(query, criteria);
assertThat(result.getCount(), is(1));
first = result.getCollection().iterator().next();
assertThat(first.get("type"), is(10));
}
Aggregations