use of org.forgerock.openam.cts.api.filter.TokenFilterBuilder 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.TokenFilterBuilder 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));
}
use of org.forgerock.openam.cts.api.filter.TokenFilterBuilder in project OpenAM by OpenRock.
the class LdapAdapterTest method shouldQuery.
@Test
public void shouldQuery() throws Exception {
// Given
final QueryBuilder<Connection, Filter> mockBuilder = mock(QueryBuilder.class);
given(mockBuilder.withFilter(any(Filter.class))).willAnswer(new Answer<QueryBuilder<Connection, Filter>>() {
@Override
public QueryBuilder<Connection, Filter> answer(InvocationOnMock invocation) throws Throwable {
return mockBuilder;
}
});
given(mockBuilder.execute(any(Connection.class))).willReturn(Arrays.asList((Collection<Token>) Arrays.asList(new Token("weasel", TokenType.OAUTH))).iterator());
given(mockQueryFactory.createInstance()).willReturn(mockBuilder);
QueryFilterVisitor<Filter, Void, CoreTokenField> visitor = mock(QueryFilterVisitor.class);
given(mockQueryFactory.createFilterConverter()).willReturn(visitor);
given(visitor.visitBooleanLiteralFilter(null, true)).willReturn(Filter.alwaysTrue());
// When
TokenFilter filter = new TokenFilterBuilder().withQuery(QueryFilter.<CoreTokenField>alwaysTrue()).build();
Collection<Token> result = adapter.query(mockConnection, filter);
// Then
verify(mockBuilder).withFilter(any(Filter.class));
verify(mockBuilder).execute(mockConnection);
assertThat(result.size()).isEqualTo(1);
assertThat(result.iterator().next().getTokenId()).isEqualTo("weasel");
}
use of org.forgerock.openam.cts.api.filter.TokenFilterBuilder in project OpenAM by OpenRock.
the class LdapAdapterTest method shouldPartialQuery.
@Test
public void shouldPartialQuery() throws Exception {
// Given
final QueryBuilder<Connection, Filter> mockBuilder = mock(QueryBuilder.class);
given(mockBuilder.withFilter(any(Filter.class))).willAnswer(new Answer<QueryBuilder<Connection, Filter>>() {
@Override
public QueryBuilder<Connection, Filter> answer(InvocationOnMock invocation) throws Throwable {
return mockBuilder;
}
});
given(mockBuilder.returnTheseAttributes(anySetOf(CoreTokenField.class))).willAnswer(new Answer<QueryBuilder<Connection, Filter>>() {
@Override
public QueryBuilder<Connection, Filter> answer(InvocationOnMock invocation) throws Throwable {
return mockBuilder;
}
});
PartialToken partialToken = new PartialToken(new HashMap<CoreTokenField, Object>());
given(mockBuilder.executeAttributeQuery(any(Connection.class))).willReturn(Arrays.asList((Collection<PartialToken>) Arrays.asList(partialToken)).iterator());
given(mockQueryFactory.createInstance()).willReturn(mockBuilder);
QueryFilterVisitor<Filter, Void, CoreTokenField> visitor = mock(QueryFilterVisitor.class);
given(mockQueryFactory.createFilterConverter()).willReturn(visitor);
given(visitor.visitBooleanLiteralFilter(null, true)).willReturn(Filter.alwaysTrue());
// When
TokenFilter filter = new TokenFilterBuilder().withQuery(QueryFilter.<CoreTokenField>alwaysTrue()).returnAttribute(CoreTokenField.STRING_ONE).build();
Collection<PartialToken> result = adapter.partialQuery(mockConnection, filter);
// Then
verify(mockBuilder).withFilter(any(Filter.class));
verify(mockBuilder).returnTheseAttributes(asSet(CoreTokenField.STRING_ONE));
verify(mockBuilder).executeAttributeQuery(mockConnection);
assertThat(result).containsOnly(partialToken);
}
use of org.forgerock.openam.cts.api.filter.TokenFilterBuilder in project OpenAM by OpenRock.
the class CtsPersistenceOperationsDelegate method listDurationOfTokens.
/**
* Gathers list of the durations of tokens in epoch'd seconds
*
* @param tokenType The type of token for which we are gathering results
* @return A collection of longs, each of which represents the duration of a token inside the CTS
* @throws CoreTokenException
*/
public Collection<Long> listDurationOfTokens(TokenType tokenType) throws CoreTokenException {
final Collection<Long> results = new ArrayList<Long>();
final long unixTime = TimeUtils.currentUnixTime();
final TokenFilter filter = new TokenFilterBuilder().returnAttribute(CoreTokenField.CREATE_TIMESTAMP).and().withAttribute(CoreTokenField.TOKEN_TYPE, tokenType).build();
for (PartialToken token : store.attributeQuery(filter)) {
Calendar timestamp = token.getValue(CoreTokenField.CREATE_TIMESTAMP);
results.add(unixTime - TimeUtils.toUnixTime(timestamp));
}
return results;
}
Aggregations