Search in sources :

Example 21 with UpdateRequest

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

the class ApplicationV1FilterTest method updateFailsWhenNoResourcesDefined.

/**
     * Verifies that update fails when no resources are defined.
     */
@Test(expectedExceptions = BadRequestException.class)
public void updateFailsWhenNoResourcesDefined() throws ResourceException {
    // Given
    // Build application JSON representation.
    JsonValue jsonValue = json(object(TestData.DATA_SET_1.getActions().asJson()));
    UpdateRequest updateRequest = mock(UpdateRequest.class);
    given(updateRequest.getContent()).willReturn(jsonValue);
    // When
    Promise<ResourceResponse, ResourceException> result = filter.filterUpdate(context, updateRequest, requestHandler);
    // Then
    result.getOrThrowUninterruptibly();
}
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) Test(org.testng.annotations.Test)

Example 22 with UpdateRequest

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

the class ApplicationV1FilterTest method updateFailsWithManyResourceTypes.

/**
     * Verifies that update fails when the mentioned application has more than one resource type.
     */
@Test(expectedExceptions = BadRequestException.class)
public void updateFailsWithManyResourceTypes() 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(applicationServiceFactory.create(subject, "/abc")).willReturn(applicationService);
    Application application = mock(Application.class);
    given(updateRequest.getResourcePath()).willReturn("testApplication");
    given(applicationService.getApplication("testApplication")).willReturn(application);
    Set<String> resourceTypeUUIDs = new HashSet<>(CollectionUtils.asSet("abc-def-ghi", "jkl-mno-qrs"));
    given(application.getResourceTypeUuids()).willReturn(resourceTypeUUIDs);
    // When
    Promise<ResourceResponse, ResourceException> result = filter.filterUpdate(context, updateRequest, requestHandler);
    // Then
    result.getOrThrowUninterruptibly();
}
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) Application(com.sun.identity.entitlement.Application) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 23 with UpdateRequest

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

the class ApplicationsResourceTest method updateInstanceShouldReturnConflictExceptionWhenApplicationNameAlreadyExists.

@Test(expectedExceptions = ConflictException.class)
public void updateInstanceShouldReturnConflictExceptionWhenApplicationNameAlreadyExists() 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);
    given(subjectContext.getCallerSubject()).willReturn(subject);
    given(request.getContent()).willReturn(content);
    given(applicationManagerWrapper.getApplication(subject, "/REALM", resourceId)).willReturn(application);
    given(applicationManagerWrapper.getApplication(subject, "/REALM", "APP_NAME")).willReturn(application);
    given(applicationWrapper.getName()).willReturn("APP_NAME");
    given(applicationWrapper.getApplication()).willReturn(newApplication);
    given(newApplication.getLastModifiedDate()).willReturn(1000L);
    doThrow(EntitlementException.class).when(applicationWrapper).toJsonValue();
    //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) 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 24 with UpdateRequest

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

the class ApplicationV1FilterTest method updateFailsWhenNoActionsDefined.

/**
     * Verifies that update fails when no actions are defined.
     */
@Test(expectedExceptions = BadRequestException.class)
public void updateFailsWhenNoActionsDefined() throws ResourceException {
    // Given
    // Build application JSON representation.
    JsonValue jsonValue = json(object(TestData.DATA_SET_1.getResources().asJson()));
    UpdateRequest updateRequest = mock(UpdateRequest.class);
    given(updateRequest.getContent()).willReturn(jsonValue);
    // When
    Promise<ResourceResponse, ResourceException> result = filter.filterUpdate(context, updateRequest, requestHandler);
    // Then
    result.getOrThrowUninterruptibly();
}
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) Test(org.testng.annotations.Test)

Example 25 with UpdateRequest

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

the class ResourceTypesResourceTest method updateShouldHandleServiceException.

@Test
public void updateShouldHandleServiceException() throws Exception {
    //given
    ResourceResponse createdResource = setupExistingResourceTypeFromJson(jsonResourceType);
    UpdateRequest updateRequest = mock(UpdateRequest.class);
    given(updateRequest.getContent()).willReturn(createdResource.getContent());
    Throwable t = new EntitlementException(EntitlementException.RESOURCE_TYPE_ALREADY_EXISTS);
    doThrow(t).when(resourceTypeService).updateResourceType(any(Subject.class), anyString(), any(ResourceType.class));
    //when
    Promise<ResourceResponse, ResourceException> promise = resourceTypesResource.updateInstance(mockServerContext, createdResource.getId(), updateRequest);
    //then
    assertResourcePromiseFailedWithCodes(promise, ResourceException.CONFLICT, EntitlementException.RESOURCE_TYPE_ALREADY_EXISTS);
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) ResourceResponse(org.forgerock.json.resource.ResourceResponse) UpdateRequest(org.forgerock.json.resource.UpdateRequest) ResourceType(org.forgerock.openam.entitlement.ResourceType) ResourceException(org.forgerock.json.resource.ResourceException) Subject(javax.security.auth.Subject) 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