Search in sources :

Example 11 with UpdateRequest

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);
}
Also used : Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) UpdateRequest(org.forgerock.json.resource.UpdateRequest) ResourceException(org.forgerock.json.resource.ResourceException) Test(org.testng.annotations.Test)

Example 12 with UpdateRequest

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);
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) UpdateRequest(org.forgerock.json.resource.UpdateRequest) JsonValue(org.forgerock.json.JsonValue) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 13 with UpdateRequest

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
}
Also used : UpdateRequest(org.forgerock.json.resource.UpdateRequest) JsonValue(org.forgerock.json.JsonValue) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 14 with UpdateRequest

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);
}
Also used : Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) UpdateRequest(org.forgerock.json.resource.UpdateRequest) ResourceException(org.forgerock.json.resource.ResourceException) UmaPolicy(org.forgerock.openam.uma.UmaPolicy) Test(org.testng.annotations.Test)

Example 15 with UpdateRequest

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);
    }
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) UpdateRequest(org.forgerock.json.resource.UpdateRequest) ResourceException(org.forgerock.json.resource.ResourceException) Test(org.testng.annotations.Test)

Aggregations

UpdateRequest (org.forgerock.json.resource.UpdateRequest)36 Test (org.testng.annotations.Test)33 ResourceResponse (org.forgerock.json.resource.ResourceResponse)27 JsonValue (org.forgerock.json.JsonValue)26 ResourceException (org.forgerock.json.resource.ResourceException)26 Context (org.forgerock.services.context.Context)16 Matchers.anyString (org.mockito.Matchers.anyString)13 Subject (javax.security.auth.Subject)11 Application (com.sun.identity.entitlement.Application)9 RealmContext (org.forgerock.openam.rest.RealmContext)9 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)7 ClientContext (org.forgerock.services.context.ClientContext)7 HashSet (java.util.HashSet)6 ResourceType (org.forgerock.openam.entitlement.ResourceType)5 EntitlementException (com.sun.identity.entitlement.EntitlementException)4 Responses.newResourceResponse (org.forgerock.json.resource.Responses.newResourceResponse)2 Router (org.forgerock.json.resource.Router)2 UmaPolicy (org.forgerock.openam.uma.UmaPolicy)2 DelegationPermission (com.sun.identity.delegation.DelegationPermission)1 Privilege (com.sun.identity.entitlement.Privilege)1