Search in sources :

Example 96 with User

use of org.springframework.data.cassandra.domain.User in project spring-data-cassandra by spring-projects.

the class CassandraTemplateUnitTests method insertShouldInsertWithOptionsEntity.

// DATACASS-250
@Test
void insertShouldInsertWithOptionsEntity() {
    InsertOptions insertOptions = InsertOptions.builder().withIfNotExists().build();
    when(resultSet.wasApplied()).thenReturn(true);
    User user = new User("heisenberg", "Walter", "White");
    template.insert(user, insertOptions);
    verify(session).execute(statementCaptor.capture());
    assertThat(render(statementCaptor.getValue())).isEqualTo("INSERT INTO users (firstname,id,lastname) VALUES ('Walter','heisenberg','White') IF NOT EXISTS");
}
Also used : VersionedUser(org.springframework.data.cassandra.domain.VersionedUser) User(org.springframework.data.cassandra.domain.User) Test(org.junit.jupiter.api.Test)

Example 97 with User

use of org.springframework.data.cassandra.domain.User in project spring-data-cassandra by spring-projects.

the class AsyncCassandraTemplateUnitTests method selectUsingCqlShouldReturnMappedResults.

// DATACASS-292
@Test
void selectUsingCqlShouldReturnMappedResults() {
    when(resultSet.currentPage()).thenReturn(Collections.singleton(row));
    when(columnDefinitions.contains(any(CqlIdentifier.class))).thenReturn(true);
    when(columnDefinitions.get(anyInt())).thenReturn(columnDefinition);
    when(columnDefinitions.firstIndexOf("id")).thenReturn(0);
    when(columnDefinitions.firstIndexOf("firstname")).thenReturn(1);
    when(columnDefinitions.firstIndexOf("lastname")).thenReturn(2);
    when(columnDefinition.getType()).thenReturn(DataTypes.TEXT);
    when(row.getObject(0)).thenReturn("myid");
    when(row.getObject(1)).thenReturn("Walter");
    when(row.getObject(2)).thenReturn("White");
    ListenableFuture<List<User>> list = template.select("SELECT * FROM users", User.class);
    assertThat(getUninterruptibly(list)).hasSize(1).contains(new User("myid", "Walter", "White"));
    verify(session).executeAsync(statementCaptor.capture());
    assertThat(render(statementCaptor.getValue())).isEqualTo("SELECT * FROM users");
}
Also used : VersionedUser(org.springframework.data.cassandra.domain.VersionedUser) User(org.springframework.data.cassandra.domain.User) ArrayList(java.util.ArrayList) List(java.util.List) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) Test(org.junit.jupiter.api.Test)

Example 98 with User

use of org.springframework.data.cassandra.domain.User in project spring-data-cassandra by spring-projects.

the class ConvertingReactiveCassandraRepositoryTests method setUp.

@BeforeEach
void setUp() throws Exception {
    TableMetadata users = session.getKeyspace().flatMap(it -> session.getMetadata().getKeyspace(it)).flatMap(it -> it.getTable(CqlIdentifier.fromCql("users"))).get();
    if (users.getIndexes().containsKey(CqlIdentifier.fromCql("IX_lastname"))) {
        session.execute("CREATE INDEX IX_lastname ON users (lastname);");
        Thread.sleep(500);
    }
    reactiveRepository.deleteAll().as(StepVerifier::create).verifyComplete();
    dave = new User("42", "Dave", "Matthews");
    oliver = new User("4", "Oliver August", "Matthews");
    carter = new User("49", "Carter", "Beauford");
    boyd = new User("45", "Boyd", "Tinsley");
    reactiveRepository.saveAll(Arrays.asList(oliver, dave, carter, boyd)).as(StepVerifier::create).expectNextCount(4).verifyComplete();
}
Also used : TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) AbstractSpringDataEmbeddedCassandraIntegrationTest(org.springframework.data.cassandra.repository.support.AbstractSpringDataEmbeddedCassandraIntegrationTest) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) Maybe(io.reactivex.Maybe) Autowired(org.springframework.beans.factory.annotation.Autowired) Observable(rx.Observable) SpringJUnitConfig(org.springframework.test.context.junit.jupiter.SpringJUnitConfig) Single(rx.Single) User(org.springframework.data.cassandra.domain.User) Flowable(io.reactivex.Flowable) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Assertions(org.assertj.core.api.Assertions) Repository(org.springframework.stereotype.Repository) RxJava2CrudRepository(org.springframework.data.repository.reactive.RxJava2CrudRepository) TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) Publisher(org.reactivestreams.Publisher) Mono(reactor.core.publisher.Mono) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) Flux(reactor.core.publisher.Flux) Filter(org.springframework.context.annotation.ComponentScan.Filter) List(java.util.List) ReactiveCrudRepository(org.springframework.data.repository.reactive.ReactiveCrudRepository) EnableReactiveCassandraRepositories(org.springframework.data.cassandra.repository.config.EnableReactiveCassandraRepositories) IntegrationTestConfig(org.springframework.data.cassandra.repository.support.IntegrationTestConfig) User(org.springframework.data.cassandra.domain.User) StepVerifier(reactor.test.StepVerifier) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 99 with User

use of org.springframework.data.cassandra.domain.User in project spring-data-cassandra by spring-projects.

the class SimpleReactiveCassandraRepositoryIntegrationTests method insertShouldDeferredWrite.

// DATACASS-335
@Test
void insertShouldDeferredWrite() {
    User person = new User("36", "Homer", "Simpson");
    repository.insert(person);
    repository.findAll().as(StepVerifier::create).expectNextCount(0L).verifyComplete();
}
Also used : User(org.springframework.data.cassandra.domain.User) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 100 with User

use of org.springframework.data.cassandra.domain.User in project spring-data-cassandra by spring-projects.

the class SimpleCassandraRepositoryIntegrationTests method insertEntityShouldInsertEntity.

// DATACASS-415
@Test
void insertEntityShouldInsertEntity() {
    repository.deleteAll();
    User User = new User("36", "Homer", "Simpson");
    repository.insert(User);
    assertThat(repository.count()).isEqualTo(1);
}
Also used : User(org.springframework.data.cassandra.domain.User) Test(org.junit.jupiter.api.Test)

Aggregations

User (org.springframework.data.cassandra.domain.User)116 Test (org.junit.jupiter.api.Test)113 VersionedUser (org.springframework.data.cassandra.domain.VersionedUser)36 StepVerifier (reactor.test.StepVerifier)27 Query (org.springframework.data.cassandra.core.query.Query)22 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)9 BeforeEach (org.junit.jupiter.api.BeforeEach)9 NoNodeAvailableException (com.datastax.oss.driver.api.core.NoNodeAvailableException)6 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)6 Statement (com.datastax.oss.driver.api.core.cql.Statement)6 Uuids (com.datastax.oss.driver.api.core.uuid.Uuids)6 Mono (reactor.core.publisher.Mono)6 Assertions (org.assertj.core.api.Assertions)5 CassandraPageRequest (org.springframework.data.cassandra.core.query.CassandraPageRequest)5 Slice (org.springframework.data.domain.Slice)5 Sort (org.springframework.data.domain.Sort)5 MappingCassandraConverter (org.springframework.data.cassandra.core.convert.MappingCassandraConverter)4 ReactiveCqlTemplate (org.springframework.data.cassandra.core.cql.ReactiveCqlTemplate)4 DefaultBridgedReactiveSession (org.springframework.data.cassandra.core.cql.session.DefaultBridgedReactiveSession)4 Columns (org.springframework.data.cassandra.core.query.Columns)4