use of io.crnk.core.engine.properties.PropertiesProvider in project crnk-framework by crnk-project.
the class FallbackServiceDiscoveryFactoryTest method fallbackToEmptyDiscoveryIfNoPackageAndDefaultAvailable.
@Test
public void fallbackToEmptyDiscoveryIfNoPackageAndDefaultAvailable() {
PropertiesProvider propertiesProvider = Mockito.mock(PropertiesProvider.class);
ServiceDiscoveryFactory defaultFactory = new ServiceDiscoveryFactory() {
@Override
public ServiceDiscovery getInstance() {
return null;
}
};
FallbackServiceDiscoveryFactory fallbackFactory = new FallbackServiceDiscoveryFactory(defaultFactory, new SampleJsonServiceLocator(), propertiesProvider);
Assert.assertTrue(fallbackFactory.getInstance() instanceof EmptyServiceDiscovery);
}
use of io.crnk.core.engine.properties.PropertiesProvider in project crnk-framework by crnk-project.
the class FallbackServiceDiscoveryFactoryTest method fallbackToReflectionsIfNoDefaultAvailable.
@Test
public void fallbackToReflectionsIfNoDefaultAvailable() {
PropertiesProvider propertiesProvider = Mockito.mock(PropertiesProvider.class);
Mockito.when(propertiesProvider.getProperty(Mockito.eq(CrnkProperties.RESOURCE_SEARCH_PACKAGE))).thenReturn("a.b.c");
ServiceDiscoveryFactory defaultFactory = new ServiceDiscoveryFactory() {
@Override
public ServiceDiscovery getInstance() {
return null;
}
};
FallbackServiceDiscoveryFactory fallbackFactory = new FallbackServiceDiscoveryFactory(defaultFactory, new SampleJsonServiceLocator(), propertiesProvider);
Assert.assertTrue(fallbackFactory.getInstance() instanceof ReflectionsServiceDiscovery);
}
use of io.crnk.core.engine.properties.PropertiesProvider in project crnk-framework by crnk-project.
the class CrnkConfigV3Test method checkProperties.
@Test
public void checkProperties() {
ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class);
Mockito.when(applicationContext.getEnvironment()).thenReturn(Mockito.mock(Environment.class));
CrnkSpringBootProperties properties = new CrnkSpringBootProperties();
properties.setDomainName("testDomain");
properties.setDefaultPageLimit(12L);
properties.setMaxPageLimit(20L);
properties.setPathPrefix("prefix");
properties.setAllowUnknownAttributes(true);
properties.setReturn404OnNull(true);
properties.setResourcePackage("ch.something");
ObjectMapper objectMapper = new ObjectMapper();
CrnkConfigV3 config = new CrnkConfigV3(properties, objectMapper);
config.setApplicationContext(applicationContext);
SpringServiceDiscovery serviceDiscovery = Mockito.mock(SpringServiceDiscovery.class);
CrnkBoot boot = config.crnkBoot(serviceDiscovery);
PropertiesProvider propertiesProvider = boot.getPropertiesProvider();
Assert.assertEquals("testDomain", propertiesProvider.getProperty(CrnkProperties.RESOURCE_DEFAULT_DOMAIN));
Assert.assertEquals("ch.something", propertiesProvider.getProperty(CrnkProperties.RESOURCE_SEARCH_PACKAGE));
Assert.assertEquals("prefix", propertiesProvider.getProperty(CrnkProperties.WEB_PATH_PREFIX));
Assert.assertEquals("true", propertiesProvider.getProperty(CrnkProperties.ALLOW_UNKNOWN_ATTRIBUTES));
Assert.assertEquals("true", propertiesProvider.getProperty(CrnkProperties.RETURN_404_ON_NULL));
DefaultQuerySpecDeserializer deserializer = (DefaultQuerySpecDeserializer) boot.getQuerySpecDeserializer();
Assert.assertTrue(deserializer.getAllowUnknownAttributes());
ConstantServiceUrlProvider constantServiceUrlProvider = (ConstantServiceUrlProvider) boot.getServiceUrlProvider();
Assert.assertEquals("testDomainprefix", constantServiceUrlProvider.getUrl());
Assert.assertSame(objectMapper, boot.getObjectMapper());
Assert.assertNotNull(boot.getModuleRegistry().getSecurityProvider());
}
use of io.crnk.core.engine.properties.PropertiesProvider in project crnk-framework by crnk-project.
the class DefaultResourceInformationProviderTest method getResourceInformationProviderWithProperty.
private ResourceInformationProvider getResourceInformationProviderWithProperty(String key, String value) {
PropertiesProvider propertiesProvider = Mockito.mock(PropertiesProvider.class);
Mockito.when(propertiesProvider.getProperty(Mockito.eq(key))).thenReturn(value);
ResourceInformationProvider resourceInformationProvider = new DefaultResourceInformationProvider(propertiesProvider, new OffsetLimitPagingBehavior(), new DefaultResourceFieldInformationProvider(), new JacksonResourceFieldInformationProvider());
resourceInformationProvider.init(context);
return resourceInformationProvider;
}
use of io.crnk.core.engine.properties.PropertiesProvider in project crnk-framework by crnk-project.
the class ResourcePatchTest method onPatchingReadOnlyFieldReturnBadRequestWithFailBehavior.
@Test
public void onPatchingReadOnlyFieldReturnBadRequestWithFailBehavior() throws Exception {
// GIVEN
Document requestDocument = new Document();
Resource data = createTask();
requestDocument.setData(Nullable.of((Object) data));
JsonPath postPath = pathBuilder.build("/tasks");
ResourcePost post = new ResourcePost(resourceRegistry, PROPERTIES_PROVIDER, typeParser, objectMapper, documentMapper, modificationFilters);
post.handle(postPath, emptyTaskQuery, null, requestDocument);
PropertiesProvider propertiesProvider = new PropertiesProvider() {
@Override
public String getProperty(String key) {
if (CrnkProperties.RESOURCE_FIELD_IMMUTABLE_WRITE_BEHAVIOR.equals(key)) {
return ResourceFieldImmutableWriteBehavior.FAIL.toString();
}
return null;
}
};
ResourcePatch sut = new ResourcePatch(resourceRegistry, propertiesProvider, typeParser, objectMapper, documentMapper, modificationFilters);
data.getAttributes().put("readOnlyValue", objectMapper.readTree("\"newValue\""));
// WHEN
try {
JsonPath patchPath = pathBuilder.build("/tasks/" + data.getId());
sut.handle(patchPath, emptyTaskQuery, null, requestDocument);
Assert.fail("should not be allowed to update read-only field");
} catch (ForbiddenException e) {
Assert.assertEquals("field 'readOnlyValue' cannot be modified", e.getMessage());
}
}
Aggregations