use of io.crnk.core.queryspec.DefaultQuerySpecDeserializer in project crnk-framework by crnk-project.
the class FilterTest method prepare.
@Before
public void prepare() {
boot = new CrnkBoot();
boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
boot.setServiceUrlProvider(new ConstantServiceUrlProvider(ResourceRegistryTest.TEST_MODELS_URL));
// GIVEN
filter = mock(TestFilter.class);
SimpleModule filterModule = new SimpleModule("filter");
filterModule.addFilter(filter);
boot.addModule(filterModule);
boot.boot();
resourceRegistry = boot.getResourceRegistry();
moduleRegistry = boot.getModuleRegistry();
pathBuilder = new PathBuilder(resourceRegistry);
ControllerRegistry controllerRegistry = new ControllerRegistry(null);
collectionGet = mock(CollectionGet.class);
controllerRegistry.addController(collectionGet);
QuerySpecAdapterBuilder queryAdapterBuilder = new QuerySpecAdapterBuilder(new DefaultQuerySpecDeserializer(), moduleRegistry);
dispatcher = new HttpRequestProcessorImpl(moduleRegistry, controllerRegistry, null, queryAdapterBuilder);
}
use of io.crnk.core.queryspec.DefaultQuerySpecDeserializer in project crnk-framework by crnk-project.
the class CrnkConfigV3Test method checkProperties.
@Test
public void checkProperties() {
ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class);
Mockito.when(applicationContext.getEnvironment()).thenReturn(Mockito.mock(Environment.class));
CrnkSpringBootProperties properties = new CrnkSpringBootProperties();
properties.setDomainName("testDomain");
properties.setDefaultPageLimit(12L);
properties.setMaxPageLimit(20L);
properties.setPathPrefix("prefix");
properties.setAllowUnknownAttributes(true);
properties.setReturn404OnNull(true);
properties.setResourcePackage("ch.something");
ObjectMapper objectMapper = new ObjectMapper();
CrnkConfigV3 config = new CrnkConfigV3(properties, objectMapper);
config.setApplicationContext(applicationContext);
SpringServiceDiscovery serviceDiscovery = Mockito.mock(SpringServiceDiscovery.class);
CrnkBoot boot = config.crnkBoot(serviceDiscovery);
PropertiesProvider propertiesProvider = boot.getPropertiesProvider();
Assert.assertEquals("testDomain", propertiesProvider.getProperty(CrnkProperties.RESOURCE_DEFAULT_DOMAIN));
Assert.assertEquals("ch.something", propertiesProvider.getProperty(CrnkProperties.RESOURCE_SEARCH_PACKAGE));
Assert.assertEquals("prefix", propertiesProvider.getProperty(CrnkProperties.WEB_PATH_PREFIX));
Assert.assertEquals("true", propertiesProvider.getProperty(CrnkProperties.ALLOW_UNKNOWN_ATTRIBUTES));
Assert.assertEquals("true", propertiesProvider.getProperty(CrnkProperties.RETURN_404_ON_NULL));
DefaultQuerySpecDeserializer deserializer = (DefaultQuerySpecDeserializer) boot.getQuerySpecDeserializer();
Assert.assertTrue(deserializer.getAllowUnknownAttributes());
ConstantServiceUrlProvider constantServiceUrlProvider = (ConstantServiceUrlProvider) boot.getServiceUrlProvider();
Assert.assertEquals("testDomainprefix", constantServiceUrlProvider.getUrl());
Assert.assertSame(objectMapper, boot.getObjectMapper());
Assert.assertNotNull(boot.getModuleRegistry().getSecurityProvider());
}
use of io.crnk.core.queryspec.DefaultQuerySpecDeserializer in project crnk-framework by crnk-project.
the class DefaultQuerySpecDeserializerTestBase method setup.
@Before
public void setup() {
super.setup();
deserializerContext = new QuerySpecDeserializerContext() {
@Override
public ResourceRegistry getResourceRegistry() {
return resourceRegistry;
}
@Override
public TypeParser getTypeParser() {
return moduleRegistry.getTypeParser();
}
};
deserializer = new DefaultQuerySpecDeserializer();
deserializer.init(deserializerContext);
taskInformation = resourceRegistry.getEntry(Task.class).getResourceInformation();
taskWithPagingBehaviorInformation = resourceRegistry.getEntry(TaskWithPagingBehavior.class).getResourceInformation();
}
use of io.crnk.core.queryspec.DefaultQuerySpecDeserializer in project crnk-framework by crnk-project.
the class DefaultQuerySpecDeserializerTestBase method deserializeUnknownParameter.
@Test
public void deserializeUnknownParameter() {
Map<String, Set<String>> params = new HashMap<>();
add(params, "doesNotExist[something]", "someValue");
final boolean[] deserialized = new boolean[1];
deserializer = new DefaultQuerySpecDeserializer() {
@Override
protected void deserializeUnknown(final QuerySpec querySpec, final Parameter parameter) {
Assert.assertEquals(RestrictedQueryParamsMembers.unknown, parameter.getParamType());
Assert.assertEquals("doesNotExist", parameter.getStrParamType());
Assert.assertEquals("doesNotExist[something]", parameter.getName());
Assert.assertNull(parameter.getResourceInformation());
Assert.assertEquals(FilterOperator.EQ, parameter.getOperator());
Assert.assertNull(parameter.getAttributePath());
Assert.assertEquals(1, parameter.getValues().size());
deserialized[0] = true;
}
};
deserializer.init(deserializerContext);
deserializer.deserialize(taskInformation, params);
Assert.assertTrue(deserialized[0]);
}
use of io.crnk.core.queryspec.DefaultQuerySpecDeserializer in project crnk-framework by crnk-project.
the class HttpRequestProcessorImplTest method shouldThrowExceptionAsIsIfMapperIsNotAvailable.
@Test
public void shouldThrowExceptionAsIsIfMapperIsNotAvailable() throws Exception {
ControllerRegistry controllerRegistry = mock(ControllerRegistry.class);
// noinspection unchecked
when(controllerRegistry.getController(any(JsonPath.class), anyString())).thenThrow(ArithmeticException.class);
QuerySpecAdapterBuilder queryAdapterBuilder = new QuerySpecAdapterBuilder(new DefaultQuerySpecDeserializer(), moduleRegistry);
RequestDispatcher requestDispatcher = new HttpRequestProcessorImpl(moduleRegistry, controllerRegistry, ExceptionMapperRegistryTest.exceptionMapperRegistry, queryAdapterBuilder);
expectedException.expect(ArithmeticException.class);
Response response = requestDispatcher.dispatchRequest("tasks", null, null, null, null);
}
Aggregations