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