Search in sources :

Example 1 with AlchemyGenerator

use of tech.sirwellington.alchemy.generator.AlchemyGenerator 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

BatchStatement (com.datastax.driver.core.BatchStatement)1 Cluster (com.datastax.driver.core.Cluster)1 ResultSet (com.datastax.driver.core.ResultSet)1 Row (com.datastax.driver.core.Row)1 Session (com.datastax.driver.core.Session)1 Statement (com.datastax.driver.core.Statement)1 Map (java.util.Map)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 TException (org.apache.thrift.TException)1 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)1 Matchers.is (org.hamcrest.Matchers.is)1 Matchers.notNullValue (org.hamcrest.Matchers.notNullValue)1 Assert.assertThat (org.junit.Assert.assertThat)1 Before (org.junit.Before)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1 RETURNS_MOCKS (org.mockito.Answers.RETURNS_MOCKS)1 ArgumentCaptor (org.mockito.ArgumentCaptor)1