use of net.n2oapp.framework.config.compile.pipeline.N2oEnvironment 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.config.compile.pipeline.N2oEnvironment 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.config.compile.pipeline.N2oEnvironment in project n2o-framework by i-novus-llc.
the class DataControllerTestBase method setUp.
@Before
public void setUp() {
N2oEnvironment environment = new N2oEnvironment();
environment.setNamespacePersisterFactory(new PersisterFactoryByMap());
environment.setNamespaceReaderFactory(new ReaderFactoryByMap());
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasenames("n2o_messages", "messages");
messageSource.setDefaultEncoding("UTF-8");
environment.setMessageSource(new MessageSourceAccessor(messageSource));
OverrideProperties properties = PropertiesReader.getPropertiesFromClasspath("META-INF/n2o.properties");
properties.put("n2o.engine.mapper", "spel");
SimplePropertyResolver propertyResolver = new SimplePropertyResolver(properties);
setUpStaticProperties(propertyResolver);
environment.setSystemProperties(propertyResolver);
builder = new N2oApplicationBuilder(environment);
configure(builder);
CompileInfo.setSourceTypes(builder.getEnvironment().getSourceTypeRegister());
}
use of net.n2oapp.framework.config.compile.pipeline.N2oEnvironment 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.config.compile.pipeline.N2oEnvironment in project n2o-framework by i-novus-llc.
the class RouterTest method route_repository.
@Test
public void route_repository() {
N2oEnvironment env = (N2oEnvironment) builder.getEnvironment();
TestRouteRepository repository = new TestRouteRepository();
env.setRouteRegister(new N2oRouteRegister(repository));
MockCompileContext<Page, Object> context = new MockCompileContext<>("/", "p", null, Page.class);
RouteInfoKey key = new RouteInfoKey("/", context.getCompiledClass());
repository.save(key, context);
context = new MockCompileContext<>("/p/w", "pw", null, Page.class);
key = new RouteInfoKey("/p/w", context.getCompiledClass());
repository.save(key, context);
N2oRouter router = new N2oRouter(env, new MockBindPipeline(env));
CompileContext<Page, ?> res = router.get("/", Page.class, null);
assertThat(res, notNullValue());
assertThat(res.getSourceId(null), is("p"));
res = router.get("/p/w", Page.class, null);
assertThat(res, notNullValue());
assertThat(res.getSourceId(null), is("pw"));
}
Aggregations