Search in sources :

Example 1 with SearchAttribute

use of com.sun.identity.entitlement.util.SearchAttribute in project OpenAM by OpenRock.

the class ApplicationsResourceTest method shouldHandleAndQueries.

@Test
public void shouldHandleAndQueries() throws Exception {
    // Given
    String value1 = "value1";
    String value2 = "value2";
    QueryRequest request = mockQueryRequest(and(equalTo(new JsonPointer(STRING_ATTRIBUTE), value1), equalTo(new JsonPointer(STRING_ATTRIBUTE), value2)));
    Subject subject = new Subject();
    // When
    applicationsResource.query(request, subject, "/abc");
    // Then
    SearchFilter searchFilter1 = new SearchFilter(new SearchAttribute(STRING_ATTRIBUTE, "ou"), value1);
    SearchFilter searchFilter2 = new SearchFilter(new SearchAttribute(STRING_ATTRIBUTE, "ou"), value2);
    verify(applicationManagerWrapper).search(eq(subject), eq("/abc"), eq(asSet(searchFilter1, searchFilter2)));
}
Also used : SearchAttribute(com.sun.identity.entitlement.util.SearchAttribute) QueryRequest(org.forgerock.json.resource.QueryRequest) SearchFilter(com.sun.identity.entitlement.util.SearchFilter) Matchers.anyString(org.mockito.Matchers.anyString) JsonPointer(org.forgerock.json.JsonPointer) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 2 with SearchAttribute

use of com.sun.identity.entitlement.util.SearchAttribute in project OpenAM by OpenRock.

the class ApplicationsResourceTest method shouldSupportDateQueries.

@Test(dataProvider = "SupportedQueryOperators")
public void shouldSupportDateQueries(String queryOperator, SearchFilter.Operator expectedOperator) throws Exception {
    // Given
    // Note: only second accuracy supported in timestamp format
    Date value = new Date(123456789000l);
    QueryRequest request = mockQueryRequest(comparisonFilter(new JsonPointer(DATE_ATTRIBUTE), queryOperator, DateUtils.toUTCDateFormat(value)));
    Subject subject = new Subject();
    // When
    applicationsResource.query(request, subject, "/abc");
    // Then
    // Date should be converted into a time-stamp long value
    SearchFilter searchFilter = new SearchFilter(new SearchAttribute(DATE_ATTRIBUTE, "ou"), value.getTime(), expectedOperator);
    verify(applicationManagerWrapper).search(eq(subject), eq("/abc"), eq(asSet(searchFilter)));
}
Also used : SearchAttribute(com.sun.identity.entitlement.util.SearchAttribute) QueryRequest(org.forgerock.json.resource.QueryRequest) SearchFilter(com.sun.identity.entitlement.util.SearchFilter) JsonPointer(org.forgerock.json.JsonPointer) Date(java.util.Date) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 3 with SearchAttribute

use of com.sun.identity.entitlement.util.SearchAttribute in project OpenAM by OpenRock.

the class ApplicationsResourceTest method setUp.

@BeforeMethod
public void setUp() {
    debug = mock(Debug.class);
    applicationManagerWrapper = mock(ApplicationManagerWrapper.class);
    applicationTypeManagerWrapper = mock(ApplicationTypeManagerWrapper.class);
    applicationWrapper = mock(ApplicationWrapper.class);
    queryAttributes = new HashMap<String, QueryAttribute>();
    queryAttributes.put(STRING_ATTRIBUTE, new QueryAttribute(AttributeType.STRING, new SearchAttribute(STRING_ATTRIBUTE, "ou")));
    queryAttributes.put(NUMERIC_ATTRIBUTE, new QueryAttribute(AttributeType.NUMBER, new SearchAttribute(NUMERIC_ATTRIBUTE, "ou")));
    queryAttributes.put(DATE_ATTRIBUTE, new QueryAttribute(AttributeType.TIMESTAMP, new SearchAttribute(DATE_ATTRIBUTE, "ou")));
    applicationsResource = new ApplicationsResource(debug, applicationManagerWrapper, applicationTypeManagerWrapper, queryAttributes, resourceErrorHandler) {

        @Override
        protected ApplicationWrapper createApplicationWrapper(JsonValue jsonValue, Subject mySubject) throws EntitlementException {
            return applicationWrapper;
        }
    };
}
Also used : ApplicationTypeManagerWrapper(org.forgerock.openam.entitlement.rest.wrappers.ApplicationTypeManagerWrapper) JsonValue(org.forgerock.json.JsonValue) Matchers.anyString(org.mockito.Matchers.anyString) ApplicationManagerWrapper(org.forgerock.openam.entitlement.rest.wrappers.ApplicationManagerWrapper) Subject(javax.security.auth.Subject) SearchAttribute(com.sun.identity.entitlement.util.SearchAttribute) EntitlementException(com.sun.identity.entitlement.EntitlementException) ApplicationWrapper(org.forgerock.openam.entitlement.rest.wrappers.ApplicationWrapper) QueryAttribute(org.forgerock.openam.entitlement.rest.query.QueryAttribute) Debug(com.sun.identity.shared.debug.Debug) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with SearchAttribute

