use of io.crnk.core.engine.internal.CoreModule in project crnk-framework by crnk-project.
the class ModuleRegistryTest method setup.
@Before
public void setup() {
moduleRegistry = new ModuleRegistry();
moduleRegistry.getHttpRequestContextProvider().setServiceUrlProvider(new ConstantServiceUrlProvider("http://localhost"));
resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
testModule = new TestModule();
moduleRegistry.addModule(testModule);
moduleRegistry.addModule(new CoreModule());
moduleRegistry.addModule(new JacksonModule(new ObjectMapper(), false, ImmutableList.of(new OffsetLimitPagingBehavior())));
moduleRegistry.setServiceDiscovery(serviceDiscovery);
moduleRegistry.init(new ObjectMapper());
Assert.assertEquals(resourceRegistry, moduleRegistry.getResourceRegistry());
}
use of io.crnk.core.engine.internal.CoreModule in project crnk-framework by crnk-project.
the class ModuleExtensionTest method setup.
@Before
public void setup() {
optional = false;
moduleRegistry = new ModuleRegistry();
moduleRegistry.addModule(new CoreModule());
moduleRegistry.addModule(new JacksonModule(objectMapper));
consumerModule = Mockito.spy(new ExtensionConsumerModule());
providerModule = Mockito.spy(new ExtensionProviderModule());
}
use of io.crnk.core.engine.internal.CoreModule 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());
}
use of io.crnk.core.engine.internal.CoreModule 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);
}
use of io.crnk.core.engine.internal.CoreModule in project crnk-framework by crnk-project.
the class CrnkBoot method setupComponents.
private void setupComponents() {
// not that the provided default implementation here are added last and
// as a consequence,
// can be overriden by other modules, like the
// JaxrsResourceRepositoryInformationBuilder.
SimpleModule module = new SimpleModule("discovery") {
@Override
public void setupModule(ModuleContext context) {
this.addHttpRequestProcessor(new JsonApiRequestProcessor(context));
super.setupModule(context);
}
};
for (JsonApiExceptionMapper<?> exceptionMapper : getInstancesByType(JsonApiExceptionMapper.class)) {
module.addExceptionMapper(exceptionMapper);
}
for (DocumentFilter filter : getInstancesByType(DocumentFilter.class)) {
module.addFilter(filter);
}
for (Object repository : getInstancesByType(Repository.class)) {
module.addRepository(repository);
}
for (Object repository : serviceDiscovery.getInstancesByAnnotation(JsonApiResourceRepository.class)) {
JsonApiResourceRepository annotation = ClassUtils.getAnnotation(repository.getClass(), JsonApiResourceRepository.class).get();
Class<?> resourceClass = annotation.value();
module.addRepository(resourceClass, repository);
}
for (Object repository : serviceDiscovery.getInstancesByAnnotation(JsonApiRelationshipRepository.class)) {
JsonApiRelationshipRepository annotation = ClassUtils.getAnnotation(repository.getClass(), JsonApiRelationshipRepository.class).get();
module.addRepository(annotation.source(), annotation.target(), repository);
}
moduleRegistry.addModule(module);
moduleRegistry.addModule(new CoreModule());
}
Aggregations