Search in sources :

Example 26 with Task

use of org.forgerock.openam.sm.datalayer.api.Task in project OpenAM by OpenRock.

the class TokenDataStoreTest method testReadNotExisting.

@Test(expectedExceptions = NotFoundException.class)
public void testReadNotExisting() 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(null);
            return task;
        }
    });
    // When
    store.read("123");
}
Also used : Task(org.forgerock.openam.sm.datalayer.api.Task) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Token(org.forgerock.openam.cts.api.tokens.Token) ResultHandler(org.forgerock.openam.sm.datalayer.api.ResultHandler) Test(org.testng.annotations.Test)

Example 27 with Task

use of org.forgerock.openam.sm.datalayer.api.Task in project OpenAM by OpenRock.

the class TokenDataStoreTest method testDeleteExecutorError.

@Test(expectedExceptions = ServerException.class)
public void testDeleteExecutorError() throws Exception {
    // Given
    final Task task = mock(Task.class);
    when(taskFactory.delete(anyString(), any(ResultHandler.class))).thenReturn(task);
    doThrow(DataLayerException.class).when(taskExecutor).execute("123", task);
    // When
    store.delete("123");
// Then - exception
}
Also used : Task(org.forgerock.openam.sm.datalayer.api.Task) ResultHandler(org.forgerock.openam.sm.datalayer.api.ResultHandler) Test(org.testng.annotations.Test)

Example 28 with Task

use of org.forgerock.openam.sm.datalayer.api.Task in project OpenAM by OpenRock.

the class TokenDataStoreTest method testReadError.

@Test(expectedExceptions = ServerException.class)
public void testReadError() 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]).processError(new Exception());
            return task;
        }
    });
    // When
    store.read("123");
}
Also used : Task(org.forgerock.openam.sm.datalayer.api.Task) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Token(org.forgerock.openam.cts.api.tokens.Token) ResultHandler(org.forgerock.openam.sm.datalayer.api.ResultHandler) DataLayerException(org.forgerock.openam.sm.datalayer.api.DataLayerException) Test(org.testng.annotations.Test)

Aggregations

Task (org.forgerock.openam.sm.datalayer.api.Task)28 Test (org.testng.annotations.Test)26 Token (org.forgerock.openam.cts.api.tokens.Token)17 ResultHandler (org.forgerock.openam.sm.datalayer.api.ResultHandler)17 InvocationOnMock (org.mockito.invocation.InvocationOnMock)15 DataLayerException (org.forgerock.openam.sm.datalayer.api.DataLayerException)7 TokenFilter (org.forgerock.openam.cts.api.filter.TokenFilter)5 Debug (com.sun.identity.shared.debug.Debug)1 Closeable (java.io.Closeable)1 Collection (java.util.Collection)1 Semaphore (java.util.concurrent.Semaphore)1 ConnectionConfig (org.forgerock.openam.sm.ConnectionConfig)1 ConnectionConfigFactory (org.forgerock.openam.sm.ConnectionConfigFactory)1 ConnectionType (org.forgerock.openam.sm.datalayer.api.ConnectionType)1 TaskExecutor (org.forgerock.openam.sm.datalayer.api.TaskExecutor)1