Search in sources :

Example 1 with DataProcessingStack

use of net.n2oapp.framework.engine.modules.stack.DataProcessingStack 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);
}
Also used : N2oInvocationFactory(net.n2oapp.framework.engine.data.N2oInvocationFactory) CopyValuesController(net.n2oapp.framework.ui.controller.query.CopyValuesController) SpringDataProcessingStack(net.n2oapp.framework.engine.modules.stack.SpringDataProcessingStack) DataProcessingStack(net.n2oapp.framework.engine.modules.stack.DataProcessingStack) HashMap(java.util.HashMap) UserContext(net.n2oapp.framework.api.user.UserContext) N2oSubModelsProcessor(net.n2oapp.framework.config.util.N2oSubModelsProcessor) TestDataProviderEngine(net.n2oapp.framework.engine.data.json.TestDataProviderEngine) ContextEngine(net.n2oapp.framework.api.context.ContextEngine) N2oQueryProcessor(net.n2oapp.framework.engine.data.N2oQueryProcessor) N2oEnvironment(net.n2oapp.framework.config.compile.pipeline.N2oEnvironment) N2oRouter(net.n2oapp.framework.config.register.route.N2oRouter) ContextProcessor(net.n2oapp.framework.api.context.ContextProcessor) N2oQueryExceptionHandler(net.n2oapp.framework.engine.data.N2oQueryExceptionHandler) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader)

Example 2 with DataProcessingStack

use of net.n2oapp.framework.engine.modules.stack.DataProcessingStack 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);
}
Also used : N2oInvocationFactory(net.n2oapp.framework.engine.data.N2oInvocationFactory) SpringDataProcessingStack(net.n2oapp.framework.engine.modules.stack.SpringDataProcessingStack) DataProcessingStack(net.n2oapp.framework.engine.modules.stack.DataProcessingStack) SimpleDefaultValuesController(net.n2oapp.framework.ui.controller.query.SimpleDefaultValuesController) HashMap(java.util.HashMap) UserContext(net.n2oapp.framework.api.user.UserContext) N2oSubModelsProcessor(net.n2oapp.framework.config.util.N2oSubModelsProcessor) TestDataProviderEngine(net.n2oapp.framework.engine.data.json.TestDataProviderEngine) ContextEngine(net.n2oapp.framework.api.context.ContextEngine) N2oQueryProcessor(net.n2oapp.framework.engine.data.N2oQueryProcessor) N2oEnvironment(net.n2oapp.framework.config.compile.pipeline.N2oEnvironment) N2oRouter(net.n2oapp.framework.config.register.route.N2oRouter) ContextProcessor(net.n2oapp.framework.api.context.ContextProcessor) N2oQueryExceptionHandler(net.n2oapp.framework.engine.data.N2oQueryExceptionHandler) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader)

Example 3 with DataProcessingStack

use of net.n2oapp.framework.engine.modules.stack.DataProcessingStack in project n2o-framework by i-novus-llc.

the class DataControllerExceptionTest method testSetData.

@Test
public void testSetData() {
    DataProcessingStack dataProcessingStack = mock(DataProcessingStack.class);
    Exception e = new N2oException("Message");
    doThrow(e).when(dataProcessingStack).processAction(any(ActionRequestInfo.class), any(ActionResponseInfo.class), any(DataSet.class));
    DataController controller = buildController(dataProcessingStack);
    SetDataResponse response = controller.setData("/page/create", null, null, new DataSet(), null);
    assertThat(response.getMeta().getAlert().getAlertKey(), is("page_main"));
    assertThat(response.getMeta().getAlert().getMessages().get(0).getColor(), is("danger"));
    assertThat(response.getMeta().getAlert().getMessages().get(0).getStacktrace().get(0), is("net.n2oapp.framework.api.exception.N2oException: Message"));
    List<ValidationMessage> messages = new ArrayList<>();
    messages.add(new ValidationMessage("message1", "field1", "validation1"));
    messages.add(new ValidationMessage("message2", "field2", "validation2"));
    e = new N2oValidationException("Validation exception", "widget", messages, "messageForm");
    doThrow(e).when(dataProcessingStack).processAction(any(ActionRequestInfo.class), any(ActionResponseInfo.class), any(DataSet.class));
    response = controller.setData("/page/create", null, null, new DataSet(), null);
    assertThat(response.getMeta().getMessages().getForm(), is("page_main"));
    assertThat(response.getMeta().getMessages().getFields().size(), is(2));
    assertThat(response.getMeta().getMessages().getFields().get("field1").getText(), is("message1"));
    assertThat(response.getMeta().getMessages().getFields().get("field1").getField(), is("field1"));
    assertThat(response.getMeta().getMessages().getFields().get("field2").getText(), is("message2"));
    assertThat(response.getMeta().getMessages().getFields().get("field2").getField(), is("field2"));
}
Also used : N2oException(net.n2oapp.framework.api.exception.N2oException) DataProcessingStack(net.n2oapp.framework.engine.modules.stack.DataProcessingStack) ValidationMessage(net.n2oapp.framework.api.exception.ValidationMessage) DataSet(net.n2oapp.criteria.dataset.DataSet) ArrayList(java.util.ArrayList) N2oValidationException(net.n2oapp.framework.api.exception.N2oValidationException) SetDataResponse(net.n2oapp.framework.api.rest.SetDataResponse) N2oException(net.n2oapp.framework.api.exception.N2oException) N2oValidationException(net.n2oapp.framework.api.exception.N2oValidationException) Test(org.junit.Test)