use of com.sun.identity.entitlement.util.SearchAttribute in project OpenAM by OpenRock.

the class ApplicationsResourceTest method shouldHandleStringEquality.

@Test
public void shouldHandleStringEquality() throws Exception {
    // Given
    String value = "testValue";
    QueryRequest request = mockQueryRequest(equalTo(new JsonPointer(STRING_ATTRIBUTE), value));
    Subject subject = new Subject();
    // When
    applicationsResource.query(request, subject, "/abc");
    // Then
    SearchFilter searchFilter = new SearchFilter(new SearchAttribute(STRING_ATTRIBUTE, "ou"), value);
    verify(applicationManagerWrapper).search(eq(subject), eq("/abc"), eq(asSet(searchFilter)));
}
Also used : SearchAttribute(com.sun.identity.entitlement.util.SearchAttribute) QueryRequest(org.forgerock.json.resource.QueryRequest) SearchFilter(com.sun.identity.entitlement.util.SearchFilter) Matchers.anyString(org.mockito.Matchers.anyString) JsonPointer(org.forgerock.json.JsonPointer) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 5 with SearchAttribute

use of com.sun.identity.entitlement.util.SearchAttribute in project OpenAM by OpenRock.

the class ApplicationsResourceTest method shouldTranslateSupportedOperators.

@Test(dataProvider = "SupportedQueryOperators")
public void shouldTranslateSupportedOperators(String queryOperator, SearchFilter.Operator expectedOperator) throws Exception {
    // Given
    long value = 123l;
    QueryRequest request = mockQueryRequest(comparisonFilter(new JsonPointer(NUMERIC_ATTRIBUTE), queryOperator, value));
    Subject subject = new Subject();
    // When
    applicationsResource.query(request, subject, "/abc");
    // Then
    SearchFilter searchFilter = new SearchFilter(new SearchAttribute(NUMERIC_ATTRIBUTE, "ou"), value, expectedOperator);
    verify(applicationManagerWrapper).search(eq(subject), eq("/abc"), eq(asSet(searchFilter)));
}
Also used : SearchAttribute(com.sun.identity.entitlement.util.SearchAttribute) QueryRequest(org.forgerock.json.resource.QueryRequest) SearchFilter(com.sun.identity.entitlement.util.SearchFilter) JsonPointer(org.forgerock.json.JsonPointer) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Aggregations

SearchAttribute (com.sun.identity.entitlement.util.SearchAttribute)5 Subject (javax.security.auth.Subject)5 SearchFilter (com.sun.identity.entitlement.util.SearchFilter)4 JsonPointer (org.forgerock.json.JsonPointer)4 QueryRequest (org.forgerock.json.resource.QueryRequest)4 Test (org.testng.annotations.Test)4 Matchers.anyString (org.mockito.Matchers.anyString)3 EntitlementException (com.sun.identity.entitlement.EntitlementException)1 Debug (com.sun.identity.shared.debug.Debug)1 Date (java.util.Date)1 JsonValue (org.forgerock.json.JsonValue)1 QueryAttribute (org.forgerock.openam.entitlement.rest.query.QueryAttribute)1 ApplicationManagerWrapper (org.forgerock.openam.entitlement.rest.wrappers.ApplicationManagerWrapper)1 ApplicationTypeManagerWrapper (org.forgerock.openam.entitlement.rest.wrappers.ApplicationTypeManagerWrapper)1 ApplicationWrapper (org.forgerock.openam.entitlement.rest.wrappers.ApplicationWrapper)1 BeforeMethod (org.testng.annotations.BeforeMethod)1