use of org.forgerock.openam.sm.datalayer.api.ResultHandler in project OpenAM by OpenRock.
the class TokenDataStoreTest method testRead.
@Test
public void testRead() throws Exception {
// Given
final Token token = new Token("123", TokenType.GENERIC);
Object returned = new Object();
final Task task = mock(Task.class);
when(adapter.fromToken(token)).thenReturn(returned);
when(taskFactory.read(anyString(), any(ResultHandler.class))).thenAnswer(new Answer<Task>() {
@Override
public Task answer(InvocationOnMock invocation) throws Throwable {
((ResultHandler) invocation.getArguments()[1]).processResults(token);
return task;
}
});
// When
Object result = store.read("123");
// Then
verify(taskFactory).read(eq("123"), any(ResultHandler.class));
verify(taskExecutor).execute("123", task);
assertThat(result).isSameAs(returned);
}
use of org.forgerock.openam.sm.datalayer.api.ResultHandler in project OpenAM by OpenRock.
the class TokenDataStoreTest method testUpdateError.
@Test(expectedExceptions = ServerException.class)
public void testUpdateError() throws Exception {
// Given
final Token token = new Token("123", TokenType.GENERIC);
Object returned = new Object();
final Task readTask = mock(Task.class);
final Task updateTask = mock(Task.class);
when(adapter.toToken(any())).thenReturn(token);
when(adapter.fromToken(token)).thenReturn(returned);
when(taskFactory.read(eq("123"), any(ResultHandler.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((ResultHandler) invocation.getArguments()[1]).processResults(token);
return readTask;
}
});
when(taskFactory.update(any(Token.class), any(ResultHandler.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((ResultHandler) invocation.getArguments()[1]).processError(new Exception());
return updateTask;
}
});
// When
store.update(new Object());
// Then - exception
}
use of org.forgerock.openam.sm.datalayer.api.ResultHandler in project OpenAM by OpenRock.
the class TokenDataStoreTest method testUpdateExecutorError.
@Test(expectedExceptions = ServerException.class)
public void testUpdateExecutorError() throws Exception {
// Given
final Token token = new Token("123", TokenType.GENERIC);
Object returned = new Object();
final Task readTask = mock(Task.class);
final Task updateTask = mock(Task.class);
when(adapter.toToken(any())).thenReturn(token);
when(adapter.fromToken(token)).thenReturn(returned);
when(taskFactory.read(eq("123"), any(ResultHandler.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((ResultHandler) invocation.getArguments()[1]).processResults(token);
return readTask;
}
});
when(taskFactory.update(any(Token.class), any(ResultHandler.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((ResultHandler) invocation.getArguments()[1]).processResults(token);
return updateTask;
}
});
doThrow(DataLayerException.class).when(taskExecutor).execute(anyString(), eq(updateTask));
// When
store.update(new Object());
// Then - exception
}
use of org.forgerock.openam.sm.datalayer.api.ResultHandler 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.sm.datalayer.api.ResultHandler 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);
}
Aggregations