Search in sources :

Example 36 with UpdateRequest

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

the class UmaPolicyResourceTest method shouldSuccessfullyUpdatePolicy.

@Test
@SuppressWarnings("unchecked")
public void shouldSuccessfullyUpdatePolicy() {
    //Given
    Context context = mock(Context.class);
    UpdateRequest request = Requests.newUpdateRequest("/policies", json(object()));
    UmaPolicy policy = mock(UmaPolicy.class);
    JsonValue policyJson = json(object());
    Promise<UmaPolicy, ResourceException> promise = Promises.newResultPromise(policy);
    given(policy.getId()).willReturn("ID");
    given(policy.getRevision()).willReturn("REVISION");
    given(policy.asJson()).willReturn(policyJson);
    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).succeeded().withId().isEqualTo("ID");
    assertThat(result).succeeded().withRevision().isEqualTo("REVISION");
    assertThat(result).succeeded().withContent().isObject().isEqualTo(policyJson);
}
Also used : Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) UpdateRequest(org.forgerock.json.resource.UpdateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) UmaPolicy(org.forgerock.openam.uma.UmaPolicy) 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