use of io.crnk.core.engine.internal.registry.ResourceRegistryImpl 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.registry.ResourceRegistryImpl in project crnk-framework by crnk-project.
the class ResourceRegistryTest method resetResourceRegistry.
@Before
public void resetResourceRegistry() {
moduleRegistry = new ModuleRegistry();
moduleRegistry.getHttpRequestContextProvider().setServiceUrlProvider(new ConstantServiceUrlProvider(TEST_MODELS_URL));
resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
}
use of io.crnk.core.engine.internal.registry.ResourceRegistryImpl in project crnk-framework by crnk-project.
the class QueryParamsAdapterTest method test.
@Test
public void test() {
ModuleRegistry moduleRegistry = new ModuleRegistry();
moduleRegistry.getHttpRequestContextProvider().setServiceUrlProvider(new ConstantServiceUrlProvider("http://localhost"));
ResourceRegistry resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
QueryParams params = new QueryParams();
DefaultResourceInformationProvider builder = new DefaultResourceInformationProvider(new NullPropertiesProvider(), new OffsetLimitPagingBehavior(), new DefaultResourceFieldInformationProvider(), new JacksonResourceFieldInformationProvider());
builder.init(new DefaultResourceInformationProviderContext(builder, new DefaultInformationBuilder(moduleRegistry.getTypeParser()), moduleRegistry.getTypeParser(), new ObjectMapper()));
ResourceInformation info = builder.build(Task.class);
QueryParamsAdapter adapter = new QueryParamsAdapter(info, params, moduleRegistry);
Assert.assertEquals(Task.class, adapter.getResourceInformation().getResourceClass());
Assert.assertEquals(resourceRegistry, adapter.getResourceRegistry());
}
use of io.crnk.core.engine.internal.registry.ResourceRegistryImpl 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.engine.internal.registry.ResourceRegistryImpl 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());
}
Aggregations