Search in sources :

Example 31 with UpdateRequest

use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.

the class Requester method update.

/**
     * Request to update a specified resource at a specified endpoint.
     *
     * @param location Endpoint destination of this request. May not be null.
     * @param resourceId Resource ID to update. May not be null.
     * @param payload Payload of the updated resource. May not be null.
     * @param context Context of this request.
     * @return The {@link org.forgerock.json.JsonValue} returned from the endpoint.
     * @throws ResourceException If any exception occurred during processing.
     */
public JsonValue update(String location, String resourceId, JsonValue payload, Context context) throws ResourceException {
    Reject.ifTrue(StringUtils.isEmpty(location), "The endpoint destination may not be null or empty.");
    Reject.ifTrue(StringUtils.isEmpty(resourceId), "The resourceId to update may not be null or empty.");
    Reject.ifNull(payload, "The payload object to create must not be null.");
    final Router rootRouter = router.get();
    final UpdateRequest updateRequest = Requests.newUpdateRequest(location, resourceId, payload);
    return rootRouter.handleUpdate(context, updateRequest).getOrThrowUninterruptibly().getContent();
}
Also used : UpdateRequest(org.forgerock.json.resource.UpdateRequest) Router(org.forgerock.json.resource.Router)

Example 32 with UpdateRequest

use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.

the class ScriptResourceTest method shouldFailIfNoScriptIsSuppliedOnUpdate.

@Test(expectedExceptions = BadRequestException.class)
public void shouldFailIfNoScriptIsSuppliedOnUpdate() throws ResourceException {
    // given
    String resourceId = "1234567890";
    JsonValue requestJson = json(object(field(SCRIPT_NAME, "MyJavaScript"), field(SCRIPT_LANGUAGE, "JAVASCRIPT"), 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 33 with UpdateRequest

use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.

the class ScriptResourceTest method shouldFailIfNoContextIsSuppliedOnUpdate.

@Test(expectedExceptions = BadRequestException.class)
public void shouldFailIfNoContextIsSuppliedOnUpdate() throws ResourceException {
    // given
    String resourceId = "1234567890";
    JsonValue requestJson = json(object(field(SCRIPT_NAME, "MyJavaScript"), field(SCRIPT_TEXT, "var a = 123;var b = 456;"), field(SCRIPT_LANGUAGE, "JAVASCRIPT")));
    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 34 with UpdateRequest

use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.

the class ScriptResourceTest method shouldFailIfNoNameIsSuppliedOnUpdate.

@Test(expectedExceptions = BadRequestException.class)
public void shouldFailIfNoNameIsSuppliedOnUpdate() throws ResourceException {
    // given
    String resourceId = "1234567890";
    JsonValue requestJson = json(object(field(SCRIPT_TEXT, encodeScript), field(SCRIPT_LANGUAGE, "JAVASCRIPT"), 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 35 with UpdateRequest

use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.

the class PolicyResourceTest method shouldUpdatePoliciesInStore.

@Test
public void shouldUpdatePoliciesInStore() throws Exception {
    // Given
    String id = "testPolicy";
    long lastModified = 1234l;
    UpdateRequest request = mock(UpdateRequest.class);
    JsonValue content = new JsonValue("content");
    given(request.getContent()).willReturn(content);
    Privilege privilege = mockPrivilege(id, lastModified);
    given(mockParser.parsePolicy(id, content)).willReturn(privilege);
    given(mockStore.update(id, privilege)).willReturn(privilege);
    // When
    Promise<ResourceResponse, ResourceException> promise = policyResource.updateInstance(mockServerContext, id, request);
    // Then
    assertThat(promise).succeeded().withId().isNotNull();
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) UpdateRequest(org.forgerock.json.resource.UpdateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) Privilege(com.sun.identity.entitlement.Privilege) 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