Search in sources :

Example 56 with Token

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));
}
Also used : Token(org.forgerock.openam.cts.api.tokens.Token) Test(org.testng.annotations.Test)

Example 57 with Token

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);
}
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 58 with Token

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");
}
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 59 with Token

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);
}
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 60 with Token

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

Token (org.forgerock.openam.cts.api.tokens.Token)86 Test (org.testng.annotations.Test)58 Task (org.forgerock.openam.sm.datalayer.api.Task)17 ResultHandler (org.forgerock.openam.sm.datalayer.api.ResultHandler)16 PartialToken (org.forgerock.openam.sm.datalayer.api.query.PartialToken)16 InvocationOnMock (org.mockito.invocation.InvocationOnMock)14 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)13 InternalSession (com.iplanet.dpro.session.service.InternalSession)8 DataLayerException (org.forgerock.openam.sm.datalayer.api.DataLayerException)8 Calendar (java.util.Calendar)7 JsonValue (org.forgerock.json.JsonValue)7 SessionID (com.iplanet.dpro.session.SessionID)6 TokenFilter (org.forgerock.openam.cts.api.filter.TokenFilter)6 Collection (java.util.Collection)5 HashMap (java.util.HashMap)5 Entry (org.forgerock.opendj.ldap.Entry)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 SAMLToken (org.forgerock.openam.cts.api.tokens.SAMLToken)4 Connection (org.forgerock.opendj.ldap.Connection)4 LinkedHashMapEntry (org.forgerock.opendj.ldap.LinkedHashMapEntry)4