Search in sources :

Example 16 with AuthenticationToken

use of tech.aroma.thrift.authentication.AuthenticationToken in project aroma-data-operations by RedRoma.

the class MemoryTokenRepository method deleteToken.

@Override
public void deleteToken(String tokenId) throws TException {
    checkThat(tokenId).usingMessage("missing tokenId").throwing(InvalidArgumentException.class).is(nonEmptyString());
    synchronized (tokens) {
        AuthenticationToken token = tokens.remove(tokenId);
        if (token == null) {
            return;
        }
        deleteTokenFromOwner(token);
    }
}
Also used : InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) AuthenticationToken(tech.aroma.thrift.authentication.AuthenticationToken)

Example 17 with AuthenticationToken

use of tech.aroma.thrift.authentication.AuthenticationToken in project aroma-data-operations by RedRoma.

the class MemoryTokenRepository method deleteTokenFromOwner.

private void deleteTokenFromOwner(AuthenticationToken token) {
    String ownerId = token.ownerId;
    synchronized (tokens) {
        List<AuthenticationToken> ownerTokens = tokensByOwner.getOrDefault(ownerId, Lists.emptyList());
        ownerTokens = ownerTokens.stream().filter(t -> !Objects.equals(t.tokenId, token.tokenId)).collect(toList());
        this.tokensByOwner.put(ownerId, ownerTokens);
    }
}
Also used : AuthenticationToken(tech.aroma.thrift.authentication.AuthenticationToken) StringAssertions.nonEmptyString(tech.sirwellington.alchemy.arguments.assertions.StringAssertions.nonEmptyString)

Example 18 with AuthenticationToken

use of tech.aroma.thrift.authentication.AuthenticationToken in project aroma-data-operations by RedRoma.

the class RequestAssertionsTest method testTokenContainingOwnerIdWithBadArgs.

@Test
public void testTokenContainingOwnerIdWithBadArgs() {
    AlchemyAssertion<AuthenticationToken> assertion = RequestAssertions.tokenContainingOwnerId();
    assertThat(assertion, notNullValue());
    assertThrows(() -> assertion.check(null)).isInstanceOf(FailedAssertionException.class);
    AuthenticationToken emptyToken = new AuthenticationToken();
    assertThrows(() -> assertion.check(emptyToken)).isInstanceOf(FailedAssertionException.class);
}
Also used : AuthenticationToken(tech.aroma.thrift.authentication.AuthenticationToken) Test(org.junit.Test)

Example 19 with AuthenticationToken

use of tech.aroma.thrift.authentication.AuthenticationToken in project aroma-data-operations by RedRoma.

the class CassandraTokenRepositoryTest method testGetToken.

@Test
public void testGetToken() throws Exception {
    AuthenticationToken result = instance.getToken(tokenId);
    assertThat(result, is(token));
}
Also used : AuthenticationToken(tech.aroma.thrift.authentication.AuthenticationToken) Test(org.junit.Test)

Example 20 with AuthenticationToken

use of tech.aroma.thrift.authentication.AuthenticationToken in project aroma-data-operations by RedRoma.

the class CassandraTokenRepositoryTest method testGetTokensBelongingTo.

