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