use of org.forgerock.openam.sm.datalayer.api.query.PartialToken in project OpenAM by OpenRock.
the class DeleteOnQueryResultHandlerTest method getHits.
private Collection<PartialToken> getHits(int count) throws Exception {
List<PartialToken> tokens = new ArrayList<PartialToken>(count);
for (int i = 0; i < count; i++) {
PartialToken token = mock(PartialToken.class);
given(token.getValue(CoreTokenField.TOKEN_ID)).willReturn(String.valueOf(i));
tokens.add(token);
}
return tokens;
}
use of org.forgerock.openam.sm.datalayer.api.query.PartialToken in project OpenAM by OpenRock.
the class DeleteOnQueryResultHandlerTest method shouldInvokeDeleteForEachHit.
@Test
public void shouldInvokeDeleteForEachHit() throws Exception {
Collection<PartialToken> hits = getHits(5);
handler.processResults(hits);
for (PartialToken hit : hits) {
verify(mockTaskDispatcher).delete(eq(hit.<String>getValue(CoreTokenField.TOKEN_ID)), any(ResultHandler.class));
}
}
use of org.forgerock.openam.sm.datalayer.api.query.PartialToken in project OpenAM by OpenRock.
the class PartialTokenTest method shouldContainNewFieldInCopyConstructor.
@Test
public void shouldContainNewFieldInCopyConstructor() {
// Given
String id = "badger";
CoreTokenField field = CoreTokenField.TOKEN_ID;
PartialToken first = new PartialToken(Collections.<CoreTokenField, Object>emptyMap());
// When
PartialToken clone = new PartialToken(first, field, id);
// Then
assertThat(clone.<String>getValue(field)).isEqualTo(id);
}
use of org.forgerock.openam.sm.datalayer.api.query.PartialToken in project OpenAM by OpenRock.
the class PartialTokenTest method shouldSupportEmptyCollectionOfFields.
@Test
public void shouldSupportEmptyCollectionOfFields() {
Map<CoreTokenField, Object> empty = Collections.emptyMap();
assertThat(new PartialToken(empty).getFields()).isEmpty();
}
use of org.forgerock.openam.sm.datalayer.api.query.PartialToken in project OpenAM by OpenRock.
the class CTSPersistentStoreImpl method delete.
@Override
public int delete(Map<CoreTokenField, Object> query) throws DeleteFailedException {
TokenFilterBuilder.FilterAttributeBuilder builder = new TokenFilterBuilder().returnAttribute(CoreTokenField.TOKEN_ID).and();
for (Map.Entry<CoreTokenField, Object> entry : query.entrySet()) {
CoreTokenField key = entry.getKey();
Object value = entry.getValue();
builder = builder.withAttribute(key, value);
}
TokenFilter filter = builder.build();
Collection<String> failures = new ArrayList<String>();
try {
Collection<PartialToken> partialTokens = attributeQuery(filter);
debug("Found {0} partial Tokens for deletion", Integer.toString(partialTokens.size()));
for (PartialToken token : partialTokens) {
String tokenId = token.getValue(CoreTokenField.TOKEN_ID);
try {
delete(tokenId);
} catch (CoreTokenException e) {
failures.add(tokenId);
}
}
if (!failures.isEmpty()) {
error("Failed to delete {0} tokens.\n{1}", Integer.toString(failures.size()), StringUtils.join(failures, ","));
}
return partialTokens.size() - failures.size();
} catch (CoreTokenException e) {
throw new DeleteFailedException("Failed to delete Tokens", e);
}
}
Aggregations