use of org.forgerock.json.resource.ResourceResponse 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.ResourceResponse in project OpenAM by OpenRock.
the class PendingRequestResourceTest method shouldReadPendingRequest.
@SuppressWarnings("unchecked")
@Test
public void shouldReadPendingRequest() throws Exception {
//Given
Context context = mock(Context.class);
ReadRequest request = Requests.newReadRequest("");
String id = mockPendingRequest();
//When
Promise<ResourceResponse, ResourceException> promise = resource.readInstance(context, id, request);
//Then
assertThat(promise).succeeded();
}
use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.
the class ResourceSetResourceTest method deleteShouldNotBeSupported.
@Test
public void deleteShouldNotBeSupported() {
//Given
Context context = mock(Context.class);
DeleteRequest request = mock(DeleteRequest.class);
//When
Promise<ResourceResponse, ResourceException> promise = resource.deleteInstance(context, "RESOURCE_SET_UID", request);
//Then
assertThat(promise).failedWithException().isInstanceOf(NotSupportedException.class);
}
use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.
the class UmaPolicyTest method shouldCreateUmaPolicyFromUnderlyingPolicies.
@Test
public void shouldCreateUmaPolicyFromUnderlyingPolicies() throws BadRequestException {
//Given
Set<ResourceResponse> policies = createUnderlyingPolicies("RESOURCE_OWNER_ID");
//When
UmaPolicy umaPolicy = UmaPolicy.fromUnderlyingPolicies(resourceSet, policies);
//Then
assertThat(umaPolicy.getId()).isEqualTo("RESOURCE_SET_ID");
assertThat(umaPolicy.getRevision()).isNotNull();
assertThat(umaPolicy.asJson().asMap()).hasSize(3).contains(entry("policyId", "RESOURCE_SET_ID"), entry("name", "NAME"));
JsonValue permissions = umaPolicy.asJson().get("permissions");
assertThat(permissions.asList()).hasSize(2);
assertThat(permissions.get(0).asMap()).contains(entry("subject", "SUBJECT_ONE"));
assertThat(permissions.get(0).get("scopes").asList()).containsOnly("SCOPE_A", "SCOPE_B");
assertThat(permissions.get(1).asMap()).contains(entry("subject", "SUBJECT_TWO"));
assertThat(permissions.get(1).get("scopes").asList()).containsOnly("SCOPE_A");
}
use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.
the class UmaEnabledFilterTest method testFilterPatch.
@Test(dataProvider = "factories")
public void testFilterPatch(UmaProviderSettingsFactory factory, boolean expectFailure) throws Exception {
// Given
UmaEnabledFilter filter = new UmaEnabledFilter(factory);
PatchRequest request = Requests.newPatchRequest("test", "test");
// When
Promise<ResourceResponse, ResourceException> promise = filter.filterPatch(context, request, requestHandler);
// Then
checkResult(expectFailure, promise);
if (expectFailure) {
verifyNoMoreInteractions(requestHandler);
} else {
verify(requestHandler).handlePatch(context, request);
}
}
Aggregations