Search in sources :

Example 6 with SampleJsonServiceLocator

use of io.crnk.legacy.locator.SampleJsonServiceLocator in project crnk-framework by crnk-project.

the class FallbackServiceDiscoveryFactoryTest method fallbackToReflectionsIfNoDefaultAvailable.

@Test
public void fallbackToReflectionsIfNoDefaultAvailable() {
    PropertiesProvider propertiesProvider = Mockito.mock(PropertiesProvider.class);
    Mockito.when(propertiesProvider.getProperty(Mockito.eq(CrnkProperties.RESOURCE_SEARCH_PACKAGE))).thenReturn("a.b.c");
    ServiceDiscoveryFactory defaultFactory = new ServiceDiscoveryFactory() {

        @Override
        public ServiceDiscovery getInstance() {
            return null;
        }
    };
    FallbackServiceDiscoveryFactory fallbackFactory = new FallbackServiceDiscoveryFactory(defaultFactory, new SampleJsonServiceLocator(), propertiesProvider);
    Assert.assertTrue(fallbackFactory.getInstance() instanceof ReflectionsServiceDiscovery);
}
Also used : PropertiesProvider(io.crnk.core.engine.properties.PropertiesProvider) NullPropertiesProvider(io.crnk.core.engine.properties.NullPropertiesProvider) SampleJsonServiceLocator(io.crnk.legacy.locator.SampleJsonServiceLocator) Test(org.junit.Test)

Example 7 with SampleJsonServiceLocator

use of io.crnk.legacy.locator.SampleJsonServiceLocator in project crnk-framework by crnk-project.

the class AbstractQueryParamsTest method setup.

@Before
public void setup() {
    JsonServiceLocator jsonServiceLocator = new SampleJsonServiceLocator();
    ResourceInformationProvider resourceInformationProvider = new DefaultResourceInformationProvider(new NullPropertiesProvider(), (PagingBehavior) null, new DefaultResourceFieldInformationProvider(), new JacksonResourceFieldInformationProvider());
    SimpleModule testModule = new SimpleModule("test");
    CrnkBoot boot = new CrnkBoot();
    boot.addModule(testModule);
    boot.boot();
    moduleRegistry = boot.getModuleRegistry();
    resourceRegistry = boot.getResourceRegistry();
    converter = new DefaultQueryParamsConverter(resourceRegistry);
    paramsToSpecConverter = new DefaultQuerySpecConverter(moduleRegistry);
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) NullPropertiesProvider(io.crnk.core.engine.properties.NullPropertiesProvider) SampleJsonServiceLocator(io.crnk.legacy.locator.SampleJsonServiceLocator) DefaultResourceInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider) JsonServiceLocator(io.crnk.legacy.locator.JsonServiceLocator) SampleJsonServiceLocator(io.crnk.legacy.locator.SampleJsonServiceLocator) ResourceInformationProvider(io.crnk.core.engine.information.resource.ResourceInformationProvider) DefaultResourceInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider) JacksonResourceFieldInformationProvider(io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider) DefaultQuerySpecConverter(io.crnk.legacy.internal.DefaultQuerySpecConverter) SimpleModule(io.crnk.core.module.SimpleModule) DefaultResourceFieldInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider) Before(org.junit.Before)

Example 8 with SampleJsonServiceLocator

use of io.crnk.legacy.locator.SampleJsonServiceLocator in project crnk-framework by crnk-project.

the class RegistryEntryTest method onInvalidRelationshipClassShouldThrowException.

@Test
public void onInvalidRelationshipClassShouldThrowException() throws Exception {
    // GIVEN
    ResourceRepositoryInformation repositoryInformation = newRepositoryInformation(Task.class, "tasks");
    ResourceField relationshipField = repositoryInformation.getResourceInformation().get().findFieldByUnderlyingName("tasks");
    Map relRepos = new HashMap<>();
    relRepos.put(relationshipField, new DirectResponseRelationshipEntry(new RepositoryInstanceBuilder(new SampleJsonServiceLocator(), TaskToProjectRepository.class)));
    RegistryEntry sut = new RegistryEntry(new DirectResponseResourceEntry(null, repositoryInformation), relRepos);
    // THEN
    expectedException.expect(ResourceFieldNotFoundException.class);
    // WHEN
    sut.getRelationshipRepository("users", null);
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) DirectResponseRelationshipEntry(io.crnk.legacy.internal.DirectResponseRelationshipEntry) DirectResponseResourceEntry(io.crnk.legacy.internal.DirectResponseResourceEntry) HashMap(java.util.HashMap) SampleJsonServiceLocator(io.crnk.legacy.locator.SampleJsonServiceLocator) HashMap(java.util.HashMap) Map(java.util.Map) RepositoryInstanceBuilder(io.crnk.legacy.registry.RepositoryInstanceBuilder) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) Test(org.junit.Test)

