use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.
the class RestRouterIT method shouldBeAbleToReachInternalViaInternalRouter.
@Test
public void shouldBeAbleToReachInternalViaInternalRouter() throws Exception {
// Given
Promise<ResourceResponse, ResourceException> promise = newResultPromise(newResourceResponse("1", "1", json(object())));
given(internalResource.readInstance(any(Context.class), eq("123"), any(ReadRequest.class))).willReturn(promise);
Router internalRouter = InjectorHolder.getInstance(Key.get(Router.class, Names.named("InternalCrestRouter")));
Context context = mockRequiredContexts();
ReadRequest request = Requests.newReadRequest("internal/123");
// When
internalRouter.handleRead(context, request);
// Then
verify(internalResource).readInstance(any(Context.class), eq("123"), any(ReadRequest.class));
}
use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.
the class ElevatedConnectionFactoryWrapperTest method requestGetsElevatedToAdminSession.
@Test
public void requestGetsElevatedToAdminSession() throws Exception {
// Given
SSOToken ssoToken = mock(SSOToken.class);
given(ssoTokenPrivilegedAction.run()).willReturn(ssoToken);
SSOPrincipal principal = new SSOPrincipal("test");
given(ssoToken.getPrincipal()).willReturn(principal);
SSOTokenID tokenID = mock(SSOTokenID.class);
given(ssoToken.getTokenID()).willReturn(tokenID);
given(internalConnectionFactory.getConnection()).willReturn(connection);
// When
RootContext context = new RootContext();
ReadRequest readRequest = Requests.newReadRequest("/test", "abc");
try (Connection connection = connectionFactory.getConnection()) {
connection.read(context, readRequest);
}
// Then
verify(connection).read(contextCaptor.capture(), eq(readRequest));
Context capturedContext = contextCaptor.getValue();
assertThat(capturedContext.containsContext(SecurityContext.class)).isTrue();
SecurityContext securityContext = capturedContext.asContext(SecurityContext.class);
assertThat(securityContext.getAuthenticationId()).isEqualTo("test");
assertThat(securityContext.getAuthorization()).containsOnlyKeys("authLevel", "tokenId");
}
use of org.forgerock.json.resource.ReadRequest 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);
}
use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.
the class SelfServiceRequestHandlerTest method initialReadCallsIntoUnderlyingService.
@Test
public void initialReadCallsIntoUnderlyingService() throws ResourceException {
// When
ReadRequest request = Requests.newReadRequest("/someEndpoint");
given(consoleConfigHandler.getConfig("/", MockBuilder.class)).willReturn(consoleConfig);
given(providerFactory.getProvider(consoleConfig)).willReturn(configProvider);
given(configProvider.isServiceEnabled(consoleConfig)).willReturn(true);
ProcessInstanceConfig config = new ProcessInstanceConfig();
given(configProvider.getServiceConfig(consoleConfig, context, "/")).willReturn(config);
given(serviceFactory.getService("/", config)).willReturn(underlyingService);
// Given
selfServiceHandler.handleRead(context, request);
// Then
verify(underlyingService).handleRead(context, request);
}
use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.
the class ApplicationTypesResourceTest method shouldReadInstanceCorrectly.
@Test
public void shouldReadInstanceCorrectly() throws IllegalAccessException, InstantiationException, ExecutionException, InterruptedException {
//given
SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject subject = new Subject();
given(mockSubjectContext.getCallerSubject()).willReturn(subject);
ReadRequest request = mock(ReadRequest.class);
ApplicationType mockApplicationType = new ApplicationType("test", null, null, null, null);
given(mockApplicationTypeManager.getApplicationType(subject, "test")).willReturn(mockApplicationType);
//when
Promise<ResourceResponse, ResourceException> result = testResource.readInstance(mockServerContext, "test", request);
//then
assertTrue(result.get().getId().equals("test"));
}
Aggregations