Search in sources :

Example 56 with Context

use of org.forgerock.services.context.Context 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 57 with Context

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

Example 58 with Context

use of org.forgerock.services.context.Context 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 59 with Context

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

Example 60 with Context

use of org.forgerock.services.context.Context 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);
}
Also used : Context(org.forgerock.services.context.Context) Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) UpdateRequest(org.forgerock.json.resource.UpdateRequest) JsonValue(org.forgerock.json.JsonValue) ArrayList(java.util.ArrayList) ResourceException(org.forgerock.json.resource.ResourceException) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

Context (org.forgerock.services.context.Context)250 Test (org.testng.annotations.Test)231 RealmContext (org.forgerock.openam.rest.RealmContext)150 ResourceException (org.forgerock.json.resource.ResourceException)132 ClientContext (org.forgerock.services.context.ClientContext)120 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)101 ResourceResponse (org.forgerock.json.resource.ResourceResponse)82 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)76 RootContext (org.forgerock.services.context.RootContext)62 JsonValue (org.forgerock.json.JsonValue)56 QueryRequest (org.forgerock.json.resource.QueryRequest)54 ReadRequest (org.forgerock.json.resource.ReadRequest)50 AttributesContext (org.forgerock.services.context.AttributesContext)44 ActionRequest (org.forgerock.json.resource.ActionRequest)43 QueryResponse (org.forgerock.json.resource.QueryResponse)43 Subject (javax.security.auth.Subject)42 Matchers.anyString (org.mockito.Matchers.anyString)38 Request (org.forgerock.http.protocol.Request)37 UpdateRequest (org.forgerock.json.resource.UpdateRequest)36 DeleteRequest (org.forgerock.json.resource.DeleteRequest)35