use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.
the class ApplicationsResourceTest method updateInstanceShouldReturnConflictWhenUpdatingFailsDueToNeedToDeletePolicies.
@Test(expectedExceptions = ConflictException.class)
public void updateInstanceShouldReturnConflictWhenUpdatingFailsDueToNeedToDeletePolicies() 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(404)).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();
}
use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldNotUpdateInstanceIfApplicationNotFound.
@Test(expectedExceptions = NotFoundException.class)
public void shouldNotUpdateInstanceIfApplicationNotFound() 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 = "RESOURCE_ID";
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(applicationManagerWrapper.getApplication(subject, "REALM", resourceId)).willReturn(null);
given(applicationWrapper.getApplication()).willReturn(mockApplication);
//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 updateFailsWhenApplicationMissing.
/**
* Verifies that update fails when the selected application cannot be found.
*/
@Test(expectedExceptions = NotFoundException.class)
public void updateFailsWhenApplicationMissing() 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);
given(applicationService.getApplication("testApplication")).willReturn(null);
// 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 PolicyResourceDelegateTest method shouldUpdatePolicies.
@Test
public void shouldUpdatePolicies() throws ResourceException {
//Given
Context context = mock(Context.class);
Set<JsonValue> policies = new HashSet<JsonValue>();
JsonValue policyOne = json(object(field("name", "POLICY_ONE")));
JsonValue policyTwo = json(object(field("name", "POLICY_TWO")));
policies.add(policyOne);
policies.add(policyTwo);
List<ResourceResponse> updatedPolicies = new ArrayList<ResourceResponse>();
ResourceResponse updatedPolicyOne = newResourceResponse("ID_1", "REVISION_1", json(object()));
ResourceResponse updatedPolicyTwo = newResourceResponse("ID_1", "REVISION_1", json(object()));
updatedPolicies.add(updatedPolicyOne);
updatedPolicies.add(updatedPolicyTwo);
Promise<ResourceResponse, ResourceException> updatePolicyOnePromise = Promises.newResultPromise(updatedPolicyOne);
Promise<ResourceResponse, ResourceException> updatePolicyTwoPromise = Promises.newResultPromise(updatedPolicyTwo);
given(policyResource.handleUpdate(eq(context), Matchers.<UpdateRequest>anyObject())).willReturn(updatePolicyOnePromise).willReturn(updatePolicyTwoPromise);
//When
List<ResourceResponse> returnedPolicies = delegate.updatePolicies(context, policies).getOrThrowUninterruptibly();
//Then
assertThat(returnedPolicies).isEqualTo(updatedPolicies);
}
use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.
the class AuditFilterTest method shouldReturnNullForUpdateSuccess.
@Test
public void shouldReturnNullForUpdateSuccess() {
UpdateRequest updateRequest = mock(UpdateRequest.class);
ResourceResponse resourceResponse = mock(ResourceResponse.class);
JsonValue filterResponse = auditFilter.getUpdateSuccessDetail(updateRequest, resourceResponse);
assertThat(filterResponse).isEqualTo(null);
}
Aggregations