Search in sources :

Example 6 with TokenFilter

use of org.forgerock.openam.cts.api.filter.TokenFilter in project OpenAM by OpenRock.

the class TokenDataStoreTest method testQueryExecutorError.

@Test(expectedExceptions = ServerException.class)
public void testQueryExecutorError() throws Exception {
    // Given
    QueryFilter<String> query = QueryFilter.alwaysTrue();
    TokenFilter tokenFilter = mock(TokenFilter.class);
    when(adapter.toTokenQuery(query)).thenReturn(tokenFilter);
    final Token token1 = new Token("123", TokenType.GENERIC);
    final Token token2 = new Token("456", TokenType.GENERIC);
    Object o1 = new Object();
    Object o2 = new Object();
    when(adapter.fromToken(token1)).thenReturn(o1);
    when(adapter.fromToken(token2)).thenReturn(o2);
    final Task task = mock(Task.class);
    when(taskFactory.query(any(TokenFilter.class), any(ResultHandler.class))).thenReturn(task);
    doThrow(DataLayerException.class).when(taskExecutor).execute(null, task);
    // When
    store.query(query);
// Then - exception;
}
Also used : Task(org.forgerock.openam.sm.datalayer.api.Task) Token(org.forgerock.openam.cts.api.tokens.Token) ResultHandler(org.forgerock.openam.sm.datalayer.api.ResultHandler) TokenFilter(org.forgerock.openam.cts.api.filter.TokenFilter) Test(org.testng.annotations.Test)

Example 7 with TokenFilter

use of org.forgerock.openam.cts.api.filter.TokenFilter in project OpenAM by OpenRock.

the class TokenDataStoreTest method testQueryError.

@Test(expectedExceptions = ServerException.class)
public void testQueryError() throws Exception {
    // Given
    QueryFilter<String> query = QueryFilter.alwaysTrue();
    TokenFilter tokenFilter = mock(TokenFilter.class);
    when(adapter.toTokenQuery(query)).thenReturn(tokenFilter);
    final Token token1 = new Token("123", TokenType.GENERIC);
    final Token token2 = new Token("456", TokenType.GENERIC);
    Object o1 = new Object();
    Object o2 = new Object();
    when(adapter.fromToken(token1)).thenReturn(o1);
    when(adapter.fromToken(token2)).thenReturn(o2);
    final Task task = mock(Task.class);
    when(taskFactory.query(any(TokenFilter.class), any(ResultHandler.class))).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            ((ResultHandler) invocation.getArguments()[1]).processError(new Exception());
            return task;
        }
    });
    // When
    store.query(query);
// Then - exception;
}
Also used : Task(org.forgerock.openam.sm.datalayer.api.Task) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Token(org.forgerock.openam.cts.api.tokens.Token) ResultHandler(org.forgerock.openam.sm.datalayer.api.ResultHandler) DataLayerException(org.forgerock.openam.sm.datalayer.api.DataLayerException) TokenFilter(org.forgerock.openam.cts.api.filter.TokenFilter) Test(org.testng.annotations.Test)

Example 8 with TokenFilter

use of org.forgerock.openam.cts.api.filter.TokenFilter in project OpenAM by OpenRock.

the class TokenDataStoreTest method testQuery.

@Test
public void testQuery() throws Exception {
    // Given
    QueryFilter<String> query = QueryFilter.alwaysTrue();
    TokenFilter tokenFilter = mock(TokenFilter.class);
    when(adapter.toTokenQuery(query)).thenReturn(tokenFilter);
    final Token token1 = new Token("123", TokenType.GENERIC);
    final Token token2 = new Token("456", TokenType.GENERIC);
    Object o1 = new Object();
    Object o2 = new Object();
    when(adapter.fromToken(token1)).thenReturn(o1);
    when(adapter.fromToken(token2)).thenReturn(o2);
    final Task task = mock(Task.class);
    when(taskFactory.query(any(TokenFilter.class), any(ResultHandler.class))).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            ((ResultHandler) invocation.getArguments()[1]).processResults(asSet(token1, token2));
            return task;
        }
    });
    // When
    Set<Object> result = store.query(query);
    // Then
    verify(taskFactory).query(eq(tokenFilter), any(ResultHandler.class));
    verify(taskExecutor).execute(null, task);
    assertThat(result).containsOnly(o1, o2);
}
Also used : Task(org.forgerock.openam.sm.datalayer.api.Task) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Token(org.forgerock.openam.cts.api.tokens.Token) ResultHandler(org.forgerock.openam.sm.datalayer.api.ResultHandler) TokenFilter(org.forgerock.openam.cts.api.filter.TokenFilter) Test(org.testng.annotations.Test)

