Search in sources :

Example 41 with CrnkBoot

use of io.crnk.core.boot.CrnkBoot 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 42 with CrnkBoot

use of io.crnk.core.boot.CrnkBoot in project crnk-framework by crnk-project.

the class ClientResourceUpsertTest method setup.

@Before
public void setup() {
    boot = new CrnkBoot();
    boot.addModule(new TestModule());
    boot.boot();
    PropertiesProvider propertiesProvider = new NullPropertiesProvider();
    ClientProxyFactory proxyFactory = Mockito.mock(ClientProxyFactory.class);
    upsert = new ClientResourceUpsert(boot.getResourceRegistry(), propertiesProvider, boot.getModuleRegistry().getTypeParser(), boot.getObjectMapper(), boot.getDocumentMapper(), proxyFactory);
}
Also used : PropertiesProvider(io.crnk.core.engine.properties.PropertiesProvider) NullPropertiesProvider(io.crnk.core.engine.properties.NullPropertiesProvider) CrnkBoot(io.crnk.core.boot.CrnkBoot) ClientProxyFactory(io.crnk.client.internal.proxy.ClientProxyFactory) NullPropertiesProvider(io.crnk.core.engine.properties.NullPropertiesProvider) TestModule(io.crnk.test.mock.TestModule) Before(org.junit.Before)

Example 43 with CrnkBoot

use of io.crnk.core.boot.CrnkBoot in project crnk-framework by crnk-project.

the class GeneratorExecutor method run.

public void run(File outputDir) {
    TSGeneratorConfig config = new TSGeneratorConfig();
    config.setGenerateExpressions(true);
    config.getNpm().setPackagingEnabled(false);
    config.getNpm().setPackageName("@crnk/angular-ngrx");
    config.getNpm().getPackageMapping().put(MetaElement.class.getPackage().getName(), "@crnk/angular-ngrx/meta");
    MetaModule metaModule = MetaModule.create();
    metaModule.addMetaProvider(new ResourceMetaProvider());
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceDiscovery(new EmptyServiceDiscovery());
    boot.addModule(metaModule);
    boot.boot();
    TSGenerator generator = new TSGenerator(outputDir, metaModule.getLookup(), config);
    try {
        generator.run();
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) TSGenerator(io.crnk.gen.typescript.internal.TSGenerator) TSGeneratorConfig(io.crnk.gen.typescript.TSGeneratorConfig) ResourceMetaProvider(io.crnk.meta.provider.resource.ResourceMetaProvider) IOException(java.io.IOException) MetaModule(io.crnk.meta.MetaModule) EmptyServiceDiscovery(io.crnk.core.module.discovery.EmptyServiceDiscovery)

Example 44 with CrnkBoot

use of io.crnk.core.boot.CrnkBoot 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 45 with CrnkBoot

use of io.crnk.core.boot.CrnkBoot 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)

Aggregations

CrnkBoot (io.crnk.core.boot.CrnkBoot)54 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)34 Before (org.junit.Before)34 ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)28 Test (org.junit.Test)11 TestModule (io.crnk.test.mock.TestModule)9 SimpleModule (io.crnk.core.module.SimpleModule)7 JsonApiUrlBuilder (io.crnk.core.engine.internal.utils.JsonApiUrlBuilder)6 ResourceMetaProvider (io.crnk.meta.provider.resource.ResourceMetaProvider)6 MetaModule (io.crnk.meta.MetaModule)5 NullPropertiesProvider (io.crnk.core.engine.properties.NullPropertiesProvider)4 PropertiesProvider (io.crnk.core.engine.properties.PropertiesProvider)4 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)4 Task (io.crnk.core.mock.models.Task)4 TaskRepository (io.crnk.core.mock.repository.TaskRepository)4 QuerySpec (io.crnk.core.queryspec.QuerySpec)4 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)4 JaxrsModule (io.crnk.rs.internal.JaxrsModule)4 JsonApiExceptionMapper (io.crnk.core.engine.error.JsonApiExceptionMapper)3 HttpRequestContextProvider (io.crnk.core.engine.http.HttpRequestContextProvider)3