use of io.crnk.core.module.ModuleRegistry in project crnk-framework by crnk-project.
the class QuerySpecAdapterTest method test.
@Test
public void test() {
ModuleRegistry moduleRegistry = new ModuleRegistry();
ResourceRegistry resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
ResourceInformation resourceInformation = new ResourceInformation(moduleRegistry.getTypeParser(), Task.class, "tasks", null, null, new OffsetLimitPagingBehavior());
resourceRegistry.addEntry(new RegistryEntry(new DirectResponseResourceEntry(null, new ResourceRepositoryInformationImpl("tasks", resourceInformation, RepositoryMethodAccess.ALL))));
QuerySpec spec = new QuerySpec(Task.class);
spec.includeField(Arrays.asList("test"));
spec.includeRelation(Arrays.asList("relation"));
QuerySpecAdapter adapter = new QuerySpecAdapter(spec, resourceRegistry);
Assert.assertEquals(Task.class, adapter.getResourceInformation().getResourceClass());
Assert.assertEquals(spec, adapter.getQuerySpec());
TypedParams<IncludedFieldsParams> includedFields = adapter.getIncludedFields();
IncludedFieldsParams includedFieldsParams = includedFields.getParams().get("tasks");
Assert.assertEquals(1, includedFieldsParams.getParams().size());
Assert.assertEquals("test", includedFieldsParams.getParams().iterator().next());
TypedParams<IncludedRelationsParams> includedRelations = adapter.getIncludedRelations();
IncludedRelationsParams includedRelationsParams = includedRelations.getParams().get("tasks");
Assert.assertEquals(1, includedRelationsParams.getParams().size());
Assert.assertEquals("relation", includedRelationsParams.getParams().iterator().next().getPath());
Assert.assertEquals(new OffsetLimitPagingSpec(), adapter.getPagingSpec());
}
use of io.crnk.core.module.ModuleRegistry in project crnk-framework by crnk-project.
the class JaxrsModuleTest method setup.
@Before
public void setup() {
final ModuleRegistry moduleRegistry = new ModuleRegistry();
builder = new JaxrsModule.JaxrsResourceRepositoryInformationProvider();
final ResourceInformationProvider resourceInformationProvider = new DefaultResourceInformationProvider(moduleRegistry.getPropertiesProvider(), ImmutableList.<PagingBehavior>of(new OffsetLimitPagingBehavior()), new DefaultResourceFieldInformationProvider(), new JacksonResourceFieldInformationProvider());
resourceInformationProvider.init(new DefaultResourceInformationProviderContext(resourceInformationProvider, new DefaultInformationBuilder(moduleRegistry.getTypeParser()), moduleRegistry.getTypeParser(), new ObjectMapper()));
context = new RepositoryInformationProviderContext() {
@Override
public ResourceInformationProvider getResourceInformationBuilder() {
return resourceInformationProvider;
}
@Override
public TypeParser getTypeParser() {
return moduleRegistry.getTypeParser();
}
@Override
public InformationBuilder builder() {
return new DefaultInformationBuilder(moduleRegistry.getTypeParser());
}
};
}
use of io.crnk.core.module.ModuleRegistry 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.module.ModuleRegistry in project crnk-framework by crnk-project.
the class ApprovalManagerTest method setup.
@Before
public void setup() {
runtimeService = Mockito.mock(RuntimeService.class);
TaskService taskService = Mockito.mock(TaskService.class);
repositoryFacade = Mockito.mock(ResourceRepositoryV2.class);
ApprovalMapper approvalMapper = new ApprovalMapper();
ActivitiResourceMapper resourceMapper = new ActivitiResourceMapper(new TypeParser(), new DefaultDateTimeMapper());
ResourceInformation information = Mockito.mock(ResourceInformation.class);
registryEntry = Mockito.mock(RegistryEntry.class);
ResourceRegistry resourceRegistry = Mockito.mock(ResourceRegistry.class);
Mockito.when(registryEntry.getResourceInformation()).thenReturn(information);
Mockito.when(registryEntry.getResourceRepositoryFacade()).thenReturn(repositoryFacade);
Mockito.when(information.getResourceType()).thenReturn("schedule");
Mockito.when(information.getId(Mockito.any())).thenReturn(mockId);
Mockito.when(resourceRegistry.getEntry(Mockito.any(Class.class))).thenReturn(registryEntry);
Mockito.when(resourceRegistry.getEntry(Mockito.any(String.class))).thenReturn(registryEntry);
ModuleRegistry moduleRegistry = Mockito.mock(ModuleRegistry.class);
Mockito.when(moduleRegistry.getResourceRegistry()).thenReturn(resourceRegistry);
originalResource = new Schedule();
originalResource.setId(mockId);
originalResource.setName("Jane");
Mockito.when(repositoryFacade.findOne(Mockito.any(Long.class), Mockito.any(QuerySpec.class))).thenReturn(originalResource);
manager = new ApprovalManager();
manager.init(runtimeService, taskService, resourceMapper, approvalMapper, moduleRegistry);
}
use of io.crnk.core.module.ModuleRegistry 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);
}
Aggregations