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;
}
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;
}
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);
}
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));
}
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));
}
Aggregations