use of org.forgerock.openam.sm.datalayer.api.Task 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.Task in project OpenAM by OpenRock.
the class TokenDataStoreTest method testCreateExecutorError.
@Test(expectedExceptions = ServerException.class)
public void testCreateExecutorError() throws Exception {
// Given
Token token = new Token("123", TokenType.GENERIC);
final Task task = mock(Task.class);
when(adapter.toToken(anyObject())).thenReturn(token);
when(taskFactory.create(any(Token.class), any(ResultHandler.class))).thenReturn(task);
doThrow(DataLayerException.class).when(taskExecutor).execute("123", task);
// When
store.create(new Object());
// Then - exception;
}
use of org.forgerock.openam.sm.datalayer.api.Task 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.Task 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.Task 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;
}
Aggregations