Search in sources :

Example 26 with ReflectionsServiceDiscovery

use of io.crnk.core.module.discovery.ReflectionsServiceDiscovery 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 27 with ReflectionsServiceDiscovery

use of io.crnk.core.module.discovery.ReflectionsServiceDiscovery in project crnk-framework by crnk-project.

the class AbstractQuerySpecTest method setup.

@Before
public void setup() {
    ResourceInformationProvider resourceInformationProvider = new DefaultResourceInformationProvider(new NullPropertiesProvider(), ImmutableList.of(new OffsetLimitPagingBehavior(), new CustomOffsetLimitPagingBehavior()), new DefaultResourceFieldInformationProvider(), new JacksonResourceFieldInformationProvider()) {

        @Override
        protected List<ResourceField> getResourceFields(Class<?> resourceClass) {
            List<ResourceField> fields = super.getResourceFields(resourceClass);
            if (resourceClass == Task.class) {
                // add additional field that is not defined on the class
                String name = "computedAttribute";
                ResourceFieldAccess access = new ResourceFieldAccess(true, true, true, true, true);
                InformationBuilder informationBuilder = new DefaultInformationBuilder(new TypeParser());
                InformationBuilder.Field fieldBuilder = informationBuilder.createResourceField();
                fieldBuilder.type(Integer.class);
                fieldBuilder.jsonName(name);
                fieldBuilder.underlyingName(name);
                fieldBuilder.access(access);
                fieldBuilder.accessor(new ResourceFieldAccessor() {

                    public Object getValue(Object resource) {
                        return 13;
                    }

                    public void setValue(Object resource, Object fieldValue) {
                    }
                });
                fields.add(fieldBuilder.build());
            }
            return fields;
        }
    };
    SimpleModule testModule = new SimpleModule("test");
    testModule.addResourceInformationProvider(resourceInformationProvider);
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider("http://127.0.0.1"));
    boot.addModule(testModule);
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery(getResourceSearchPackage()));
    boot.boot();
    moduleRegistry = boot.getModuleRegistry();
    querySpecConverter = new DefaultQuerySpecConverter(moduleRegistry);
    resourceRegistry = boot.getResourceRegistry();
}
Also used : OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) CustomOffsetLimitPagingBehavior(io.crnk.core.queryspec.repository.CustomOffsetLimitPagingBehavior) TypeParser(io.crnk.core.engine.parser.TypeParser) NullPropertiesProvider(io.crnk.core.engine.properties.NullPropertiesProvider) DefaultResourceInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider) JacksonResourceFieldInformationProvider(io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider) DefaultQuerySpecConverter(io.crnk.legacy.internal.DefaultQuerySpecConverter) ResourceFieldAccess(io.crnk.core.engine.information.resource.ResourceFieldAccess) CustomOffsetLimitPagingBehavior(io.crnk.core.queryspec.repository.CustomOffsetLimitPagingBehavior) InformationBuilder(io.crnk.core.engine.information.InformationBuilder) DefaultInformationBuilder(io.crnk.core.engine.internal.information.DefaultInformationBuilder) ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceFieldAccessor(io.crnk.core.engine.information.resource.ResourceFieldAccessor) DefaultInformationBuilder(io.crnk.core.engine.internal.information.DefaultInformationBuilder) CrnkBoot(io.crnk.core.boot.CrnkBoot) ResourceInformationProvider(io.crnk.core.engine.information.resource.ResourceInformationProvider) DefaultResourceInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) SimpleModule(io.crnk.core.module.SimpleModule) DefaultResourceFieldInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider) Before(org.junit.Before)

Example 28 with ReflectionsServiceDiscovery

use of io.crnk.core.module.discovery.ReflectionsServiceDiscovery in project crnk-framework by crnk-project.

the class DefaultQuerySpecSerializerTest method setup.

@Before
public void setup() {
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider("http://127.0.0.1"));
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery(String.format("%s,io.crnk.core.queryspec.pagingspec", MockConstants.TEST_MODELS_PACKAGE)));
    boot.boot();
    resourceRegistry = boot.getResourceRegistry();
    urlBuilder = new JsonApiUrlBuilder(resourceRegistry);
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) JsonApiUrlBuilder(io.crnk.core.engine.internal.utils.JsonApiUrlBuilder) Before(org.junit.Before)

Example 29 with ReflectionsServiceDiscovery

use of io.crnk.core.module.discovery.ReflectionsServiceDiscovery in project crnk-framework by crnk-project.