Example 4 with DataProcessingStack

use of net.n2oapp.framework.engine.modules.stack.DataProcessingStack in project n2o-framework by i-novus-llc.

the class DataControllerExceptionTest method testGetData.

@Test
public void testGetData() {
    DataProcessingStack dataProcessingStack = mock(DataProcessingStack.class);
    Exception e = new N2oException("Message");
    doThrow(e).when(dataProcessingStack).processQuery(any(QueryRequestInfo.class), any(QueryResponseInfo.class));
    DataController controller = buildController(dataProcessingStack);
    GetDataResponse response = controller.getData("/page/main", null, null);
    assertThat(response.getMeta().getAlert().getMessages().get(0).getColor(), is(SeverityType.danger.toString()));
    assertThat(response.getMeta().getAlert().getMessages().get(0).getStacktrace().get(0), is("net.n2oapp.framework.api.exception.N2oException: Message"));
    List<ValidationMessage> messages = new ArrayList<>();
    messages.add(new ValidationMessage("message1", "field1", "validation1"));
    messages.add(new ValidationMessage("message2", "field2", "validation2"));
    e = new N2oValidationException("Validation exception", "widget", messages, "messageForm");
    doThrow(e).when(dataProcessingStack).processQuery(any(QueryRequestInfo.class), any(QueryResponseInfo.class));
    controller = buildController(dataProcessingStack);
    response = controller.getData("/page/main", null, null);
    assertThat(response.getMeta().getMessages().getForm(), is("page_main"));
    assertThat(response.getMeta().getMessages().getFields().size(), is(2));
    assertThat(response.getMeta().getMessages().getFields().get("field1").getText(), is("message1"));
    assertThat(response.getMeta().getMessages().getFields().get("field1").getField(), is("field1"));
    assertThat(response.getMeta().getMessages().getFields().get("field2").getText(), is("message2"));
    assertThat(response.getMeta().getMessages().getFields().get("field2").getField(), is("field2"));
}
Also used : N2oException(net.n2oapp.framework.api.exception.N2oException) DataProcessingStack(net.n2oapp.framework.engine.modules.stack.DataProcessingStack) ValidationMessage(net.n2oapp.framework.api.exception.ValidationMessage) ArrayList(java.util.ArrayList) GetDataResponse(net.n2oapp.framework.api.rest.GetDataResponse) N2oValidationException(net.n2oapp.framework.api.exception.N2oValidationException) N2oException(net.n2oapp.framework.api.exception.N2oException) N2oValidationException(net.n2oapp.framework.api.exception.N2oValidationException) Test(org.junit.Test)

Example 5 with DataProcessingStack

use of net.n2oapp.framework.engine.modules.stack.DataProcessingStack in project n2o-framework by i-novus-llc.

the class DataControllerTest method testOperation.

