Search in sources :

Example 21 with QueryRequest

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

the class PrivilegePolicyStoreTest method shouldHandleStringEquality.

@Test
public void shouldHandleStringEquality() throws Exception {
    // Given
    String value = "testValue";
    QueryRequest request = mockQueryRequest(QueryFilter.equalTo(new JsonPointer(STRING_ATTRIBUTE), value));
    // When
    testStore.query(request);
    // Then
    verify(mockManager).search(singleton(new SearchFilter(STRING_SEARCH_ATTRIBUTE, value)));
}
Also used : QueryRequest(org.forgerock.json.resource.QueryRequest) SearchFilter(com.sun.identity.entitlement.util.SearchFilter) JsonPointer(org.forgerock.json.JsonPointer) Test(org.testng.annotations.Test)

Example 22 with QueryRequest

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

the class PrivilegePolicyStoreTest method shouldRejectPresenceQueries.

@Test(expectedExceptions = EntitlementException.class, expectedExceptionsMessageRegExp = ".*not supported.*")
public void shouldRejectPresenceQueries() throws Exception {
    // Given
    QueryRequest request = mockQueryRequest(QueryFilter.present(new JsonPointer((STRING_ATTRIBUTE))));
    // When
    testStore.query(request);
// Then - exception
}
Also used : QueryRequest(org.forgerock.json.resource.QueryRequest) JsonPointer(org.forgerock.json.JsonPointer) Test(org.testng.annotations.Test)

Example 23 with QueryRequest

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

the class SubjectTypesResourceTest method testSuccessfulJsonificationAndQuery.

@Test
public void testSuccessfulJsonificationAndQuery() throws Exception {
    //given
    SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(mockSubjectContext);
    Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
    Subject mockSubject = new Subject();
    given(mockSubjectContext.getCallerSubject()).willReturn(mockSubject);
    QueryRequest mockRequest = mock(QueryRequest.class);
    JsonSchema mockSchema = mock(JsonSchema.class);
    QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
    given(mockRequest.getPageSize()).willReturn(2);
    given(mockHandler.handleResource(any(ResourceResponse.class))).willReturn(true);
    given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
    //when
    Promise<QueryResponse, ResourceException> promise = testResource.queryCollection(mockServerContext, mockRequest, mockHandler);
    //then
    assertThat(promise).succeeded();
    verify(mockHandler, times(2)).handleResource(any(ResourceResponse.class));
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) RealmContext(org.forgerock.openam.rest.RealmContext) QueryRequest(org.forgerock.json.resource.QueryRequest) ResourceResponse(org.forgerock.json.resource.ResourceResponse) JsonSchema(com.fasterxml.jackson.databind.jsonschema.JsonSchema) QueryResponse(org.forgerock.json.resource.QueryResponse) ResourceException(org.forgerock.json.resource.ResourceException) QueryResourceHandler(org.forgerock.json.resource.QueryResourceHandler) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) Subject(javax.security.auth.Subject) LogicalSubject(com.sun.identity.entitlement.LogicalSubject) Test(org.testng.annotations.Test)

Example 24 with QueryRequest

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

the class ApplicationsResourceTest method shouldRejectOrQueries.

@Test(expectedExceptions = EntitlementException.class, expectedExceptionsMessageRegExp = ".*'Or' not supported.*")
public void shouldRejectOrQueries() throws Exception {
    // Given
    QueryRequest request = mockQueryRequest(or(QueryFilter.<JsonPointer>alwaysTrue(), QueryFilter.<JsonPointer>alwaysTrue()));
    Subject subject = new Subject();
    // When
    applicationsResource.query(request, subject, "/abc");
// Then - exception
}
Also used : QueryRequest(org.forgerock.json.resource.QueryRequest) JsonPointer(org.forgerock.json.JsonPointer) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 25 with QueryRequest

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

the class ApplicationsResourceTest method shouldRejectUnsupportedQueryOperators.

@Test(dataProvider = "UnsupportedOperators", expectedExceptions = EntitlementException.class, expectedExceptionsMessageRegExp = ".*not supported.*")
public void shouldRejectUnsupportedQueryOperators(String queryOperator) throws Exception {
    // Given
    QueryRequest request = mockQueryRequest(comparisonFilter(new JsonPointer(NUMERIC_ATTRIBUTE), queryOperator, 123l));
    Subject subject = new Subject();
    // When
    applicationsResource.query(request, subject, "/abc");
// Then - exception
}
Also used : QueryRequest(org.forgerock.json.resource.QueryRequest) JsonPointer(org.forgerock.json.JsonPointer) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Aggregations

QueryRequest (org.forgerock.json.resource.QueryRequest)79 Test (org.testng.annotations.Test)68 QueryResponse (org.forgerock.json.resource.QueryResponse)40 JsonPointer (org.forgerock.json.JsonPointer)34 Context (org.forgerock.services.context.Context)34 QueryResourceHandler (org.forgerock.json.resource.QueryResourceHandler)29 ResourceException (org.forgerock.json.resource.ResourceException)28 Subject (javax.security.auth.Subject)26 RealmContext (org.forgerock.openam.rest.RealmContext)26 ResourceResponse (org.forgerock.json.resource.ResourceResponse)24 ClientContext (org.forgerock.services.context.ClientContext)22 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)20 Collection (java.util.Collection)15 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)15 SearchFilter (com.sun.identity.entitlement.util.SearchFilter)10 Matchers.anyString (org.mockito.Matchers.anyString)9 JsonValue (org.forgerock.json.JsonValue)8 ArrayList (java.util.ArrayList)7 Set (java.util.Set)7 EntitlementException (com.sun.identity.entitlement.EntitlementException)6