use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class ResourceSetResourceTest method createShouldNotBeSupported.
@Test
public void createShouldNotBeSupported() {
//Given
Context context = mock(Context.class);
CreateRequest request = mock(CreateRequest.class);
//When
Promise<ResourceResponse, ResourceException> instancePromise = resource.createInstance(context, request);
//Then
assertThat(instancePromise).failedWithException().isInstanceOf(NotSupportedException.class);
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class ResourceSetResourceTest method shouldRevokeAllUserPolicies.
@Test
public void shouldRevokeAllUserPolicies() throws ResourceException {
//Given
Context context = mock(Context.class);
ActionRequest request = mock(ActionRequest.class);
given(contextHelper.getRealm(context)).willReturn("REALM");
given(contextHelper.getUserId(context)).willReturn("RESOURCE_OWNER_ID");
given(request.getAction()).willReturn("revokeAll");
given(resourceSetService.revokeAllPolicies(context, "REALM", "RESOURCE_OWNER_ID")).willReturn(Promises.<Void, ResourceException>newResultPromise(null));
//When
Promise<ActionResponse, ResourceException> promise = resource.actionCollection(context, request);
//Then
assertThat(promise).succeeded().withObject().isNotNull();
JsonValue jsonContent = promise.getOrThrowUninterruptibly().getJsonContent();
assertThat(jsonContent.asMap()).isEmpty();
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class ResourceSetResourceTest method shouldReadResourceSet.
@Test
public void shouldReadResourceSet() throws Exception {
//Given
Context context = mock(Context.class);
ReadRequest request = mock(ReadRequest.class);
given(request.getFields()).willReturn(Arrays.asList(new JsonPointer("/fred")));
ResourceSetDescription resourceSet = new ResourceSetDescription();
resourceSet.setDescription(json(object()));
Promise<ResourceSetDescription, ResourceException> resourceSetPromise = Promises.newResultPromise(resourceSet);
given(contextHelper.getRealm(context)).willReturn("REALM");
given(contextHelper.getUserId(context)).willReturn("RESOURCE_OWNER_ID");
given(resourceSetService.getResourceSet(context, "REALM", "RESOURCE_SET_ID", "RESOURCE_OWNER_ID", false)).willReturn(resourceSetPromise);
//When
Promise<ResourceResponse, ResourceException> readPromise = resource.readInstance(context, "RESOURCE_SET_ID", request);
//Then
assertThat(readPromise).succeeded().withObject().isNotNull();
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class ResourceSetResourceTest method queryShouldNotBeSupported.
@Test
public void queryShouldNotBeSupported() {
//Given
Context context = mock(Context.class);
QueryRequest request = mock(QueryRequest.class);
QueryResourceHandler handler = mock(QueryResourceHandler.class);
given(request.getQueryFilter()).willReturn(QueryFilter.equalTo(new JsonPointer("/fred"), 5));
//When
Promise<QueryResponse, ResourceException> promise = resource.queryCollection(context, request, handler);
//Then
assertThat(promise).failedWithException().isInstanceOf(NotSupportedException.class);
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class PolicyGraphTest method shouldCreatePolicyWhenMakingValid.
/*
Alice had removed Dave's ability to VIEW, EDIT and DELETE, so Dave's resharing
policies to Ed had been made inactive. Alice has re-granted Dave's VIEW and DELETE,
so those need to be active, while EDIT stays inactive.
*/
@Test
public void shouldCreatePolicyWhenMakingValid() throws Exception {
// Given
List<ResourceResponse> policies = excludePolicies(DAVE, ED);
policies.add(makePolicy(DAVE, ED, false, VIEW, DELETE, EDIT));
PolicyGraph graph = makePolicyGraph(policies);
graph.computeGraph();
given(resourceSetStore.read(anyString(), anyString())).willReturn(new ResourceSetDescription(RESOURCE_SET_ID, "RESOURCE_SERVER_ID", ALICE, null));
given(delegate.updatePolicies(isNull(Context.class), anySet())).willReturn(Promises.<List<ResourceResponse>, ResourceException>newResultPromise(Collections.<ResourceResponse>emptyList()));
given(delegate.createPolicies(isNull(Context.class), anySet())).willReturn(Promises.<List<ResourceResponse>, ResourceException>newResultPromise(Collections.<ResourceResponse>emptyList()));
// When
Promise<List<List<ResourceResponse>>, ResourceException> promise = graph.update(null, delegate);
// Then
AssertJPromiseAssert.assertThat(promise).succeeded();
JsonValue created = policyCreated();
assertThat(UmaPolicyUtils.getPolicyScopes(created)).containsOnly(VIEW, DELETE);
assertThat(created.get("active").asBoolean()).isTrue();
assertThat(UmaPolicyUtils.getPolicyScopes(policyUpdated())).containsOnly(EDIT);
verifyNoMoreInteractions(delegate);
}
Aggregations