use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldRejectAlwaysFalseQueryFilters.
@Test(expectedExceptions = EntitlementException.class, expectedExceptionsMessageRegExp = ".*'false' not supported.*")
public void shouldRejectAlwaysFalseQueryFilters() throws Exception {
// Given
QueryRequest request = mockQueryRequest(QueryFilter.<JsonPointer>alwaysFalse());
Subject subject = new Subject();
// When
applicationsResource.query(request, subject, "/abc");
// Then - exception
}
use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldRejectNotQueries.
@Test(expectedExceptions = EntitlementException.class, expectedExceptionsMessageRegExp = ".*not supported.*")
public void shouldRejectNotQueries() throws Exception {
// Given
QueryRequest request = mockQueryRequest(not(QueryFilter.<JsonPointer>alwaysTrue()));
Subject subject = new Subject();
// When
applicationsResource.query(request, subject, "/abc");
// Then - exception
}
use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldRejectUnknownAttributes.
@Test(expectedExceptions = EntitlementException.class, expectedExceptionsMessageRegExp = ".*Unknown query field.*")
public void shouldRejectUnknownAttributes() throws Exception {
// Given
QueryRequest request = mockQueryRequest(equalTo(new JsonPointer("unknown"), "a value"));
Subject subject = new Subject();
// When
applicationsResource.query(request, subject, "/abc");
// Then - exception
}
use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldTranslateAlwaysTrueQueryFilterToEmptySearchFilters.
@Test
public void shouldTranslateAlwaysTrueQueryFilterToEmptySearchFilters() throws Exception {
// Given
QueryRequest request = mockQueryRequest(QueryFilter.<JsonPointer>alwaysTrue());
Subject subject = new Subject();
// When
applicationsResource.query(request, subject, "/abc");
// Then
verify(applicationManagerWrapper).search(eq(subject), eq("/abc"), eq(Collections.<SearchFilter>emptySet()));
}
use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.
the class ApplicationsResourceTest method reservedInternalAppIsMappedDuringQuery.
@Test
public void reservedInternalAppIsMappedDuringQuery() throws EntitlementException, IllegalAccessException, InstantiationException {
// Override the creation of the application wrapper so to return a mocked version.
applicationsResource = new ApplicationsResource(debug, applicationManagerWrapper, applicationTypeManagerWrapper, queryAttributes, resourceErrorHandler) {
@Override
protected ApplicationWrapper createApplicationWrapper(Application application, ApplicationTypeManagerWrapper type) {
ApplicationWrapper wrapper = mock(ApplicationWrapper.class);
String appName = application.getName();
given(wrapper.getName()).willReturn(appName);
try {
JsonValue jsonValue = JsonValueBuilder.jsonValue().put("name", "agentProtectedApplication").build();
given(wrapper.toJsonValue()).willReturn(jsonValue);
} catch (EntitlementException e) {
fail();
}
return wrapper;
}
};
// Given...
SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
realmContext.setSubRealm("abc", "abc");
Context serverContext = ClientContext.newInternalClientContext(realmContext);
QueryRequest request = mock(QueryRequest.class);
given(request.getSortKeys()).willReturn(Arrays.asList(SortKey.ascendingOrder("name")));
Subject subject = new Subject();
given(mockSubjectContext.getCallerSubject()).willReturn(subject);
Set<String> appNames = asSet("iPlanetAMWebAgentService");
given(applicationManagerWrapper.search(eq(subject), eq("/abc"), any(Set.class))).willReturn(appNames);
Application app = mock(Application.class);
given(applicationManagerWrapper.getApplication(eq(subject), eq("/abc"), eq("iPlanetAMWebAgentService"))).willReturn(app);
given(app.getName()).willReturn("agentProtectedApplication");
QueryResourceHandler handler = mock(QueryResourceHandler.class);
given(handler.handleResource(any(ResourceResponse.class))).willReturn(true);
// When...
applicationsResource.queryCollection(serverContext, request, handler);
// Then...
verify(applicationManagerWrapper).search(eq(subject), eq("/abc"), any(Set.class));
verify(applicationManagerWrapper).getApplication(eq(subject), eq("/abc"), anyString());
ArgumentCaptor<ResourceResponse> resourceCapture = ArgumentCaptor.forClass(ResourceResponse.class);
verify(handler).handleResource(resourceCapture.capture());
ResourceResponse resource = resourceCapture.getValue();
assertThat(resource.getId()).isEqualTo("agentProtectedApplication");
}
Aggregations