use of io.crnk.core.engine.information.resource.ResourceInformationProvider in project crnk-framework by crnk-project.
the class DefaultResourceInformationProviderTest method shouldOverrideGlobalLookupBehavior.
@Test
public void shouldOverrideGlobalLookupBehavior() throws Exception {
ResourceInformationProvider resourceInformationProviderWithProperty = getResourceInformationProviderWithProperty(CrnkProperties.INCLUDE_AUTOMATICALLY_OVERWRITE, "true");
ResourceInformation resourceInformation = resourceInformationProviderWithProperty.build(JsonResourceWithOverrideLookupBehaviorRelationship.class);
// Global says automatically always, but relationship says only when null.
// Relationship annotation should win in this case.
assertThat(resourceInformation.getRelationshipFields()).extracting("lookupIncludeBehavior").contains(LookupIncludeBehavior.AUTOMATICALLY_WHEN_NULL);
}
use of io.crnk.core.engine.information.resource.ResourceInformationProvider in project crnk-framework by crnk-project.
the class AbstractQueryParamsTest method setup.
@Before
public void setup() {
JsonServiceLocator jsonServiceLocator = new SampleJsonServiceLocator();
ResourceInformationProvider resourceInformationProvider = new DefaultResourceInformationProvider(new NullPropertiesProvider(), (PagingBehavior) null, new DefaultResourceFieldInformationProvider(), new JacksonResourceFieldInformationProvider());
SimpleModule testModule = new SimpleModule("test");
CrnkBoot boot = new CrnkBoot();
boot.addModule(testModule);
boot.boot();
moduleRegistry = boot.getModuleRegistry();
resourceRegistry = boot.getResourceRegistry();
converter = new DefaultQueryParamsConverter(resourceRegistry);
paramsToSpecConverter = new DefaultQuerySpecConverter(moduleRegistry);
}
use of io.crnk.core.engine.information.resource.ResourceInformationProvider 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.engine.information.resource.ResourceInformationProvider in project crnk-framework by crnk-project.
the class DefaultResourceRepositoryInformationProvider method build.
private RepositoryInformation build(Object repository, Class<? extends Object> repositoryClass, RepositoryInformationProviderContext context) {
Class<?> resourceClass = getResourceClass(repository, repositoryClass);
ResourceInformationProvider resourceInformationProvider = context.getResourceInformationBuilder();
PreconditionUtil.assertTrue("cannot get ResourceInformation for " + resourceClass, resourceInformationProvider.accept(resourceClass));
ResourceInformation resourceInformation = resourceInformationProvider.build(resourceClass);
String path = getPath(resourceInformation, repository);
return new ResourceRepositoryInformationImpl(path, resourceInformation, buildActions(repositoryClass), getAccess(repository));
}
use of io.crnk.core.engine.information.resource.ResourceInformationProvider 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();
}
Aggregations