Search in sources :

Example 11 with User

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

the class ReactiveCassandraTemplateUnitTests method updateShouldUpdateEntityWithLwt.

// DATACASS-575
@Test
void updateShouldUpdateEntityWithLwt() {
    when(reactiveResultSet.rows()).thenReturn(Flux.just(row));
    UpdateOptions options = UpdateOptions.builder().ifCondition(where("firstname").is("Walter")).build();
    User user = new User("heisenberg", "Walter", "White");
    // 
    template.update(user, options).as(// 
    StepVerifier::create).expectNextCount(// 
    1).verifyComplete();
    verify(session).execute(statementCaptor.capture());
    assertThat(render(statementCaptor.getValue())).isEqualTo("UPDATE users SET firstname='Walter', lastname='White' WHERE id='heisenberg' IF firstname='Walter'");
}
Also used : VersionedUser(org.springframework.data.cassandra.domain.VersionedUser) User(org.springframework.data.cassandra.domain.User) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 12 with User

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

the class ReactiveCassandraTemplateIntegrationTests method deleteByQueryShouldRemoveEntityWithLwt.

// DATACASS-606
@Test
void deleteByQueryShouldRemoveEntityWithLwt() {
    DeleteOptions lwtOptions = DeleteOptions.builder().withIfExists().build();
    User user = new User("heisenberg", "Walter", "White");
    template.insert(user).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    Query query = Query.query(where("id").is("heisenberg")).queryOptions(lwtOptions);
    // 
    template.delete(query, User.class).as(// 
    StepVerifier::create).expectNext(// 
    true).verifyComplete();
    // 
    template.delete(query, User.class).as(// 
    StepVerifier::create).expectNext(// 
    false).verifyComplete();
}
Also used : User(org.springframework.data.cassandra.domain.User) Query(org.springframework.data.cassandra.core.query.Query) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 13 with User

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

the class ReactiveCassandraTemplateUnitTests method deleteShouldRemoveEntity.

// DATACASS-335
@Test
void deleteShouldRemoveEntity() {
    when(reactiveResultSet.wasApplied()).thenReturn(true);
    when(reactiveResultSet.rows()).thenReturn(Flux.just(row));
    User user = new User("heisenberg", "Walter", "White");
    template.delete(user).as(StepVerifier::create).expectNext(user).verifyComplete();
    verify(session).execute(statementCaptor.capture());
    assertThat(render(statementCaptor.getValue())).isEqualTo("DELETE FROM users WHERE id='heisenberg'");
}
Also used : VersionedUser(org.springframework.data.cassandra.domain.VersionedUser) User(org.springframework.data.cassandra.domain.User) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 14 with User

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

the class ReactiveCassandraTemplateUnitTests method updateShouldUpdateEntityWithOptions.

// DATACASS-575
@Test
void updateShouldUpdateEntityWithOptions() {
    when(reactiveResultSet.rows()).thenReturn(Flux.just(row));
    UpdateOptions updateOptions = UpdateOptions.builder().withIfExists().build();
    User user = new User("heisenberg", "Walter", "White");
    // 
    template.update(user, updateOptions).as(// 
    StepVerifier::create).expectNextCount(// 
    1).verifyComplete();
    verify(session).execute(statementCaptor.capture());
    assertThat(render(statementCaptor.getValue())).isEqualTo("UPDATE users SET firstname='Walter', lastname='White' WHERE id='heisenberg' IF EXISTS");
}
Also used : VersionedUser(org.springframework.data.cassandra.domain.VersionedUser) User(org.springframework.data.cassandra.domain.User) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 15 with User

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

the class ReactiveCassandraRepositoryIntegrationTests 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);
    }
    factory = new ReactiveCassandraRepositoryFactory(operations);
    factory.setRepositoryBaseClass(SimpleReactiveCassandraRepository.class);
    factory.setBeanClassLoader(classLoader);
    factory.setBeanFactory(beanFactory);
    repository = factory.getRepository(UserRepository.class);
    groupRepostitory = factory.getRepository(GroupRepository.class);
    repository.deleteAll().concatWith(groupRepostitory.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");
    repository.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) IncorrectResultSizeDataAccessException(org.springframework.dao.IncorrectResultSizeDataAccessException) StepVerifier(reactor.test.StepVerifier) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) ReactiveCassandraRepositoryFactory(org.springframework.data.cassandra.repository.support.ReactiveCassandraRepositoryFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleReactiveCassandraRepository(org.springframework.data.cassandra.repository.support.SimpleReactiveCassandraRepository) HashSet(java.util.HashSet) SpringJUnitConfig(org.springframework.test.context.junit.jupiter.SpringJUnitConfig) User(org.springframework.data.cassandra.domain.User) CqlSession(com.datastax.oss.driver.api.core.CqlSession) BeanFactoryAware(org.springframework.beans.factory.BeanFactoryAware) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) Publisher(org.reactivestreams.Publisher) GroupKey(org.springframework.data.cassandra.domain.GroupKey) Set(java.util.Set) Mono(reactor.core.publisher.Mono) BeansException(org.springframework.beans.BeansException) Slice(org.springframework.data.domain.Slice) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) Flux(reactor.core.publisher.Flux) Group(org.springframework.data.cassandra.domain.Group) Streamable(org.springframework.data.util.Streamable) BeanFactory(org.springframework.beans.factory.BeanFactory) BeanClassLoaderAware(org.springframework.beans.factory.BeanClassLoaderAware) ReactiveCassandraOperations(org.springframework.data.cassandra.core.ReactiveCassandraOperations) CassandraPageRequest(org.springframework.data.cassandra.core.query.CassandraPageRequest) IntegrationTestConfig(org.springframework.data.cassandra.repository.support.IntegrationTestConfig) User(org.springframework.data.cassandra.domain.User) ReactiveCassandraRepositoryFactory(org.springframework.data.cassandra.repository.support.ReactiveCassandraRepositoryFactory) StepVerifier(reactor.test.StepVerifier) BeforeEach(org.junit.jupiter.api.BeforeEach)

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