Search in sources :

Example 31 with ConstantServiceUrlProvider

use of io.crnk.core.engine.url.ConstantServiceUrlProvider in project crnk-framework by crnk-project.

the class PathBuilderTest method prepare.

@Before
public void prepare() {
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider(ResourceRegistryTest.TEST_MODELS_URL));
    boot.boot();
    pathBuilder = new PathBuilder(boot.getResourceRegistry());
    RegistryEntry entry = boot.getResourceRegistry().findEntry(Task.class);
    ResourceRepositoryInformation repositoryInformation = entry.getRepositoryInformation();
    repositoryInformation.getActions().put("someRepositoryAction", Mockito.mock(RepositoryAction.class));
    repositoryInformation.getActions().put("someResourceAction", Mockito.mock(RepositoryAction.class));
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) RepositoryAction(io.crnk.core.engine.information.repository.RepositoryAction) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) Before(org.junit.Before)

Example 32 with ConstantServiceUrlProvider

use of io.crnk.core.engine.url.ConstantServiceUrlProvider in project crnk-framework by crnk-project.

the class ControllerRegistryTest method prepare.

@Before
public void prepare() {
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider(ResourceRegistryTest.TEST_MODELS_URL));
    boot.boot();
    resourceRegistry = boot.getResourceRegistry();
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) Before(org.junit.Before)

Example 33 with ConstantServiceUrlProvider

use of io.crnk.core.engine.url.ConstantServiceUrlProvider in project crnk-framework by crnk-project.

the class AbstractJpaTest method setup.

@Before
public void setup() {
    ModuleRegistry moduleRegistry = new ModuleRegistry();
    moduleRegistry.getHttpRequestContextProvider().setServiceUrlProvider(new ConstantServiceUrlProvider("http://localhost:1234"));
    resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
    module = JpaModule.newServerModule(emFactory, em, transactionRunner);
    setupModule(module);
    moduleRegistry.addModule(new JacksonModule(new ObjectMapper()));
    moduleRegistry.addModule(new CoreModule());
    moduleRegistry.addModule(module);
    moduleRegistry.setServiceDiscovery(new EmptyServiceDiscovery());
    moduleRegistry.init(new ObjectMapper());
    queryFactory = createQueryFactory(em);
    module.setQueryFactory(queryFactory);
    clear();
    for (int i = 0; i < numTestEntities; i++) {
        TestEmbeddedIdEntity idEntity = new TestEmbeddedIdEntity();
        idEntity.setId(new TestIdEmbeddable(i, "test" + i));
        idEntity.setLongValue(100L + i);
        em.persist(idEntity);
        RelatedEntity related = new RelatedEntity();
        related.setId(100L + i);
        related.setStringValue("related" + i);
        em.persist(related);
        TestAnyType anyValue = new TestAnyType();
        if (i == 0)
            anyValue.setValue("first");
        else
            anyValue.setValue(i);
        TestEmbeddable embValue = new TestEmbeddable();
        embValue.setEmbIntValue(i);
        embValue.setEmbStringValue("emb" + i);
        embValue.setNestedValue(new TestNestedEmbeddable(i == 0));
        embValue.setAnyValue(anyValue);
        TestEntity test = new TestEntity();
        test.setStringValue("test" + i);
        test.setId((long) i);
        test.setLongValue(i);
        test.setEmbValue(embValue);
        // left join sorting
        if (i != numTestEntities - 1) {
            test.setOneRelatedValue(related);
            test.getMapValue().put("a", "a" + i);
            test.getMapValue().put("b", "b" + i);
            test.getMapValue().put("c", "c" + i);
        }
        em.persist(test);
        // inheritance
        SingleTableBaseEntity singleTableBase = new SingleTableBaseEntity();
        singleTableBase.setId((long) i);
        singleTableBase.setStringValue("base" + i);
        em.persist(singleTableBase);
        SingleTableChildEntity singleTableChild = new SingleTableChildEntity();
        singleTableChild.setId((long) i + numTestEntities);
        singleTableChild.setStringValue("child" + i);
        singleTableChild.setIntValue(i);
        em.persist(singleTableChild);
        JoinedTableBaseEntity joinedTableBase = new JoinedTableBaseEntity();
        joinedTableBase.setId((long) i);
        joinedTableBase.setStringValue("base" + i);
        em.persist(joinedTableBase);
        JoinedTableChildEntity joinedTableChild = new JoinedTableChildEntity();
        joinedTableChild.setId((long) i + numTestEntities);
        joinedTableChild.setStringValue("child" + i);
        joinedTableChild.setIntValue(i);
        em.persist(joinedTableChild);
        TablePerClassBaseEntity tablePerClassBase = new TablePerClassBaseEntity();
        tablePerClassBase.setId((long) i);
        tablePerClassBase.setStringValue("base" + i);
        em.persist(tablePerClassBase);
        TablePerClassChildEntity tablePerClassChild = new TablePerClassChildEntity();
        tablePerClassChild.setId((long) i + numTestEntities);
        tablePerClassChild.setStringValue("child" + i);
        tablePerClassChild.setIntValue(i);
        em.persist(tablePerClassChild);
    }
    em.flush();
    em.clear();
    queryFactory = createQueryFactory(em);
    module.setQueryFactory(queryFactory);
}
Also used : ModuleRegistry(io.crnk.core.module.ModuleRegistry) ResourceRegistryImpl(io.crnk.core.engine.internal.registry.ResourceRegistryImpl) JacksonModule(io.crnk.core.engine.internal.jackson.JacksonModule) DefaultResourceRegistryPart(io.crnk.core.engine.registry.DefaultResourceRegistryPart) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) CoreModule(io.crnk.core.engine.internal.CoreModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EmptyServiceDiscovery(io.crnk.core.module.discovery.EmptyServiceDiscovery) Before(org.junit.Before)

Example 34 with ConstantServiceUrlProvider

use of io.crnk.core.engine.url.ConstantServiceUrlProvider 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 35 with ConstantServiceUrlProvider

use of io.crnk.core.engine.url.ConstantServiceUrlProvider 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)

Aggregations

ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)40 CrnkBoot (io.crnk.core.boot.CrnkBoot)34 Before (org.junit.Before)27 ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)24 Test (org.junit.Test)8 JsonApiUrlBuilder (io.crnk.core.engine.internal.utils.JsonApiUrlBuilder)6 TestModule (io.crnk.test.mock.TestModule)6 Task (io.crnk.core.mock.models.Task)5 ResourceMetaProvider (io.crnk.meta.provider.resource.ResourceMetaProvider)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 ResourceRegistryImpl (io.crnk.core.engine.internal.registry.ResourceRegistryImpl)4 DefaultResourceRegistryPart (io.crnk.core.engine.registry.DefaultResourceRegistryPart)4 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)4 SimpleModule (io.crnk.core.module.SimpleModule)4 PropertiesProvider (io.crnk.core.engine.properties.PropertiesProvider)3 RelationIdTestResource (io.crnk.core.mock.models.RelationIdTestResource)3 ModuleRegistry (io.crnk.core.module.ModuleRegistry)3 CoreModule (io.crnk.core.engine.internal.CoreModule)2 PathBuilder (io.crnk.core.engine.internal.dispatcher.path.PathBuilder)2 DefaultInformationBuilder (io.crnk.core.engine.internal.information.DefaultInformationBuilder)2