Search in sources :

Example 61 with ResourceResponse

use of org.forgerock.json.resource.ResourceResponse 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);
}
Also used : Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) CreateRequest(org.forgerock.json.resource.CreateRequest) ResourceException(org.forgerock.json.resource.ResourceException) Test(org.testng.annotations.Test)

Example 62 with ResourceResponse

use of org.forgerock.json.resource.ResourceResponse 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();
}
Also used : Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) JsonPointer(org.forgerock.json.JsonPointer) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 63 with ResourceResponse

use of org.forgerock.json.resource.ResourceResponse 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);
}
Also used : Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) PolicyGraph(org.forgerock.openam.uma.rest.PolicyGraph) JsonValue(org.forgerock.json.JsonValue) ArrayList(java.util.ArrayList) List(java.util.List) ResourceException(org.forgerock.json.resource.ResourceException) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) Test(org.testng.annotations.Test)

Example 64 with ResourceResponse

use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.

the class PolicyGraphTest method shouldDetectInvalidRightsTree.

/*
      VIEW scope is accessible to Dave, so his VIEW reshare to Ed should be active, not inactive.
     */
@Test
public void shouldDetectInvalidRightsTree() throws Exception {
    // Given
    List<ResourceResponse> policies = excludePolicies(DAVE, ED);
    policies.add(makePolicy(DAVE, ED, true, DELETE));
    policies.add(makePolicy(DAVE, ED, false, VIEW));
    PolicyGraph graph = makePolicyGraph(policies);
    // When
    graph.computeGraph();
    // Then
    assertThat(graph.isValid()).isFalse();
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) PolicyGraph(org.forgerock.openam.uma.rest.PolicyGraph) Test(org.testng.annotations.Test)

Example 65 with ResourceResponse

use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.

the class PolicyGraphTest method shouldDetectValidRights.

@Test
public void shouldDetectValidRights() throws Exception {
    // Given
    List<ResourceResponse> policies = VALID_POLICIES;
    PolicyGraph graph = makePolicyGraph(policies);
    // When
    graph.computeGraph();
    // Then
    assertThat(graph.isValid()).isTrue();
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) PolicyGraph(org.forgerock.openam.uma.rest.PolicyGraph) Test(org.testng.annotations.Test)

Aggregations

ResourceResponse (org.forgerock.json.resource.ResourceResponse)227 ResourceException (org.forgerock.json.resource.ResourceException)171 Test (org.testng.annotations.Test)154 JsonValue (org.forgerock.json.JsonValue)123 Context (org.forgerock.services.context.Context)83 RealmContext (org.forgerock.openam.rest.RealmContext)72 Subject (javax.security.auth.Subject)57 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)48 Responses.newResourceResponse (org.forgerock.json.resource.Responses.newResourceResponse)44 CreateRequest (org.forgerock.json.resource.CreateRequest)41 ClientContext (org.forgerock.services.context.ClientContext)41 ArrayList (java.util.ArrayList)38 EntitlementException (com.sun.identity.entitlement.EntitlementException)30 ReadRequest (org.forgerock.json.resource.ReadRequest)30 NotFoundException (org.forgerock.json.resource.NotFoundException)29 UpdateRequest (org.forgerock.json.resource.UpdateRequest)29 Matchers.anyString (org.mockito.Matchers.anyString)28 HashSet (java.util.HashSet)27 BadRequestException (org.forgerock.json.resource.BadRequestException)26 DeleteRequest (org.forgerock.json.resource.DeleteRequest)26