private SetDataResponse testOperation(String path, ReadCompileTerminalPipeline<ReadCompileBindTerminalPipeline> pipeline, Map<String, String[]> params, DataSet body) {
    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);
    invocationProcessor.setEnvironment(builder.getEnvironment());
    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);
    DataProcessingStack dataProcessingStack = new SpringDataProcessingStack();
    ((SpringDataProcessingStack) dataProcessingStack).setApplicationContext(context);
    N2oRouter router = new N2oRouter(builder.getEnvironment(), pipeline);
    ContextEngine contextEngine = Mockito.mock(ContextEngine.class);
    Map<String, Object> map = new HashMap<>();
    AlertMessageBuilder messageBuilder = new AlertMessageBuilder(builder.getEnvironment().getMessageSource(), null);
    OperationController operationController = new OperationController(dataProcessingStack, operationProcessor, messageBuilder, builder.getEnvironment());
    map.put("operationController", operationController);
    N2oControllerFactory factory = new N2oControllerFactory(map);
    factory.setEnvironment(builder.getEnvironment());
    DataController controller = new DataController(factory, builder.getEnvironment(), router);
    controller.setMessageBuilder(messageBuilder);
    return controller.setData(path, params, null, body, new UserContext(contextEngine));
}
Also used : N2oInvocationFactory(net.n2oapp.framework.engine.data.N2oInvocationFactory) HashMap(java.util.HashMap) N2oOperationProcessor(net.n2oapp.framework.engine.data.N2oOperationProcessor) ContextEngine(net.n2oapp.framework.api.context.ContextEngine) DataProcessing(net.n2oapp.framework.api.processing.DataProcessing) ApplicationContext(org.springframework.context.ApplicationContext) N2oValidationModule(net.n2oapp.framework.engine.validation.N2oValidationModule) ValidationProcessor(net.n2oapp.framework.engine.validation.engine.ValidationProcessor) N2oOperationExceptionHandler(net.n2oapp.framework.engine.data.N2oOperationExceptionHandler) N2oRouter(net.n2oapp.framework.config.register.route.N2oRouter) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) OperationController(net.n2oapp.framework.ui.controller.action.OperationController) SpringDataProcessingStack(net.n2oapp.framework.engine.modules.stack.SpringDataProcessingStack) DataProcessingStack(net.n2oapp.framework.engine.modules.stack.DataProcessingStack) AlertMessageBuilder(net.n2oapp.framework.api.ui.AlertMessageBuilder) UserContext(net.n2oapp.framework.api.user.UserContext) TestDataProviderEngine(net.n2oapp.framework.engine.data.json.TestDataProviderEngine) N2oInvocationProcessor(net.n2oapp.framework.engine.data.N2oInvocationProcessor) SpringDataProcessingStack(net.n2oapp.framework.engine.modules.stack.SpringDataProcessingStack)

Aggregations

DataProcessingStack (net.n2oapp.framework.engine.modules.stack.DataProcessingStack)5 HashMap (java.util.HashMap)3 ContextEngine (net.n2oapp.framework.api.context.ContextEngine)3 UserContext (net.n2oapp.framework.api.user.UserContext)3 N2oRouter (net.n2oapp.framework.config.register.route.N2oRouter)3 N2oInvocationFactory (net.n2oapp.framework.engine.data.N2oInvocationFactory)3 TestDataProviderEngine (net.n2oapp.framework.engine.data.json.TestDataProviderEngine)3 SpringDataProcessingStack (net.n2oapp.framework.engine.modules.stack.SpringDataProcessingStack)3 DefaultResourceLoader (org.springframework.core.io.DefaultResourceLoader)3 ArrayList (java.util.ArrayList)2 ContextProcessor (net.n2oapp.framework.api.context.ContextProcessor)2 N2oException (net.n2oapp.framework.api.exception.N2oException)2 N2oValidationException (net.n2oapp.framework.api.exception.N2oValidationException)2 ValidationMessage (net.n2oapp.framework.api.exception.ValidationMessage)2 N2oEnvironment (net.n2oapp.framework.config.compile.pipeline.N2oEnvironment)2 N2oSubModelsProcessor (net.n2oapp.framework.config.util.N2oSubModelsProcessor)2 N2oQueryExceptionHandler (net.n2oapp.framework.engine.data.N2oQueryExceptionHandler)2 N2oQueryProcessor (net.n2oapp.framework.engine.data.N2oQueryProcessor)2 Test (org.junit.Test)2 DataSet (net.n2oapp.criteria.dataset.DataSet)1