Search in sources :

Example 76 with ResourceResponse

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

the class AuditFilterTest method shouldReturnNullForReadSuccess.

@Test
public void shouldReturnNullForReadSuccess() {
    ReadRequest readRequest = mock(ReadRequest.class);
    ResourceResponse resourceResponse = mock(ResourceResponse.class);
    JsonValue filterResponse = auditFilter.getReadSuccessDetail(readRequest, resourceResponse);
    assertThat(filterResponse).isEqualTo(null);
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) JsonValue(org.forgerock.json.JsonValue) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 77 with ResourceResponse

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

the class AuditFilterTest method shouldReturnNullForPatchSuccess.

@Test
public void shouldReturnNullForPatchSuccess() {
    PatchRequest patchRequest = mock(PatchRequest.class);
    ResourceResponse resourceResponse = mock(ResourceResponse.class);
    JsonValue filterResponse = auditFilter.getPatchSuccessDetail(patchRequest, resourceResponse);
    assertThat(filterResponse).isEqualTo(null);
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) JsonValue(org.forgerock.json.JsonValue) PatchRequest(org.forgerock.json.resource.PatchRequest) Test(org.testng.annotations.Test)

Example 78 with ResourceResponse

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

the class KbaResource method readInstance.

@Override
public Promise<ResourceResponse, ResourceException> readInstance(Context context, ReadRequest readRequest) {
    String realm = RealmContext.getRealm(context);
    JsonValue kbaJson = configHandler.getConfig(realm, KbaBuilder.class);
    ResourceResponse response = Responses.newResourceResponse("1", "1.0", kbaJson);
    return Promises.newResultPromise(response);
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) JsonValue(org.forgerock.json.JsonValue)

Example 79 with ResourceResponse

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

the class RequesterTest method shouldExecuteUpdateOperation.

@Test
public void shouldExecuteUpdateOperation() throws ResourceException {
    // *** GIVEN ***
    String location = "location";
    String resourceId = "resourceId";
    JsonValue payload = JsonValueBuilder.jsonValue().build();
    JsonValue expectedResult = JsonValueBuilder.toJsonValue("{ \"lemon\" : \"custard\" } ");
    // Set up mocks
    Promise<ResourceResponse, ResourceException> mockResponse = mock(Promise.class);
    ResourceResponse mockResourceResponse = mock(ResourceResponse.class);
    // Stub mocks
    given(mockRealmRouterProvider.get()).willReturn(mockRouter);
    given(mockRouter.handleUpdate(any(Context.class), any(UpdateRequest.class))).willReturn(mockResponse);
    given(mockResponse.getOrThrowUninterruptibly()).willReturn(mockResourceResponse);
    given(mockResourceResponse.getContent()).willReturn(expectedResult);
    // *** WHEN ***
    JsonValue actualResult = requester.update(location, resourceId, payload, mockServerContext);
    // *** THEN ***
    verify(mockRealmRouterProvider, times(1)).get();
    verifyNoMoreInteractions(mockRealmRouterProvider);
    verify(mockRouter, times(1)).handleUpdate(any(Context.class), any(UpdateRequest.class));
    verifyNoMoreInteractions(mockRouter);
    verify(mockResponse, times(1)).getOrThrowUninterruptibly();
    verifyNoMoreInteractions(mockResponse);
    verify(mockResourceResponse, times(1)).getContent();
    verifyNoMoreInteractions(mockResourceResponse);
    assertThat(actualResult).isEqualTo(expectedResult);
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) ResourceResponse(org.forgerock.json.resource.ResourceResponse) UpdateRequest(org.forgerock.json.resource.UpdateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 80 with ResourceResponse

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

the class RequesterTest method shouldExecuteCreateRequest.

@Test
public void shouldExecuteCreateRequest() throws ResourceException {
    // *** GIVEN ***
    String location = "location";
    String resourceId = "resourceId";
    JsonValue payload = JsonValueBuilder.jsonValue().build();
    JsonValue expectedResult = JsonValueBuilder.toJsonValue("{ \"lemon\" : \"custard\" } ");
    // Create mocks
    Promise<ResourceResponse, ResourceException> mockResponse = mock(Promise.class);
    ResourceResponse mockResourceResponse = mock(ResourceResponse.class);
    ;
    // Stub mocks
    given(mockRealmRouterProvider.get()).willReturn(mockRouter);
    given(mockRouter.handleCreate(any(Context.class), any(CreateRequest.class))).willReturn(mockResponse);
    given(mockResponse.getOrThrowUninterruptibly()).willReturn(mockResourceResponse);
    given(mockResourceResponse.getContent()).willReturn(expectedResult);
    // *** WHEN ***
    JsonValue actualResult = requester.create(location, resourceId, payload, mockServerContext);
    // *** THEN ***
    verify(mockRealmRouterProvider, times(1)).get();
    verifyNoMoreInteractions(mockRealmRouterProvider);
    verify(mockRouter, times(1)).handleCreate(any(Context.class), any(CreateRequest.class));
    verifyNoMoreInteractions(mockRouter);
    verify(mockResponse, times(1)).getOrThrowUninterruptibly();
    verifyNoMoreInteractions(mockResponse);
    verify(mockResourceResponse, times(1)).getContent();
    verifyNoMoreInteractions(mockResourceResponse);
    assertThat(actualResult).isEqualTo(expectedResult);
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) ResourceResponse(org.forgerock.json.resource.ResourceResponse) CreateRequest(org.forgerock.json.resource.CreateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

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