use of io.crnk.core.module.discovery.ReflectionsServiceDiscovery in project crnk-framework by crnk-project.
the class ValidationMetaProviderTest method setup.
private void setup(boolean addValidationProvider) {
CrnkBoot boot = new CrnkBoot();
boot.addModule(new JaxrsModule(null));
boot.setServiceUrlProvider(new ConstantServiceUrlProvider("http://localhost"));
boot.setServiceDiscovery(new ReflectionsServiceDiscovery("io.crnk.validation.mock", new SampleJsonServiceLocator()));
boot.boot();
resourceMetaProvider = new ResourceMetaProvider();
lookup = new MetaLookup();
lookup.setModuleContext(boot.getModuleRegistry().getContext());
lookup.addProvider(resourceMetaProvider);
if (addValidationProvider) {
lookup.addProvider(new ValidationMetaProvider());
}
lookup.initialize();
}
use of io.crnk.core.module.discovery.ReflectionsServiceDiscovery 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();
}
use of io.crnk.core.module.discovery.ReflectionsServiceDiscovery in project crnk-framework by crnk-project.
the class DefaultQuerySpecSerializerTest method setup.
@Before
public void setup() {
CrnkBoot boot = new CrnkBoot();
boot.setServiceUrlProvider(new ConstantServiceUrlProvider("http://127.0.0.1"));
boot.setServiceDiscovery(new ReflectionsServiceDiscovery(String.format("%s,io.crnk.core.queryspec.pagingspec", MockConstants.TEST_MODELS_PACKAGE)));
boot.boot();
resourceRegistry = boot.getResourceRegistry();
urlBuilder = new JsonApiUrlBuilder(resourceRegistry);
}
use of io.crnk.core.module.discovery.ReflectionsServiceDiscovery in project crnk-framework by crnk-project.
the class ResourceRepositoryBaseTest method setup.
@Before
public void setup() {
CrnkBoot boot = new CrnkBoot();
boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
boot.setPropertiesProvider(new PropertiesProvider() {
@Override
public String getProperty(String key) {
if (key.equals(CrnkProperties.RETURN_404_ON_NULL)) {
return "true";
}
return null;
}
});
boot.boot();
repository = new TestRepository();
repository.setResourceRegistry(boot.getResourceRegistry());
}
use of io.crnk.core.module.discovery.ReflectionsServiceDiscovery in project crnk-framework by crnk-project.
the class BraveResponseFilterTest method setup.
@Before
public void setup() {
boot = new CrnkBoot();
boot.setServiceDiscovery(new ReflectionsServiceDiscovery("io.crnk.test.mock.repository", new SampleJsonServiceLocator()));
boot.boot();
span = Mockito.mock(Span.class);
tracing = Mockito.mock(Tracing.class);
tracer = Mockito.mock(Tracer.class);
Mockito.when(tracing.tracer()).thenReturn(tracer);
Mockito.when(tracer.nextSpan()).thenReturn(span);
moduleContext = Mockito.mock(Module.ModuleContext.class);
Mockito.when(moduleContext.getResourceRegistry()).thenReturn(boot.getResourceRegistry());
QuerySpec querySpec = new QuerySpec(Task.class);
queryAdapter = new QuerySpecAdapter(querySpec, boot.getResourceRegistry());
ResourceInformation taskResourceInformation = boot.getResourceRegistry().getEntry(Task.class).getResourceInformation();
requestSpec = Mockito.mock(RepositoryRequestSpec.class);
Mockito.when(requestSpec.getMethod()).thenReturn(HttpMethod.GET);
Mockito.when(requestSpec.getQueryAdapter()).thenReturn(queryAdapter);
Mockito.when(requestSpec.getQuerySpec(taskResourceInformation)).thenReturn(querySpec);
filter = new BraveRepositoryFilter(tracing, moduleContext);
filterContext = Mockito.mock(RepositoryFilterContext.class);
Mockito.when(filterContext.getRequest()).thenReturn(requestSpec);
filterChain = Mockito.mock(RepositoryRequestFilterChain.class);
}
Aggregations