use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class RealmContextFilterTest method filterShouldConsumeRealmFromRequest.
@Test
public void filterShouldConsumeRealmFromRequest() throws Exception {
//Given
Context context = mockContext(ENDPOINT_PATH_ELEMENT);
Request request = createRequest(HOSTNAME, ENDPOINT_PATH_ELEMENT);
mockDnsAlias(HOSTNAME, "/");
//When
filter.filter(context, request, handler);
//Then
ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
verify(handler).handle(contextCaptor.capture(), eq(request));
verifyRealmContext(contextCaptor.getValue(), "", "/", null);
verifyUriRouterContext(contextCaptor.getValue(), "");
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class RealmContextFilterTest method filterShouldConsumeRealmFromRequestWithDnsAliasAndOverrideRealm.
@Test
public void filterShouldConsumeRealmFromRequestWithDnsAliasAndOverrideRealm() throws Exception {
//Given
Context context = mockContext(ENDPOINT_PATH_ELEMENT);
Request request = createRequest(DNS_ALIAS_HOSTNAME, ENDPOINT_PATH_ELEMENT + "?realm=" + OVERRIDE_REALM);
mockDnsAlias(DNS_ALIAS_HOSTNAME, "/" + DNS_ALIS_SUB_REALM);
mockRealmAlias(OVERRIDE_REALM, OVERRIDE_REALM);
//When
filter.filter(context, request, handler);
//Then
ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
verify(handler).handle(contextCaptor.capture(), eq(request));
verifyRealmContext(contextCaptor.getValue(), "/" + DNS_ALIS_SUB_REALM, "", OVERRIDE_REALM);
verifyUriRouterContext(contextCaptor.getValue(), "");
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class RealmContextFilterTest method filterShouldFailToConsumeRealmFromRequestWithInvalidUriRealm.
@Test
public void filterShouldFailToConsumeRealmFromRequestWithInvalidUriRealm() throws Exception {
//Given
Context context = mockContext(INVALID_SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT);
Request request = createRequest(HOSTNAME, INVALID_SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT);
mockDnsAlias(HOSTNAME, "/");
mockInvalidRealmAlias(INVALID_SUB_REALM);
//When
filter.filter(context, request, handler);
//Then
ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
verify(handler).handle(contextCaptor.capture(), eq(request));
verifyRealmContext(contextCaptor.getValue(), "", "/", null);
verifyUriRouterContextForInvalidRealm(contextCaptor.getValue());
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class AuditFilterTest method shouldAuditSuccessForResults.
@Test
public void shouldAuditSuccessForResults() throws Exception {
ResourceResponse response = mock(ResourceResponse.class);
Promise<ResourceResponse, ResourceException> myPromise = Promises.newResultPromise(response);
given(filterChain.handleUpdate(any(Context.class), any(UpdateRequest.class))).willReturn(myPromise);
given(auditorFactory.create(context, updateRequest)).willReturn(auditor);
AuditFilter auditFilter = new AuditFilter(debug, auditorFactory);
auditFilter.filterUpdate(context, updateRequest, filterChain);
verify(auditor).auditAccessSuccess(null);
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class RequesterTest method emptyLocationBreaksDelete.
//
// test delete()
//
@Test(expectedExceptions = IllegalArgumentException.class)
public void emptyLocationBreaksDelete() throws ResourceException {
// given
String location = "";
String resourceId = "resourceId";
Context fakeContext = mock(Context.class);
// when
requester.delete(location, resourceId, fakeContext);
// then -- matched by expectedExceptions
}
Aggregations