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();
}
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();
}
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();
}
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();
}
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);
}
Aggregations