Search in sources :

Example 11 with ResultHandler

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

the class TokenDataStoreTest method testDeleteError.

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

Example 12 with ResultHandler

use of org.forgerock.openam.sm.datalayer.api.ResultHandler 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;
}
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)

Example 13 with ResultHandler

use of org.forgerock.openam.sm.datalayer.api.ResultHandler 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 14 with ResultHandler

use of org.forgerock.openam.sm.datalayer.api.ResultHandler 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

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