Search in sources :

Example 1 with QuerySpecDeserializer

use of io.crnk.core.queryspec.QuerySpecDeserializer in project crnk-framework by crnk-project.

the class CrnkFeatureTest method testQuerySpecConstructor.

@Test
public void testQuerySpecConstructor() {
    ObjectMapper objectMapper = new ObjectMapper();
    QuerySpecDeserializer querySpecDeserializer = new DefaultQuerySpecDeserializer();
    SampleJsonServiceLocator serviceLocator = new SampleJsonServiceLocator();
    CrnkFeature feature = new CrnkFeature(objectMapper, querySpecDeserializer, serviceLocator);
    Assert.assertSame(objectMapper, feature.getObjectMapper());
    Assert.assertSame(querySpecDeserializer, feature.getBoot().getQuerySpecDeserializer());
}
Also used : QuerySpecDeserializer(io.crnk.core.queryspec.QuerySpecDeserializer) DefaultQuerySpecDeserializer(io.crnk.core.queryspec.DefaultQuerySpecDeserializer) DefaultQuerySpecDeserializer(io.crnk.core.queryspec.DefaultQuerySpecDeserializer) SampleJsonServiceLocator(io.crnk.legacy.locator.SampleJsonServiceLocator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with QuerySpecDeserializer

use of io.crnk.core.queryspec.QuerySpecDeserializer in project crnk-framework by crnk-project.

the class CrnkBootTest method testDiscoverDeserializer.

@Test
public void testDiscoverDeserializer() {
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceDiscovery(serviceDiscovery);
    DefaultQuerySpecDeserializer instance = new DefaultQuerySpecDeserializer();
    Mockito.when(serviceDiscovery.getInstancesByType(eq(QuerySpecDeserializer.class))).thenReturn(Arrays.<QuerySpecDeserializer>asList(instance));
    boot.boot();
    Assert.assertSame(instance, boot.getQuerySpecDeserializer());
}
Also used : DefaultQuerySpecDeserializer(io.crnk.core.queryspec.DefaultQuerySpecDeserializer) QuerySpecDeserializer(io.crnk.core.queryspec.QuerySpecDeserializer) DefaultQuerySpecDeserializer(io.crnk.core.queryspec.DefaultQuerySpecDeserializer) Test(org.junit.Test)

Example 3 with QuerySpecDeserializer

use of io.crnk.core.queryspec.QuerySpecDeserializer in project crnk-framework by crnk-project.

the class CrnkBoot method setupQuerySpecDeserializer.

private void setupQuerySpecDeserializer() {
    if (querySpecDeserializer == null) {
        setupServiceDiscovery();
        List<QuerySpecDeserializer> list = serviceDiscovery.getInstancesByType(QuerySpecDeserializer.class);
        if (list.isEmpty()) {
            querySpecDeserializer = new DefaultQuerySpecDeserializer();
        } else {
            querySpecDeserializer = list.get(0);
        }
    }
    if (querySpecDeserializer instanceof DefaultQuerySpecDeserializer) {
        if (allowUnknownAttributes == null) {
            String strAllow = propertiesProvider.getProperty(CrnkProperties.ALLOW_UNKNOWN_ATTRIBUTES);
            if (strAllow != null) {
                allowUnknownAttributes = Boolean.parseBoolean(strAllow);
            }
        }
        if (allowUnknownAttributes != null) {
            ((DefaultQuerySpecDeserializer) this.querySpecDeserializer).setAllowUnknownAttributes(allowUnknownAttributes);
        }
        if (allowUnknownParameters == null) {
            String strAllow = propertiesProvider.getProperty(CrnkProperties.ALLOW_UNKNOWN_PARAMETERS);
            if (strAllow != null) {
                allowUnknownParameters = Boolean.parseBoolean(strAllow);
            }
        }
        if (allowUnknownParameters != null) {
            ((DefaultQuerySpecDeserializer) this.querySpecDeserializer).setAllowUnknownParameters(allowUnknownParameters);
        }
    }
}
Also used : QuerySpecDeserializer(io.crnk.core.queryspec.QuerySpecDeserializer) DefaultQuerySpecDeserializer(io.crnk.core.queryspec.DefaultQuerySpecDeserializer) DefaultQuerySpecDeserializer(io.crnk.core.queryspec.DefaultQuerySpecDeserializer)

Example 4 with QuerySpecDeserializer

use of io.crnk.core.queryspec.QuerySpecDeserializer in project crnk-framework by crnk-project.

the class CrnkBootTest method setQuerySpecDeserializer.

@Test
public void setQuerySpecDeserializer() {
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceDiscoveryFactory(serviceDiscoveryFactory);
    boot.setDefaultServiceUrlProvider(mock(ServiceUrlProvider.class));
    QuerySpecDeserializer deserializer = Mockito.mock(QuerySpecDeserializer.class);
    boot.setQuerySpecDeserializer(deserializer);
    Assert.assertSame(deserializer, boot.getQuerySpecDeserializer());
    boot.boot();
    HttpRequestProcessorImpl requestDispatcher = boot.getRequestDispatcher();
    QueryAdapterBuilder queryAdapterBuilder = requestDispatcher.getQueryAdapterBuilder();
    Assert.assertTrue(queryAdapterBuilder instanceof QuerySpecAdapterBuilder);
}
Also used : QuerySpecAdapterBuilder(io.crnk.core.queryspec.internal.QuerySpecAdapterBuilder) QuerySpecDeserializer(io.crnk.core.queryspec.QuerySpecDeserializer) DefaultQuerySpecDeserializer(io.crnk.core.queryspec.DefaultQuerySpecDeserializer) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) ServiceUrlProvider(io.crnk.core.engine.url.ServiceUrlProvider) HttpRequestProcessorImpl(io.crnk.core.engine.internal.http.HttpRequestProcessorImpl) QueryAdapterBuilder(io.crnk.core.engine.query.QueryAdapterBuilder) Test(org.junit.Test)

Aggregations

DefaultQuerySpecDeserializer (io.crnk.core.queryspec.DefaultQuerySpecDeserializer)4 QuerySpecDeserializer (io.crnk.core.queryspec.QuerySpecDeserializer)4 Test (org.junit.Test)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HttpRequestProcessorImpl (io.crnk.core.engine.internal.http.HttpRequestProcessorImpl)1 QueryAdapterBuilder (io.crnk.core.engine.query.QueryAdapterBuilder)1 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)1 ServiceUrlProvider (io.crnk.core.engine.url.ServiceUrlProvider)1 QuerySpecAdapterBuilder (io.crnk.core.queryspec.internal.QuerySpecAdapterBuilder)1 SampleJsonServiceLocator (io.crnk.legacy.locator.SampleJsonServiceLocator)1