Example 9 with TokenFilter

use of org.forgerock.openam.cts.api.filter.TokenFilter in project OpenAM by OpenRock.

the class CoreTokenAdapterTest method shouldUseTaskQueueForQuery.

@Test
public void shouldUseTaskQueueForQuery() throws CoreTokenException {
    // Given
    Collection<Token> tokens = new ArrayList<Token>();
    ResultHandler<Collection<Token>, CoreTokenException> mockResultHandler = mock(ResultHandler.class);
    given(mockResultHandler.getResults()).willReturn(tokens);
    given(mockResultHandlerFactory.getQueryHandler()).willReturn(mockResultHandler);
    TokenFilter filter = new TokenFilterBuilder().and().build();
    // When
    adapter.query(filter);
    // Then
    verify(mockTaskDispatcher).query(eq(filter), eq(mockResultHandler));
}
Also used : ArrayList(java.util.ArrayList) Collection(java.util.Collection) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) Token(org.forgerock.openam.cts.api.tokens.Token) PartialToken(org.forgerock.openam.sm.datalayer.api.query.PartialToken) TokenFilterBuilder(org.forgerock.openam.cts.api.filter.TokenFilterBuilder) TokenFilter(org.forgerock.openam.cts.api.filter.TokenFilter) Test(org.testng.annotations.Test)

Example 10 with TokenFilter

use of org.forgerock.openam.cts.api.filter.TokenFilter in project OpenAM by OpenRock.

the class CoreTokenAdapterTest method shouldUseTaskQueueForAttributeQuery.

@Test
public void shouldUseTaskQueueForAttributeQuery() throws CoreTokenException {
    // Given
    Collection<PartialToken> partialTokens = new ArrayList<PartialToken>();
    ResultHandler<Collection<PartialToken>, CoreTokenException> mockResultHandler = mock(ResultHandler.class);
    given(mockResultHandler.getResults()).willReturn(partialTokens);
    given(mockResultHandlerFactory.getPartialQueryHandler()).willReturn(mockResultHandler);
    TokenFilter filter = new TokenFilterBuilder().returnAttribute(CoreTokenField.BLOB).build();
    // When
    adapter.attributeQuery(filter);
    // Then
    verify(mockTaskDispatcher).partialQuery(eq(filter), eq(mockResultHandler));
}
Also used : PartialToken(org.forgerock.openam.sm.datalayer.api.query.PartialToken) ArrayList(java.util.ArrayList) Collection(java.util.Collection) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) TokenFilterBuilder(org.forgerock.openam.cts.api.filter.TokenFilterBuilder) TokenFilter(org.forgerock.openam.cts.api.filter.TokenFilter) Test(org.testng.annotations.Test)

Aggregations

TokenFilter (org.forgerock.openam.cts.api.filter.TokenFilter)15 TokenFilterBuilder (org.forgerock.openam.cts.api.filter.TokenFilterBuilder)10 Test (org.testng.annotations.Test)10 PartialToken (org.forgerock.openam.sm.datalayer.api.query.PartialToken)7 Token (org.forgerock.openam.cts.api.tokens.Token)6 ArrayList (java.util.ArrayList)5 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)5 Task (org.forgerock.openam.sm.datalayer.api.Task)5 ResultHandler (org.forgerock.openam.sm.datalayer.api.ResultHandler)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 CoreTokenField (org.forgerock.openam.tokens.CoreTokenField)3 Calendar (java.util.Calendar)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 QueryBuilder (org.forgerock.openam.sm.datalayer.api.query.QueryBuilder)2 Connection (org.forgerock.opendj.ldap.Connection)2 Filter (org.forgerock.opendj.ldap.Filter)2 QueryFilter (org.forgerock.util.query.QueryFilter)2 SessionException (com.iplanet.dpro.session.SessionException)1 SSOException (com.iplanet.sso.SSOException)1