Search in sources :

Example 1 with Message

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

the class CassandraMessageRepositoryIT method testGetByTitle.

@Test
public void testGetByTitle() throws Exception {
    String title = one(alphabeticString());
    List<Message> expected = messages.stream().map(m -> m.setTitle(title)).collect(toList());
    saveMessages(expected);
    List<Message> result = instance.getByTitle(appId, title);
    assertThat(result, notNullValue());
    assertThat(result, not(empty()));
    assertThat(containTheSameElements(result, expected), is(true));
}
Also used : UUIDs(com.datastax.driver.core.utils.UUIDs) LengthOfTime(tech.aroma.thrift.LengthOfTime) BeforeClass(org.junit.BeforeClass) Row(com.datastax.driver.core.Row) RunWith(org.junit.runner.RunWith) Matchers.not(org.hamcrest.Matchers.not) AlchemyTestRunner(tech.sirwellington.alchemy.test.junit.runners.AlchemyTestRunner) TimeUnit(tech.aroma.thrift.TimeUnit) Function(java.util.function.Function) TimeSensitive(tech.sirwellington.alchemy.annotations.testing.TimeSensitive) UUID(tech.sirwellington.alchemy.test.junit.runners.GenerateString.Type.UUID) Assert.assertThat(org.junit.Assert.assertThat) Repeat(tech.sirwellington.alchemy.test.junit.runners.Repeat) MessageGenerators.messages(tech.aroma.thrift.generators.MessageGenerators.messages) Session(com.datastax.driver.core.Session) After(org.junit.After) IntegrationTest(tech.sirwellington.alchemy.annotations.testing.IntegrationTest) GenerateList(tech.sirwellington.alchemy.test.junit.runners.GenerateList) Before(org.junit.Before) Sets.containTheSameElements(sir.wellington.alchemy.collections.sets.Sets.containTheSameElements) Sets(sir.wellington.alchemy.collections.sets.Sets) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) StringGenerators.alphabeticString(tech.sirwellington.alchemy.generator.StringGenerators.alphabeticString) Set(java.util.Set) TException(org.apache.thrift.TException) Test(org.junit.Test) AlchemyGenerator.one(tech.sirwellington.alchemy.generator.AlchemyGenerator.one) DontRepeat(tech.sirwellington.alchemy.test.junit.runners.DontRepeat) List(java.util.List) AlchemyGenerator(tech.sirwellington.alchemy.generator.AlchemyGenerator) Collectors.toList(java.util.stream.Collectors.toList) Matchers.contains(org.hamcrest.Matchers.contains) GenerateString(tech.sirwellington.alchemy.test.junit.runners.GenerateString) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) Message(tech.aroma.thrift.Message) Message(tech.aroma.thrift.Message) StringGenerators.alphabeticString(tech.sirwellington.alchemy.generator.StringGenerators.alphabeticString) GenerateString(tech.sirwellington.alchemy.test.junit.runners.GenerateString) IntegrationTest(tech.sirwellington.alchemy.annotations.testing.IntegrationTest) Test(org.junit.Test)

Example 2 with Message

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

the class CassandraInboxRepositoryTest method testGetMessagesForUser.

@Test
public void testGetMessagesForUser() throws Exception {
    List<Message> result = instance.getMessagesForUser(userId);
    assertThat(result, notNullValue());
    assertThat(result, not(empty()));
    assertThat(result, contains(message));
    verify(cassandra).execute(captor.capture());
    Statement statement = captor.getValue();
    assertThat(statement, notNullValue());
    assertThat(statement, is(instanceOf(Select.class)));
}
Also used : Message(tech.aroma.thrift.Message) Statement(com.datastax.driver.core.Statement) Test(org.junit.Test)

Example 3 with Message

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

the class CassandraInboxRepositoryTest method testSaveMessageForUserWithBadArgs.

@DontRepeat
@Test
public void testSaveMessageForUserWithBadArgs() throws Exception {
    User userWithBadId = new User(user).setUserId(badId);
    assertThrows(() -> instance.saveMessageForUser(userWithBadId, message, lifetime)).isInstanceOf(InvalidArgumentException.class);
    Message messageWithBadId = new Message(message).setMessageId(badId);
    assertThrows(() -> instance.saveMessageForUser(user, messageWithBadId, lifetime)).isInstanceOf(InvalidArgumentException.class);
    Message messageWithBadAppId = new Message(message).setApplicationId(badId);
    assertThrows(() -> instance.saveMessageForUser(user, messageWithBadAppId, lifetime)).isInstanceOf(InvalidArgumentException.class);
}
Also used : User(tech.aroma.thrift.User) Message(tech.aroma.thrift.Message) Test(org.junit.Test) DontRepeat(tech.sirwellington.alchemy.test.junit.runners.DontRepeat)

Example 4 with Message

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

the class CassandraMessageRepositoryTest method testSaveMessageWithBadArgs.

@Test
public void testSaveMessageWithBadArgs() throws Exception {
    assertThrows(() -> instance.saveMessage(null, lifetime)).isInstanceOf(InvalidArgumentException.class);
    assertThrows(() -> instance.saveMessage(message, null)).isInstanceOf(InvalidArgumentException.class);
    Message emptyMessage = new Message();
    assertThrows(() -> instance.saveMessage(emptyMessage, lifetime)).isInstanceOf(InvalidArgumentException.class);
    Message messageWithBadId = new Message(message).setMessageId(badId);
    assertThrows(() -> instance.saveMessage(messageWithBadId)).isInstanceOf(InvalidArgumentException.class);
}
Also used : Message(tech.aroma.thrift.Message) Test(org.junit.Test)

Example 5 with Message

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

the class CassandraMessageRepositoryTest method testGetMessage.

@Test
public void testGetMessage() throws Exception {
    Message result = instance.getMessage(appId, messageId);
    assertThat(result, is(message));
    verify(cassandra).execute(captor.capture());
    Statement statement = captor.getValue();
    assertThat(statement, notNullValue());
    assertThat(statement, instanceOf(Select.class));
}
Also used : Message(tech.aroma.thrift.Message) Statement(com.datastax.driver.core.Statement) Select(com.datastax.driver.core.querybuilder.Select) Test(org.junit.Test)

Aggregations

Message (tech.aroma.thrift.Message)22 Test (org.junit.Test)12 Statement (com.datastax.driver.core.Statement)8 Row (com.datastax.driver.core.Row)7 ResultSet (com.datastax.driver.core.ResultSet)6 RequestAssertions.validMessage (tech.aroma.data.assertions.RequestAssertions.validMessage)5 InvalidArgumentException (tech.aroma.thrift.exceptions.InvalidArgumentException)5 DontRepeat (tech.sirwellington.alchemy.test.junit.runners.DontRepeat)5 TException (org.apache.thrift.TException)3 User (tech.aroma.thrift.User)3 Session (com.datastax.driver.core.Session)2 List (java.util.List)2 Function (java.util.function.Function)2 LengthOfTime (tech.aroma.thrift.LengthOfTime)2 OperationFailedException (tech.aroma.thrift.exceptions.OperationFailedException)2 IntegrationTest (tech.sirwellington.alchemy.annotations.testing.IntegrationTest)2 QueryBuilder (com.datastax.driver.core.querybuilder.QueryBuilder)1 QueryBuilder.desc (com.datastax.driver.core.querybuilder.QueryBuilder.desc)1 QueryBuilder.eq (com.datastax.driver.core.querybuilder.QueryBuilder.eq)1 QueryBuilder.ttl (com.datastax.driver.core.querybuilder.QueryBuilder.ttl)1