use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.
the class AuditFilterTest method shouldAuditSuccessForResults.
@Test
public void shouldAuditSuccessForResults() throws Exception {
ResourceResponse response = mock(ResourceResponse.class);
Promise<ResourceResponse, ResourceException> myPromise = Promises.newResultPromise(response);
given(filterChain.handleUpdate(any(Context.class), any(UpdateRequest.class))).willReturn(myPromise);
given(auditorFactory.create(context, updateRequest)).willReturn(auditor);
AuditFilter auditFilter = new AuditFilter(debug, auditorFactory);
auditFilter.filterUpdate(context, updateRequest, filterChain);
verify(auditor).auditAccessSuccess(null);
}
use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.
the class ScriptResourceTest method shouldUpdateScriptConfigurationWithoutError.
@Test
public void shouldUpdateScriptConfigurationWithoutError() throws Exception {
// given
String resourceId = "1234567890";
JsonValue requestJson = json(object(field(SCRIPT_NAME, "MyJavaScript"), field(SCRIPT_DESCRIPTION, "A test script configuration"), field(SCRIPT_TEXT, encodeScript), field(SCRIPT_LANGUAGE, "JAVASCRIPT"), field(SCRIPT_CONTEXT, "POLICY_CONDITION")));
UpdateRequest updateRequest = mock(UpdateRequest.class);
when(updateRequest.getContent()).thenReturn(requestJson);
// when
ResourceResponse response = scriptResource.updateInstance(context, resourceId, updateRequest).getOrThrowUninterruptibly();
// then
assertNotNull(response);
assertNotNull(response.getId());
JsonValue responseJson = response.getContent();
assertEquals(responseJson.get(SCRIPT_NAME).asString(), "MyJavaScript");
assertEquals(responseJson.get(SCRIPT_DESCRIPTION).asString(), "A test script configuration");
assertEquals(responseJson.get(SCRIPT_TEXT).asString(), encodeScript);
assertEquals(getLanguageFromString(responseJson.get(SCRIPT_LANGUAGE).asString()), JAVASCRIPT);
assertEquals(getContextFromString(responseJson.get(SCRIPT_CONTEXT).asString()), POLICY_CONDITION);
}
use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.
the class ScriptResourceTest method shouldFailIfNoLanguageIsSuppliedOnUpdate.
@Test(expectedExceptions = BadRequestException.class)
public void shouldFailIfNoLanguageIsSuppliedOnUpdate() throws ResourceException {
// given
String resourceId = "1234567890";
JsonValue requestJson = json(object(field(SCRIPT_NAME, "MyJavaScript"), field(SCRIPT_TEXT, encodeScript), field(SCRIPT_CONTEXT, "POLICY_CONDITION")));
UpdateRequest updateRequest = mock(UpdateRequest.class);
when(updateRequest.getContent()).thenReturn(requestJson);
// when
scriptResource.updateInstance(context, resourceId, updateRequest).getOrThrowUninterruptibly();
// then - exception
}
use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.
the class UmaPolicyResourceTest method shouldHandledFailedUpdatePolicy.
@Test
@SuppressWarnings("unchecked")
public void shouldHandledFailedUpdatePolicy() {
//Given
Context context = mock(Context.class);
UpdateRequest request = Requests.newUpdateRequest("/policies", json(object()));
ResourceException resourceException = mock(ResourceException.class);
Promise<UmaPolicy, ResourceException> promise = Promises.newExceptionPromise(resourceException);
given(policyService.updatePolicy(context, "RESOURCE_SET_UID", request.getContent())).willReturn(promise);
//When
Promise<ResourceResponse, ResourceException> result = policyResource.updateInstance(context, "RESOURCE_SET_UID", request);
//Then
assertThat(result).failedWithResourceException().isEqualTo(resourceException);
}
use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.
the class UmaEnabledFilterTest method testFilterUpdate.
@Test(dataProvider = "factories")
public void testFilterUpdate(UmaProviderSettingsFactory factory, boolean expectFailure) throws Exception {
// Given
UmaEnabledFilter filter = new UmaEnabledFilter(factory);
UpdateRequest request = Requests.newUpdateRequest("test", json(object()));
// When
Promise<ResourceResponse, ResourceException> promise = filter.filterUpdate(context, request, requestHandler);
// Then
checkResult(expectFailure, promise);
if (expectFailure) {
verifyNoMoreInteractions(requestHandler);
} else {
verify(requestHandler).handleUpdate(context, request);
}
}
Aggregations