@Test
public void testGetTokensBelongingTo() throws Exception {
    AlchemyGenerator<AuthenticationToken> generator = pojos(AuthenticationToken.class);
    Set<AuthenticationToken> expected = listOf(generator).stream().map(t -> t.setOwnerId(ownerId)).map(t -> t.setTokenId(one(uuids))).map(t -> t.setOrganizationId(one(uuids))).collect(toSet());
    Map<AuthenticationToken, Row> rows = Maps.create();
    for (AuthenticationToken t : expected) {
        Row mockRow = mock(Row.class);
        when(tokenMapper.apply(mockRow)).thenReturn(t);
        rows.put(t, mockRow);
    }
    when(results.iterator()).thenReturn(rows.values().iterator());
    Set<AuthenticationToken> result = Sets.toSet(instance.getTokensBelongingTo(ownerId));
    assertThat(result, is(expected));
}
Also used : Row(com.datastax.driver.core.Row) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) GeneratePojo(tech.sirwellington.alchemy.test.junit.runners.GeneratePojo) AlchemyTestRunner(tech.sirwellington.alchemy.test.junit.runners.AlchemyTestRunner) Function(java.util.function.Function) Captor(org.mockito.Captor) AuthenticationToken(tech.aroma.thrift.authentication.AuthenticationToken) UUID(tech.sirwellington.alchemy.test.junit.runners.GenerateString.Type.UUID) Assert.assertThat(org.junit.Assert.assertThat) Repeat(tech.sirwellington.alchemy.test.junit.runners.Repeat) ResultSet(com.datastax.driver.core.ResultSet) ArgumentCaptor(org.mockito.ArgumentCaptor) Session(com.datastax.driver.core.Session) Map(java.util.Map) BatchStatement(com.datastax.driver.core.BatchStatement) Collectors.toSet(java.util.stream.Collectors.toSet) Before(org.junit.Before) RETURNS_MOCKS(org.mockito.Answers.RETURNS_MOCKS) Sets(sir.wellington.alchemy.collections.sets.Sets) InvalidTokenException(tech.aroma.thrift.exceptions.InvalidTokenException) Maps(sir.wellington.alchemy.collections.maps.Maps) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Set(java.util.Set) TException(org.apache.thrift.TException) ObjectGenerators.pojos(tech.sirwellington.alchemy.generator.ObjectGenerators.pojos) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) AlchemyGenerator.one(tech.sirwellington.alchemy.generator.AlchemyGenerator.one) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) Mockito.verify(org.mockito.Mockito.verify) CollectionGenerators.listOf(tech.sirwellington.alchemy.generator.CollectionGenerators.listOf) DontRepeat(tech.sirwellington.alchemy.test.junit.runners.DontRepeat) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException) AlchemyGenerator(tech.sirwellington.alchemy.generator.AlchemyGenerator) ThrowableAssertion.assertThrows(tech.sirwellington.alchemy.test.junit.ThrowableAssertion.assertThrows) Cluster(com.datastax.driver.core.Cluster) GenerateString(tech.sirwellington.alchemy.test.junit.runners.GenerateString) NumberGenerators.positiveLongs(tech.sirwellington.alchemy.generator.NumberGenerators.positiveLongs) StringGenerators.uuids(tech.sirwellington.alchemy.generator.StringGenerators.uuids) ALPHABETIC(tech.sirwellington.alchemy.test.junit.runners.GenerateString.Type.ALPHABETIC) Matchers.is(org.hamcrest.Matchers.is) Statement(com.datastax.driver.core.Statement) Mockito.mock(org.mockito.Mockito.mock) AuthenticationToken(tech.aroma.thrift.authentication.AuthenticationToken) Row(com.datastax.driver.core.Row) Test(org.junit.Test)

Aggregations

AuthenticationToken (tech.aroma.thrift.authentication.AuthenticationToken)22 Test (org.junit.Test)14 BatchStatement (com.datastax.driver.core.BatchStatement)4 Row (com.datastax.driver.core.Row)4 Statement (com.datastax.driver.core.Statement)4 InvalidArgumentException (tech.aroma.thrift.exceptions.InvalidArgumentException)3 InvalidTokenException (tech.aroma.thrift.exceptions.InvalidTokenException)3 ResultSet (com.datastax.driver.core.ResultSet)2 TException (org.apache.thrift.TException)2 OperationFailedException (tech.aroma.thrift.exceptions.OperationFailedException)2 IntegrationTest (tech.sirwellington.alchemy.annotations.testing.IntegrationTest)2 StringAssertions.nonEmptyString (tech.sirwellington.alchemy.arguments.assertions.StringAssertions.nonEmptyString)2 StringGenerators.hexadecimalString (tech.sirwellington.alchemy.generator.StringGenerators.hexadecimalString)2 Cluster (com.datastax.driver.core.Cluster)1 Session (com.datastax.driver.core.Session)1 Map (java.util.Map)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Function (java.util.function.Function)1 Collectors.toSet (java.util.stream.Collectors.toSet)1