use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.
the class SessionAdapterTest method shouldDoNothingIfLatestAccessTimeNotFound.
@Test
public void shouldDoNothingIfLatestAccessTimeNotFound() throws UnsupportedEncodingException {
// Given
Token mockToken = mock(Token.class);
given(mockToken.getBlob()).willReturn("badger".getBytes(TokenBlobUtils.ENCODING));
// When
adapter.filterLatestAccessTime(mockToken);
// Then
verify(mockToken, times(0)).setBlob(any(byte[].class));
}
use of org.forgerock.openam.cts.api.tokens.Token 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.cts.api.tokens.Token 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.cts.api.tokens.Token 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);
}
use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.
the class TokenDataStoreTest method testCreateError.
@Test(expectedExceptions = ServerException.class)
public void testCreateError() 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]).processError(new Exception());
return task;
}
});
// When
store.create(new Object());
// Then - exception;
}
Aggregations