use of org.forgerock.services.context.RootContext in project OpenAM by OpenRock.
the class HandlerProviderTest method shouldNotCallInjectorHolderTwice.
@Test
public void shouldNotCallInjectorHolderTwice() {
//Given
Context context = new RootContext();
Request request = new Request();
//When
handlerProvider.handle(context, request);
handlerProvider.handle(context, request);
//Then
assertThat(handlerReturnCount.get()).isEqualTo(1);
verify(handler, times(2)).handle(context, request);
}
use of org.forgerock.services.context.RootContext in project OpenAM by OpenRock.
the class HandlerProviderTest method shouldCallInjectorHolderOnFirstCallToHandler.
@Test
public void shouldCallInjectorHolderOnFirstCallToHandler() {
//Given
Context context = new RootContext();
Request request = new Request();
//When
handlerProvider.handle(context, request);
//Then
assertThat(handlerReturnCount.get()).isEqualTo(1);
verify(handler).handle(context, request);
}
use of org.forgerock.services.context.RootContext in project OpenAM by OpenRock.
the class AuthenticationServiceV2Test method shouldFailAuthenticationWithUnsupportedMediaTypeMessage.
@Test
public void shouldFailAuthenticationWithUnsupportedMediaTypeMessage() throws IOException {
// given
AttributesContext context = new AttributesContext(new SessionContext(new RootContext(), mock(Session.class)));
Request httpRequest = new Request();
httpRequest.setEntity("<xml></xml>");
httpRequest.getHeaders().put(ContentTypeHeader.NAME, "application/xml");
// when
Response response = authServiceV2.authenticate(context, httpRequest);
// then
assertThat(response.getStatus()).isEqualTo(Status.UNSUPPORTED_MEDIA_TYPE);
JsonValue responseBody = json(response.getEntity().getJson());
assertThat(responseBody).integerAt("code").isEqualTo(415);
assertThat(responseBody).stringAt("reason").isEqualTo("Unsupported Media Type");
assertThat(responseBody).stringAt("message").isEqualTo("Unsupported Media Type");
}
use of org.forgerock.services.context.RootContext in project OpenAM by OpenRock.
the class AuthenticationServiceV1Test method shouldFailAuthenticationWithUnsupportedMediaTypeMessage.
@Test
public void shouldFailAuthenticationWithUnsupportedMediaTypeMessage() throws IOException {
// given
AttributesContext context = new AttributesContext(new SessionContext(new RootContext(), mock(Session.class)));
Request httpRequest = new Request();
httpRequest.setEntity("<xml></xml>");
httpRequest.getHeaders().put(ContentTypeHeader.NAME, "application/xml");
// when
Response response = authServiceV1.authenticate(context, httpRequest);
// then
assertThat(response.getStatus()).isEqualTo(Status.UNSUPPORTED_MEDIA_TYPE);
assertThat(json(response.getEntity().getJson())).stringAt("errorMessage").isEqualTo("Unsupported Media Type");
}
use of org.forgerock.services.context.RootContext in project OpenAM by OpenRock.
the class SessionResourceTest method actionCollectionShouldLogoutSessionAndReturnEmptyJsonObjectWhenSSOTokenValid.
@Test
public void actionCollectionShouldLogoutSessionAndReturnEmptyJsonObjectWhenSSOTokenValid() throws SSOException {
//Given
cookieResponse = "SSO_TOKEN_ID";
final AttributesContext attrContext = new AttributesContext(new SessionContext(new RootContext(), mock(Session.class)));
final AdviceContext adviceContext = new AdviceContext(attrContext, Collections.<String>emptySet());
final SecurityContext securityContext = new SecurityContext(adviceContext, null, null);
final Context context = ClientContext.newInternalClientContext(new SSOTokenContext(mock(Debug.class), null, securityContext));
final ActionRequest request = mock(ActionRequest.class);
final SSOTokenID ssoTokenId = mock(SSOTokenID.class);
given(request.getAction()).willReturn(LOGOUT_ACTION_ID);
given(authUtilsWrapper.logout(ssoTokenId.toString(), null, null)).willReturn(true);
//When
Promise<ActionResponse, ResourceException> promise = sessionResource.actionCollection(context, request);
//Then
assertThat(promise).succeeded().withContent().stringAt("result").isEqualTo("Successfully logged out");
}
Aggregations