Search in sources :

Example 16 with UpdateRequest

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

the class CoreTokenResourceTest method shouldUpdateUsingTokenInUpdateRequest.

@Test
public void shouldUpdateUsingTokenInUpdateRequest() throws CoreTokenException {
    // Given
    UpdateRequest updateRequest = mock(UpdateRequest.class);
    JsonValue value = mock(JsonValue.class);
    given(value.toString()).willReturn("{ \"value\": \"test\" }");
    given(updateRequest.getContent()).willReturn(value);
    given(mockSerialisation.deserialise(anyString(), Matchers.<Class<Object>>any())).willReturn(mockToken);
    // When
    resource.updateInstance(null, "badger", updateRequest);
    // Then
    verify(mockStore).updateAsync(any(Token.class));
}
Also used : UpdateRequest(org.forgerock.json.resource.UpdateRequest) JsonValue(org.forgerock.json.JsonValue) Token(org.forgerock.openam.cts.api.tokens.Token) Test(org.testng.annotations.Test)

Example 17 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)

Example 18 with UpdateRequest

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

the class ApplicationsResourceTest method updateInstanceShouldReturnForbiddenWhenUpdatingFailsDueToNotAuthorized.

@Test(expectedExceptions = ForbiddenException.class)
public void updateInstanceShouldReturnForbiddenWhenUpdatingFailsDueToNotAuthorized() throws EntitlementException, ResourceException {
    //Given
    SSOTokenContext subjectContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(subjectContext);
    realmContext.setSubRealm("REALM", "REALM");
    Context context = ClientContext.newInternalClientContext(realmContext);
    String resourceId = "iPlanetAMWebAgentService";
    UpdateRequest request = mock(UpdateRequest.class);
    Subject subject = new Subject();
    JsonValue content = mock(JsonValue.class);
    Application mockApplication = mock(Application.class);
    given(subjectContext.getCallerSubject()).willReturn(subject);
    given(request.getContent()).willReturn(content);
    given(applicationWrapper.getApplication()).willReturn(mockApplication);
    given(applicationManagerWrapper.getApplication(subject, "/REALM", resourceId)).willReturn(mockApplication);
    doThrow(new EntitlementException(326)).when(applicationManagerWrapper).updateApplication(any(Application.class), any(Application.class), any(Subject.class), anyString());
    //When
    Promise<ResourceResponse, ResourceException> result = applicationsResource.updateInstance(context, resourceId, request);
    //Then
    result.getOrThrowUninterruptibly();
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) Context(org.forgerock.services.context.Context) EntitlementException(com.sun.identity.entitlement.EntitlementException) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) RealmContext(org.forgerock.openam.rest.RealmContext) ResourceResponse(org.forgerock.json.resource.ResourceResponse) UpdateRequest(org.forgerock.json.resource.UpdateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) Matchers.anyString(org.mockito.Matchers.anyString) Application(com.sun.identity.entitlement.Application) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 19 with UpdateRequest

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

the class ApplicationsResourceTest method shouldUpdateInstance.

@Test
public void shouldUpdateInstance() throws EntitlementException, ResourceException {
    //Given
    SSOTokenContext subjectContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(subjectContext);
    realmContext.setSubRealm("REALM", "REALM");
    Context context = ClientContext.newInternalClientContext(realmContext);
    String resourceId = "iPlanetAMWebAgentService";
    UpdateRequest request = mock(UpdateRequest.class);
    Subject subject = new Subject();
    JsonValue content = mock(JsonValue.class);
    Application application = mock(Application.class);
    Application newApplication = mock(Application.class);
    JsonValue response = mock(JsonValue.class);
    given(subjectContext.getCallerSubject()).willReturn(subject);
    given(request.getContent()).willReturn(content);
    given(applicationManagerWrapper.getApplication(subject, "/REALM", resourceId)).willReturn(application);
    given(applicationWrapper.getName()).willReturn("APP_NAME");
    given(applicationWrapper.getApplication()).willReturn(newApplication);
    given(newApplication.getLastModifiedDate()).willReturn(1000L);
    given(applicationWrapper.toJsonValue()).willReturn(response);
    //When
    Promise<ResourceResponse, ResourceException> result = applicationsResource.updateInstance(context, resourceId, request);
    //Then
    verify(applicationManagerWrapper).updateApplication(application, applicationWrapper.getApplication(), subject, "/REALM");
    ResourceResponse resource = result.getOrThrowUninterruptibly();
    assertEquals(resource.getId(), "APP_NAME");
    assertEquals(resource.getRevision(), "1000");
    assertEquals(resource.getContent(), response);
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) Context(org.forgerock.services.context.Context) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) RealmContext(org.forgerock.openam.rest.RealmContext) ResourceResponse(org.forgerock.json.resource.ResourceResponse) UpdateRequest(org.forgerock.json.resource.UpdateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) Matchers.anyString(org.mockito.Matchers.anyString) Application(com.sun.identity.entitlement.Application) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 20 with UpdateRequest

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

the class ApplicationV1FilterTest method updateModifiesUnderlyingResourceType.

/**
     * Verifies that the underlying associated resource type is updated to reflect changes in a v1.0 application.
     */
@Test
public void updateModifiesUnderlyingResourceType() throws Exception {
    // Given
    given(contextHelper.getRealm(context)).willReturn("/abc");
    given(contextHelper.getSubject(context)).willReturn(subject);
    // Build application JSON representation.
    JsonValue jsonValue = json(object(TestData.DATA_SET_1.getResources().asJson(), TestData.DATA_SET_1.getActions().asJson(), field("realm", "/abc")));
    UpdateRequest updateRequest = mock(UpdateRequest.class);
    given(updateRequest.getContent()).willReturn(jsonValue);
    given(updateRequest.getResourcePath()).willReturn("testApplication");
    given(applicationServiceFactory.create(subject, "/abc")).willReturn(applicationService);
    Application application = mock(Application.class);
    given(applicationService.getApplication("testApplication")).willReturn(application);
    Set<String> resourceTypeUUIDs = new HashSet<>(CollectionUtils.asSet("abc-def-ghi"));
    given(application.getResourceTypeUuids()).willReturn(resourceTypeUUIDs);
    ResourceType resourceType = ResourceType.builder().setName("test").setUUID("abc-def-ghi").setActions(TestData.DATA_SET_2.getActions().getUnderlyingMap()).setPatterns(TestData.DATA_SET_2.getResources().getUnderlyingSet()).build();
    given(resourceTypeService.getResourceType(subject, "/abc", "abc-def-ghi")).willReturn(resourceType);
    // When
    filter.filterUpdate(context, updateRequest, requestHandler);
    // Then
    assertThat(jsonValue.get("resourceTypeUuids").asSet(String.class)).containsOnly("abc-def-ghi");
    verify(resourceTypeService).updateResourceType(eq(subject), eq("/abc"), resourceTypeCaptor.capture());
    verify(requestHandler).handleUpdate(eq(context), eq(updateRequest));
    ResourceType capturedResourceType = resourceTypeCaptor.getValue();
    assertThat(capturedResourceType.getUUID()).isEqualTo("abc-def-ghi");
    assertThat(capturedResourceType.getActions()).isEqualTo(TestData.DATA_SET_1.getActions().getUnderlyingMap());
    assertThat(capturedResourceType.getPatterns()).isEqualTo(TestData.DATA_SET_1.getResources().getUnderlyingSet());
}
Also used : UpdateRequest(org.forgerock.json.resource.UpdateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceType(org.forgerock.openam.entitlement.ResourceType) Application(com.sun.identity.entitlement.Application) HashSet(java.util.HashSet) 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