use of io.crnk.core.engine.properties.PropertiesProvider in project crnk-framework by crnk-project.
the class ResourcePostTest method onPostingReadOnlyFieldShouldIgnoreWithIgnoreBehavior.
@Test
public void onPostingReadOnlyFieldShouldIgnoreWithIgnoreBehavior() throws Exception {
// GIVEN
Document requestDocument = new Document();
Resource data = createTask();
data.getAttributes().put("readOnlyValue", objectMapper.readTree("\"newValue\""));
requestDocument.setData(Nullable.of((Object) data));
JsonPath path = pathBuilder.build("/tasks");
PropertiesProvider propertiesProvider = new PropertiesProvider() {
@Override
public String getProperty(String key) {
if (CrnkProperties.RESOURCE_FIELD_IMMUTABLE_WRITE_BEHAVIOR.equals(key)) {
return ResourceFieldImmutableWriteBehavior.IGNORE.toString();
}
return null;
}
};
ResourcePost sut = new ResourcePost(resourceRegistry, propertiesProvider, typeParser, objectMapper, documentMapper, modificationFilters);
// WHEN
Response response = sut.handle(path, emptyTaskQuery, null, requestDocument);
String persistedValue = response.getDocument().getSingleData().get().getAttributes().get("readOnlyValue").asText();
Assert.assertEquals("someReadOnlyValue", persistedValue);
}
use of io.crnk.core.engine.properties.PropertiesProvider in project crnk-framework by crnk-project.
the class ResourcePostTest method onPostingReadOnlyFieldReturnBadRequestWithFailBehavior.
@Test
public void onPostingReadOnlyFieldReturnBadRequestWithFailBehavior() throws Exception {
// GIVEN
Document requestDocument = new Document();
Resource data = createTask();
data.getAttributes().put("readOnlyValue", objectMapper.readTree("\"newValue\""));
requestDocument.setData(Nullable.of((Object) data));
JsonPath path = pathBuilder.build("/tasks");
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;
}
};
ResourcePost sut = new ResourcePost(resourceRegistry, propertiesProvider, typeParser, objectMapper, documentMapper, modificationFilters);
// WHEN
try {
sut.handle(path, 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());
}
}
use of io.crnk.core.engine.properties.PropertiesProvider in project crnk-framework by crnk-project.
the class ControllerRegistryBuilderTest method onBuildShouldAddAllControllers.
@Test
public void onBuildShouldAddAllControllers() throws Exception {
// GIVEN
PropertiesProvider propertiesProvider = Mockito.mock(PropertiesProvider.class);
ResourceFilterDirectory resourceFilterDirectory = Mockito.mock(ResourceFilterDirectory.class);
ControllerRegistryBuilder sut = new ControllerRegistryBuilder(null, null, null, propertiesProvider, resourceFilterDirectory, (List) Collections.emptyList());
// WHEN
ControllerRegistry result = sut.build();
// THEN
result.getController(new ResourcePath("path"), "GET");
}
use of io.crnk.core.engine.properties.PropertiesProvider in project crnk-framework by crnk-project.
the class IncludeLookupSetterBaseTest method includePropertiesProviderAllTrueRelationshipLookup.
@Test
public void includePropertiesProviderAllTrueRelationshipLookup() throws Exception {
PropertiesProvider propertiesProvider = new PropertiesProvider() {
@Override
public String getProperty(String key) {
if (key.equalsIgnoreCase(CrnkProperties.INCLUDE_AUTOMATICALLY_OVERWRITE)) {
return "true";
}
return null;
}
};
mapper = new DocumentMapper(resourceRegistry, objectMapper, propertiesProvider, resourceFilterDirectory);
QuerySpec querySpec = new QuerySpec(Task.class);
querySpec.includeRelation(Arrays.asList("project"));
Task task = new Task();
task.setId(1L);
Document document = mapper.toDocument(toResponse(task), toAdapter(querySpec));
Resource taskResource = document.getSingleData().get();
assertNotNull(taskResource.getRelationships().get("project"));
assertNotNull(taskResource.getRelationships().get("project").getData());
}
use of io.crnk.core.engine.properties.PropertiesProvider in project crnk-framework by crnk-project.
the class IncludeLookupUtilTest method checkDefaultLookupIncludeBehavior.
@Test
public void checkDefaultLookupIncludeBehavior() {
Assert.assertEquals(LookupIncludeBehavior.DEFAULT, IncludeLookupUtil.getGlolbalLookupIncludeBehavior(null));
PropertiesProvider propertiesProvider = Mockito.mock(PropertiesProvider.class);
Assert.assertEquals(LookupIncludeBehavior.DEFAULT, IncludeLookupUtil.getGlolbalLookupIncludeBehavior(propertiesProvider));
Mockito.when(propertiesProvider.getProperty(CrnkProperties.INCLUDE_AUTOMATICALLY)).thenReturn("true");
Assert.assertEquals(LookupIncludeBehavior.AUTOMATICALLY_WHEN_NULL, IncludeLookupUtil.getGlolbalLookupIncludeBehavior(propertiesProvider));
Mockito.when(propertiesProvider.getProperty(CrnkProperties.INCLUDE_AUTOMATICALLY)).thenReturn("false");
Assert.assertEquals(LookupIncludeBehavior.DEFAULT, IncludeLookupUtil.getGlolbalLookupIncludeBehavior(propertiesProvider));
Mockito.when(propertiesProvider.getProperty(CrnkProperties.INCLUDE_AUTOMATICALLY_OVERWRITE)).thenReturn("true");
Assert.assertEquals(LookupIncludeBehavior.AUTOMATICALLY_ALWAYS, IncludeLookupUtil.getGlolbalLookupIncludeBehavior(propertiesProvider));
Mockito.when(propertiesProvider.getProperty(CrnkProperties.INCLUDE_AUTOMATICALLY_OVERWRITE)).thenReturn("false");
Assert.assertEquals(LookupIncludeBehavior.DEFAULT, IncludeLookupUtil.getGlolbalLookupIncludeBehavior(propertiesProvider));
}
Aggregations