the class ResourceRepositoryBaseTest method setup.

@Before
public void setup() {
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
    boot.setPropertiesProvider(new PropertiesProvider() {

        @Override
        public String getProperty(String key) {
            if (key.equals(CrnkProperties.RETURN_404_ON_NULL)) {
                return "true";
            }
            return null;
        }
    });
    boot.boot();
    repository = new TestRepository();
    repository.setResourceRegistry(boot.getResourceRegistry());
}
Also used : PropertiesProvider(io.crnk.core.engine.properties.PropertiesProvider) CrnkBoot(io.crnk.core.boot.CrnkBoot) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) Before(org.junit.Before)

Example 30 with ReflectionsServiceDiscovery

use of io.crnk.core.module.discovery.ReflectionsServiceDiscovery in project crnk-framework by crnk-project.

the class BraveResponseFilterTest method setup.

@Before
public void setup() {
    boot = new CrnkBoot();
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery("io.crnk.test.mock.repository", new SampleJsonServiceLocator()));
    boot.boot();
    span = Mockito.mock(Span.class);
    tracing = Mockito.mock(Tracing.class);
    tracer = Mockito.mock(Tracer.class);
    Mockito.when(tracing.tracer()).thenReturn(tracer);
    Mockito.when(tracer.nextSpan()).thenReturn(span);
    moduleContext = Mockito.mock(Module.ModuleContext.class);
    Mockito.when(moduleContext.getResourceRegistry()).thenReturn(boot.getResourceRegistry());
    QuerySpec querySpec = new QuerySpec(Task.class);
    queryAdapter = new QuerySpecAdapter(querySpec, boot.getResourceRegistry());
    ResourceInformation taskResourceInformation = boot.getResourceRegistry().getEntry(Task.class).getResourceInformation();
    requestSpec = Mockito.mock(RepositoryRequestSpec.class);
    Mockito.when(requestSpec.getMethod()).thenReturn(HttpMethod.GET);
    Mockito.when(requestSpec.getQueryAdapter()).thenReturn(queryAdapter);
    Mockito.when(requestSpec.getQuerySpec(taskResourceInformation)).thenReturn(querySpec);
    filter = new BraveRepositoryFilter(tracing, moduleContext);
    filterContext = Mockito.mock(RepositoryFilterContext.class);
    Mockito.when(filterContext.getRequest()).thenReturn(requestSpec);
    filterChain = Mockito.mock(RepositoryRequestFilterChain.class);
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Task(io.crnk.test.mock.models.Task) RepositoryRequestSpec(io.crnk.core.engine.dispatcher.RepositoryRequestSpec) Tracer(brave.Tracer) SampleJsonServiceLocator(io.crnk.legacy.locator.SampleJsonServiceLocator) BraveRepositoryFilter(io.crnk.monitor.brave.internal.BraveRepositoryFilter) RepositoryFilterContext(io.crnk.core.engine.filter.RepositoryFilterContext) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) Span(brave.Span) CrnkBoot(io.crnk.core.boot.CrnkBoot) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) Tracing(brave.Tracing) QuerySpec(io.crnk.core.queryspec.QuerySpec) RepositoryRequestFilterChain(io.crnk.core.engine.filter.RepositoryRequestFilterChain) Before(org.junit.Before)

Aggregations

ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)30 CrnkBoot (io.crnk.core.boot.CrnkBoot)28 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)25 Before (org.junit.Before)22 Test (org.junit.Test)7 JsonApiUrlBuilder (io.crnk.core.engine.internal.utils.JsonApiUrlBuilder)6 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)5 Task (io.crnk.core.mock.models.Task)5 SimpleModule (io.crnk.core.module.SimpleModule)4 RelationIdTestResource (io.crnk.core.mock.models.RelationIdTestResource)3 PathBuilder (io.crnk.core.engine.internal.dispatcher.path.PathBuilder)2 PropertiesProvider (io.crnk.core.engine.properties.PropertiesProvider)2 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)2 Project (io.crnk.core.mock.models.Project)2 Schedule (io.crnk.core.mock.models.Schedule)2 User (io.crnk.core.mock.models.User)2 ProjectRepository (io.crnk.core.mock.repository.ProjectRepository)2 ScheduleRepositoryImpl (io.crnk.core.mock.repository.ScheduleRepositoryImpl)2 TaskRepository (io.crnk.core.mock.repository.TaskRepository)2 Module (io.crnk.core.module.Module)2