Search in sources :

Example 1 with EmptyServiceDiscovery

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

the class TSGeneratorTest method setup.

@Before
public void setup() {
    Project project = Mockito.mock(Project.class);
    TSGeneratorExtension config = new TSGeneratorExtension(project, null);
    File outputDir = testProjectDir.getRoot();
    MetaModuleConfig metaConfig = new MetaModuleConfig();
    metaConfig.addMetaProvider(new ResourceMetaProvider());
    MetaModule metaModule = MetaModule.createServerModule(metaConfig);
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceDiscovery(new EmptyServiceDiscovery());
    boot.addModule(metaModule);
    boot.boot();
    generator = new TSGenerator(outputDir, metaModule.getLookup(), config);
}
Also used : Project(org.gradle.api.Project) CrnkBoot(io.crnk.core.boot.CrnkBoot) ResourceMetaProvider(io.crnk.meta.provider.resource.ResourceMetaProvider) File(java.io.File) MetaModule(io.crnk.meta.MetaModule) TSGeneratorExtension(io.crnk.gen.typescript.TSGeneratorExtension) MetaModuleConfig(io.crnk.meta.MetaModuleConfig) EmptyServiceDiscovery(io.crnk.core.module.discovery.EmptyServiceDiscovery) Before(org.junit.Before)

Example 2 with EmptyServiceDiscovery

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

the class SecurityModuleTest method setup.

@Before
public void setup() {
    // TODO simplify ones simple module is fixed
    SimpleModule appModule = new SimpleModule("app") {

        @Override
        public void setupModule(ModuleContext context) {
            super.setupModule(context);
            context.addSecurityProvider(new SecurityProvider() {

                @Override
                public boolean isUserInRole(String role) {
                    return role.equals(allowedRule);
                }
            });
        }
    };
    appModule.addRepository(new TaskRepository());
    appModule.addRepository(new ProjectRepository());
    Builder builder = SecurityConfig.builder();
    builder.permitAll(ResourcePermission.GET);
    builder.permitRole("taskRole", Task.class, ResourcePermission.ALL);
    builder.permitRole("projectRole", "projects", ResourcePermission.POST);
    SecurityConfig config = builder.build();
    securityModule = SecurityModule.newServerModule(config);
    Assert.assertSame(config, securityModule.getConfig());
    ModuleRegistry moduleRegistry = new ModuleRegistry();
    moduleRegistry.setServiceDiscovery(new EmptyServiceDiscovery());
    moduleRegistry.setResourceRegistry(new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry));
    moduleRegistry.addModule(securityModule);
    moduleRegistry.addModule(appModule);
    moduleRegistry.addModule(new JacksonModule(new ObjectMapper(), false, ImmutableList.of(new OffsetLimitPagingBehavior())));
    moduleRegistry.addModule(new CoreModule());
    moduleRegistry.init(new ObjectMapper());
}
Also used : OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) ProjectRepository(io.crnk.security.model.ProjectRepository) TaskRepository(io.crnk.security.model.TaskRepository) Builder(io.crnk.security.SecurityConfig.Builder) ModuleRegistry(io.crnk.core.module.ModuleRegistry) ResourceRegistryImpl(io.crnk.core.engine.internal.registry.ResourceRegistryImpl) JacksonModule(io.crnk.core.engine.internal.jackson.JacksonModule) SecurityProvider(io.crnk.core.engine.security.SecurityProvider) DefaultResourceRegistryPart(io.crnk.core.engine.registry.DefaultResourceRegistryPart) CoreModule(io.crnk.core.engine.internal.CoreModule) SimpleModule(io.crnk.core.module.SimpleModule) EmptyServiceDiscovery(io.crnk.core.module.discovery.EmptyServiceDiscovery) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 3 with EmptyServiceDiscovery

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

use of io.crnk.core.module.discovery.EmptyServiceDiscovery 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)

Aggregations

EmptyServiceDiscovery (io.crnk.core.module.discovery.EmptyServiceDiscovery)4 Before (org.junit.Before)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 CrnkBoot (io.crnk.core.boot.CrnkBoot)2 CoreModule (io.crnk.core.engine.internal.CoreModule)2 JacksonModule (io.crnk.core.engine.internal.jackson.JacksonModule)2 ResourceRegistryImpl (io.crnk.core.engine.internal.registry.ResourceRegistryImpl)2 DefaultResourceRegistryPart (io.crnk.core.engine.registry.DefaultResourceRegistryPart)2 ModuleRegistry (io.crnk.core.module.ModuleRegistry)2 MetaModule (io.crnk.meta.MetaModule)2 ResourceMetaProvider (io.crnk.meta.provider.resource.ResourceMetaProvider)2 SecurityProvider (io.crnk.core.engine.security.SecurityProvider)1 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)1 SimpleModule (io.crnk.core.module.SimpleModule)1 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)1 TSGeneratorConfig (io.crnk.gen.typescript.TSGeneratorConfig)1 TSGeneratorExtension (io.crnk.gen.typescript.TSGeneratorExtension)1 TSGenerator (io.crnk.gen.typescript.internal.TSGenerator)1 MetaModuleConfig (io.crnk.meta.MetaModuleConfig)1 Builder (io.crnk.security.SecurityConfig.Builder)1