Search in sources :

Example 6 with DefaultQuerySpecDeserializer

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);
}
Also used : ControllerRegistry(io.crnk.core.engine.internal.dispatcher.ControllerRegistry) PathBuilder(io.crnk.core.engine.internal.dispatcher.path.PathBuilder) CrnkBoot(io.crnk.core.boot.CrnkBoot) CollectionGet(io.crnk.core.engine.internal.dispatcher.controller.CollectionGet) QuerySpecAdapterBuilder(io.crnk.core.queryspec.internal.QuerySpecAdapterBuilder) DefaultQuerySpecDeserializer(io.crnk.core.queryspec.DefaultQuerySpecDeserializer) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) SimpleModule(io.crnk.core.module.SimpleModule) HttpRequestProcessorImpl(io.crnk.core.engine.internal.http.HttpRequestProcessorImpl) Before(org.junit.Before)

Example 7 with DefaultQuerySpecDeserializer

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());
}
Also used : PropertiesProvider(io.crnk.core.engine.properties.PropertiesProvider) ApplicationContext(org.springframework.context.ApplicationContext) CrnkBoot(io.crnk.core.boot.CrnkBoot) DefaultQuerySpecDeserializer(io.crnk.core.queryspec.DefaultQuerySpecDeserializer) Environment(org.springframework.core.env.Environment) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) CrnkSpringBootProperties(io.crnk.spring.boot.CrnkSpringBootProperties) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CrnkConfigV3(io.crnk.spring.boot.v3.CrnkConfigV3) SpringServiceDiscovery(io.crnk.spring.internal.SpringServiceDiscovery) Test(org.junit.Test)

Example 8 with DefaultQuerySpecDeserializer

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();
}
Also used : TypeParser(io.crnk.core.engine.parser.TypeParser) DefaultQuerySpecDeserializer(io.crnk.core.queryspec.DefaultQuerySpecDeserializer) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) QuerySpecDeserializerContext(io.crnk.core.queryspec.QuerySpecDeserializerContext) Before(org.junit.Before)

Example 9 with DefaultQuerySpecDeserializer

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]);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) DefaultQuerySpecDeserializer(io.crnk.core.queryspec.DefaultQuerySpecDeserializer) QuerySpec(io.crnk.core.queryspec.QuerySpec) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 10 with DefaultQuerySpecDeserializer

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);
}
Also used : ControllerRegistry(io.crnk.core.engine.internal.dispatcher.ControllerRegistry) Response(io.crnk.core.engine.dispatcher.Response) QuerySpecAdapterBuilder(io.crnk.core.queryspec.internal.QuerySpecAdapterBuilder) DefaultQuerySpecDeserializer(io.crnk.core.queryspec.DefaultQuerySpecDeserializer) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) RequestDispatcher(io.crnk.core.engine.dispatcher.RequestDispatcher) HttpRequestProcessorImpl(io.crnk.core.engine.internal.http.HttpRequestProcessorImpl) ExceptionMapperRegistryTest(io.crnk.core.engine.internal.exception.ExceptionMapperRegistryTest) Test(org.junit.Test)

Aggregations

DefaultQuerySpecDeserializer (io.crnk.core.queryspec.DefaultQuerySpecDeserializer)13 Test (org.junit.Test)10 ControllerRegistry (io.crnk.core.engine.internal.dispatcher.ControllerRegistry)7 HttpRequestProcessorImpl (io.crnk.core.engine.internal.http.HttpRequestProcessorImpl)7 QuerySpecAdapterBuilder (io.crnk.core.queryspec.internal.QuerySpecAdapterBuilder)7 RequestDispatcher (io.crnk.core.engine.dispatcher.RequestDispatcher)6 ExceptionMapperRegistryTest (io.crnk.core.engine.internal.exception.ExceptionMapperRegistryTest)6 JsonPath (io.crnk.core.engine.internal.dispatcher.path.JsonPath)5 HashMap (java.util.HashMap)4 Set (java.util.Set)4 Document (io.crnk.core.engine.document.Document)3 CollectionGet (io.crnk.core.engine.internal.dispatcher.controller.CollectionGet)3 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)3 QuerySpecDeserializer (io.crnk.core.queryspec.QuerySpecDeserializer)3 RepositoryMethodParameterProvider (io.crnk.legacy.internal.RepositoryMethodParameterProvider)3 Matchers.anyString (org.mockito.Matchers.anyString)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 CrnkBoot (io.crnk.core.boot.CrnkBoot)2 Response (io.crnk.core.engine.dispatcher.Response)2 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)2