Search in sources :

Example 96 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class RequesterTest method emptyLocationBreaksQuery.

//
// test query()
//
@Test(expectedExceptions = IllegalArgumentException.class)
public void emptyLocationBreaksQuery() throws ResourceException {
    // given
    String location = "";
    String queryId = "queryId";
    Context fakeContext = mock(Context.class);
    // when
    requester.query(location, queryId, fakeContext);
// then -- matched by expectedExceptions
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 97 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class RequesterTest method nullLocationBreaksDelete.

@Test(expectedExceptions = IllegalArgumentException.class)
public void nullLocationBreaksDelete() throws ResourceException {
    // given
    String location = null;
    String resourceId = "resourceId";
    Context fakeContext = mock(Context.class);
    // when
    requester.delete(location, resourceId, fakeContext);
// then -- matched by expectedExceptions
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 98 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class ScriptExceptionMappingHandlerTest method shouldTranslateMessageToAcceptLanguage.

@Test
public void shouldTranslateMessageToAcceptLanguage() throws Exception {
    // given
    final Context serverContext = getHttpServerContext("te");
    for (ScriptErrorCode errorCode : ScriptErrorCode.values()) {
        // when
        ResourceException re = mappingHandler.handleError(serverContext, null, new ScriptException(errorCode));
        // then
        assertNotNull(re);
    //            assertEquals("Test message", re.getMessage()); //TODO dont get this...
    }
}
Also used : Context(org.forgerock.services.context.Context) HttpContext(org.forgerock.json.resource.http.HttpContext) ClientContext(org.forgerock.services.context.ClientContext) ScriptException(org.forgerock.openam.scripting.ScriptException) ScriptErrorCode(org.forgerock.openam.scripting.ScriptConstants.ScriptErrorCode) ResourceException(org.forgerock.json.resource.ResourceException) Test(org.testng.annotations.Test)

Example 99 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class BatchResourceTest method shouldRejectNonBatchActions.

@Test
public void shouldRejectNonBatchActions() {
    //given
    Context mockContext = Mockito.mock(Context.class);
    ActionRequest mockRequest = mock(ActionRequest.class);
    given(mockRequest.getAction()).willReturn("false");
    @SuppressWarnings("unchecked") ExceptionHandler<ResourceException> handler = mock(ExceptionHandler.class);
    //when
    Promise<ActionResponse, ResourceException> result = batchResource.actionCollection(mockContext, mockRequest);
    result.thenOnException(handler);
    //then
    verify(handler, times(1)).handleException(any(ResourceException.class));
    verifyNoMoreInteractions(handler);
}
Also used : Context(org.forgerock.services.context.Context) Requests.newActionRequest(org.forgerock.json.resource.Requests.newActionRequest) ActionRequest(org.forgerock.json.resource.ActionRequest) ResourceException(org.forgerock.json.resource.ResourceException) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 100 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class UmaPolicyResourceTest method shouldSuccessfullyCreatePolicy.

@Test
@SuppressWarnings("unchecked")
public void shouldSuccessfullyCreatePolicy() {
    //Given
    Context context = mock(Context.class);
    CreateRequest request = Requests.newCreateRequest("/policies", json(object()));
    UmaPolicy policy = mock(UmaPolicy.class);
    Promise<UmaPolicy, ResourceException> promise = Promises.newResultPromise(policy);
    given(policy.getId()).willReturn("ID");
    given(policy.getRevision()).willReturn("REVISION");
    given(policyService.createPolicy(context, request.getContent())).willReturn(promise);
    //When
    Promise<ResourceResponse, ResourceException> result = policyResource.createInstance(context, request);
    //Then
    assertThat(result).succeeded().withId().isEqualTo("ID");
    assertThat(result).succeeded().withRevision().isEqualTo("REVISION");
    assertThat(result).succeeded().withContent().isEmpty();
}
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) UmaPolicy(org.forgerock.openam.uma.UmaPolicy) 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