Example 9 with SampleJsonServiceLocator

use of io.crnk.legacy.locator.SampleJsonServiceLocator in project crnk-framework by crnk-project.

the class ValidationMetaProviderTest method setup.

private void setup(boolean addValidationProvider) {
    CrnkBoot boot = new CrnkBoot();
    boot.addModule(new JaxrsModule(null));
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider("http://localhost"));
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery("io.crnk.validation.mock", new SampleJsonServiceLocator()));
    boot.boot();
    resourceMetaProvider = new ResourceMetaProvider();
    lookup = new MetaLookup();
    lookup.setModuleContext(boot.getModuleRegistry().getContext());
    lookup.addProvider(resourceMetaProvider);
    if (addValidationProvider) {
        lookup.addProvider(new ValidationMetaProvider());
    }
    lookup.initialize();
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) MetaLookup(io.crnk.meta.MetaLookup) ResourceMetaProvider(io.crnk.meta.provider.resource.ResourceMetaProvider) JaxrsModule(io.crnk.rs.internal.JaxrsModule) SampleJsonServiceLocator(io.crnk.legacy.locator.SampleJsonServiceLocator) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery)

Example 10 with SampleJsonServiceLocator

use of io.crnk.legacy.locator.SampleJsonServiceLocator in project crnk-framework by crnk-project.

the class RepositoryInstanceBuilderTest method onExistingInstanceShouldReturnValue.

@Test
public void onExistingInstanceShouldReturnValue() throws Exception {
    // GIVEN
    RepositoryInstanceBuilder<TaskRepository> sut = new RepositoryInstanceBuilder<>(new SampleJsonServiceLocator(), TaskRepository.class);
    // WHEN
    TaskRepository result = sut.buildRepository();
    // THEN
    assertThat(sut.getRepositoryClass()).isEqualTo(TaskRepository.class);
    assertThat(result).isInstanceOf(TaskRepository.class);
}
Also used : TaskRepository(io.crnk.core.mock.repository.TaskRepository) SampleJsonServiceLocator(io.crnk.legacy.locator.SampleJsonServiceLocator) RepositoryInstanceBuilder(io.crnk.legacy.registry.RepositoryInstanceBuilder) Test(org.junit.Test)

Aggregations

SampleJsonServiceLocator (io.crnk.legacy.locator.SampleJsonServiceLocator)11 Test (org.junit.Test)7 CrnkBoot (io.crnk.core.boot.CrnkBoot)4 NullPropertiesProvider (io.crnk.core.engine.properties.NullPropertiesProvider)4 PropertiesProvider (io.crnk.core.engine.properties.PropertiesProvider)3 ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)3 RepositoryInstanceBuilder (io.crnk.legacy.registry.RepositoryInstanceBuilder)3 Before (org.junit.Before)3 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)2 Span (brave.Span)1 Tracer (brave.Tracer)1 Tracing (brave.Tracing)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 RepositoryRequestSpec (io.crnk.core.engine.dispatcher.RepositoryRequestSpec)1 RepositoryFilterContext (io.crnk.core.engine.filter.RepositoryFilterContext)1 RepositoryRequestFilterChain (io.crnk.core.engine.filter.RepositoryRequestFilterChain)1 ResourceRepositoryInformation (io.crnk.core.engine.information.repository.ResourceRepositoryInformation)1 ResourceField (io.crnk.core.engine.information.resource.ResourceField)1 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)1 ResourceInformationProvider (io.crnk.core.engine.information.resource.ResourceInformationProvider)1