Search in sources :

Example 6 with ResultHandler

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
}
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 7 with ResultHandler

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);
}
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 8 with ResultHandler

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");
}
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 9 with ResultHandler

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);
}
Also used : Task(org.forgerock.openam.sm.datalayer.api.Task) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ResultHandler(org.forgerock.openam.sm.datalayer.api.ResultHandler) Test(org.testng.annotations.Test)

Example 10 with ResultHandler

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);
}
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)

Aggregations

ResultHandler (org.forgerock.openam.sm.datalayer.api.ResultHandler)14 Task (org.forgerock.openam.sm.datalayer.api.Task)14 InvocationOnMock (org.mockito.invocation.InvocationOnMock)14 Test (org.testng.annotations.Test)14 Token (org.forgerock.openam.cts.api.tokens.Token)12 DataLayerException (org.forgerock.openam.sm.datalayer.api.DataLayerException)5 TokenFilter (org.forgerock.openam.cts.api.filter.TokenFilter)2