use of io.crnk.core.engine.properties.PropertiesProvider in project crnk-framework by crnk-project.
the class CrnkConfigV3 method crnkBoot.
@Bean
@ConditionalOnMissingBean(CrnkBoot.class)
public CrnkBoot crnkBoot(ServiceDiscovery serviceDiscovery) {
CrnkBoot boot = new CrnkBoot();
boot.setObjectMapper(objectMapper);
if (properties.getDomainName() != null && properties.getPathPrefix() != null) {
String baseUrl = properties.getDomainName() + properties.getPathPrefix();
boot.setServiceUrlProvider(new ConstantServiceUrlProvider(baseUrl));
}
boot.setServiceDiscovery(serviceDiscovery);
boot.setDefaultPageLimit(properties.getDefaultPageLimit());
boot.setMaxPageLimit(properties.getMaxPageLimit());
boot.setPropertiesProvider(new PropertiesProvider() {
@Override
public String getProperty(String key) {
if (CrnkProperties.RESOURCE_SEARCH_PACKAGE.equals(key)) {
return properties.getResourcePackage();
}
if (CrnkProperties.RESOURCE_DEFAULT_DOMAIN.equals(key)) {
return properties.getDomainName();
}
if (CrnkProperties.WEB_PATH_PREFIX.equals(key)) {
return properties.getPathPrefix();
}
if (CrnkProperties.ALLOW_UNKNOWN_ATTRIBUTES.equals(key)) {
return String.valueOf(properties.getAllowUnknownAttributes());
}
if (CrnkProperties.ALLOW_UNKNOWN_PARAMETERS.equals(key)) {
return String.valueOf(properties.getAllowUnknownParameters());
}
if (CrnkProperties.RETURN_404_ON_NULL.equals(key)) {
return String.valueOf(properties.getReturn404OnNull());
}
return applicationContext.getEnvironment().getProperty(key);
}
});
boot.setAllowUnknownAttributes();
boot.addModule(new ServletModule(boot.getModuleRegistry().getHttpRequestContextProvider()));
boot.boot();
return boot;
}
use of io.crnk.core.engine.properties.PropertiesProvider in project crnk-framework by crnk-project.
the class CrnkBootTest method setServiceLocator.
@Test
public void setServiceLocator() {
JsonServiceLocator locator = mock(JsonServiceLocator.class);
PropertiesProvider propertiesProvider = mock(PropertiesProvider.class);
Mockito.when(propertiesProvider.getProperty(eq(CrnkProperties.RESOURCE_SEARCH_PACKAGE))).thenReturn("a.b.c");
CrnkBoot boot = new CrnkBoot();
boot.setPropertiesProvider(propertiesProvider);
boot.setServiceLocator(locator);
boot.setServiceDiscoveryFactory(mock(ServiceDiscoveryFactory.class));
boot.boot();
ReflectionsServiceDiscovery serviceDiscovery = (ReflectionsServiceDiscovery) boot.getServiceDiscovery();
Assert.assertSame(locator, serviceDiscovery.getLocator());
}
use of io.crnk.core.engine.properties.PropertiesProvider in project crnk-framework by crnk-project.
the class CrnkBootTest method setConstantServiceUrlProvider.
@Test
public void setConstantServiceUrlProvider() {
CrnkBoot boot = new CrnkBoot();
boot.setServiceDiscoveryFactory(serviceDiscoveryFactory);
final Properties properties = new Properties();
properties.put(CrnkProperties.RESOURCE_DEFAULT_DOMAIN, "http://something");
PropertiesProvider propertiesProvider = new PropertiesProvider() {
@Override
public String getProperty(String key) {
return (String) properties.get(key);
}
};
boot.setPropertiesProvider(propertiesProvider);
boot.boot();
ServiceUrlProvider serviceUrlProvider = boot.getServiceUrlProvider();
Assert.assertTrue(serviceUrlProvider instanceof ConstantServiceUrlProvider);
Assert.assertEquals("http://something", serviceUrlProvider.getUrl());
}
use of io.crnk.core.engine.properties.PropertiesProvider in project crnk-framework by crnk-project.
the class IncludeLookupSetterBaseTest method includePropertiesProviderNonOverwriteRelationshipLookup.
@Test
public void includePropertiesProviderNonOverwriteRelationshipLookup() throws Exception {
PropertiesProvider propertiesProvider = new PropertiesProvider() {
@Override
public String getProperty(String key) {
if (key.equalsIgnoreCase(CrnkProperties.INCLUDE_AUTOMATICALLY_OVERWRITE)) {
return "false";
}
return null;
}
};
mapper = new DocumentMapper(resourceRegistry, objectMapper, propertiesProvider, resourceFilterDirectory);
QuerySpec querySpec = new QuerySpec(Task.class);
querySpec.includeRelation(Arrays.asList("project"));
Project project = new Project();
project.setId(12L);
Task task = new Task();
task.setId(1L);
task.setProject(project);
Document document = mapper.toDocument(toResponse(task), toAdapter(querySpec));
Resource taskResource = document.getSingleData().get();
Relationship relationship = taskResource.getRelationships().get("project");
assertNotNull(relationship);
assertEquals(relationship.getSingleData().get().getId(), "12");
}
use of io.crnk.core.engine.properties.PropertiesProvider in project crnk-framework by crnk-project.
the class FallbackServiceDiscoveryFactoryTest method returnDefaultDiscoveryIfAvailable.
@Test
public void returnDefaultDiscoveryIfAvailable() {
PropertiesProvider propertiesProvider = new NullPropertiesProvider();
DefaultServiceDiscoveryFactory defaultFactory = new DefaultServiceDiscoveryFactory();
FallbackServiceDiscoveryFactory fallbackFactory = new FallbackServiceDiscoveryFactory(defaultFactory, new SampleJsonServiceLocator(), propertiesProvider);
Assert.assertTrue(fallbackFactory.getInstance() instanceof TestServiceDiscovery);
}
Aggregations