use of org.forgerock.openam.tokens.CoreTokenField in project OpenAM by OpenRock.
the class TokenTest method shouldStoreByteData.
@Test
public void shouldStoreByteData() {
// Given
byte[] data = "Badger".getBytes();
CoreTokenField key = CoreTokenField.BLOB;
Token token = new Token("", TokenType.SESSION);
// When
token.setAttribute(key, data);
// Then
assertArrayEquals(data, token.<byte[]>getValue(key));
}
use of org.forgerock.openam.tokens.CoreTokenField 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.tokens.CoreTokenField 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.tokens.CoreTokenField in project OpenAM by OpenRock.
the class CoreTokenFieldTypesTest method shouldValidateByteField.
@Test
public void shouldValidateByteField() throws CoreTokenException {
// Given
CoreTokenField key = CoreTokenField.BLOB;
byte[] value = new byte[] { 1, 2, 3, 4 };
// When / Then
CoreTokenFieldTypes.validateType(key, value);
}
use of org.forgerock.openam.tokens.CoreTokenField in project OpenAM by OpenRock.
the class CoreTokenFieldTypesTest method shouldValidateStringField.
@Test
public void shouldValidateStringField() throws CoreTokenException {
// Given
CoreTokenField key = CoreTokenField.STRING_ONE;
String value = "badger";
// When / Then
CoreTokenFieldTypes.validateType(key, value);
}
Aggregations