Search in sources :

Example 1 with User

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

the class ReactiveCassandraTemplateIntegrationTests method insertShouldCreateEntityWithLwt.

// DATACASS-250, DATACASS-573
@Test
void insertShouldCreateEntityWithLwt() {
    InsertOptions lwtOptions = InsertOptions.builder().withIfNotExists().build();
    User user = new User("heisenberg", "Walter", "White");
    Mono<EntityWriteResult<User>> inserted = template.insert(user, lwtOptions);
    inserted.as(StepVerifier::create).consumeNextWith(actual -> {
        assertThat(actual.wasApplied()).isTrue();
        assertThat(actual.getEntity()).isSameAs(user);
    }).verifyComplete();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) DefaultBridgedReactiveSession(org.springframework.data.cassandra.core.cql.session.DefaultBridgedReactiveSession) Criteria(org.springframework.data.cassandra.core.query.Criteria) StepVerifier(reactor.test.StepVerifier) Update(org.springframework.data.cassandra.core.query.Update) SchemaTestUtils(org.springframework.data.cassandra.repository.support.SchemaTestUtils) Mono(reactor.core.publisher.Mono) Query(org.springframework.data.cassandra.core.query.Query) AbstractKeyspaceCreatingIntegrationTests(org.springframework.data.cassandra.test.util.AbstractKeyspaceCreatingIntegrationTests) Slice(org.springframework.data.domain.Slice) Test(org.junit.jupiter.api.Test) User(org.springframework.data.cassandra.domain.User) Uuids(com.datastax.oss.driver.api.core.uuid.Uuids) ReactiveCqlTemplate(org.springframework.data.cassandra.core.cql.ReactiveCqlTemplate) Assertions(org.assertj.core.api.Assertions) UserToken(org.springframework.data.cassandra.domain.UserToken) Sort(org.springframework.data.domain.Sort) MappingCassandraConverter(org.springframework.data.cassandra.core.convert.MappingCassandraConverter) CassandraPageRequest(org.springframework.data.cassandra.core.query.CassandraPageRequest) FirstStep(reactor.test.StepVerifier.FirstStep) Columns(org.springframework.data.cassandra.core.query.Columns) User(org.springframework.data.cassandra.domain.User) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 2 with User

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

the class ReactiveCassandraTemplateIntegrationTests method shouldInsertEntityAndCountByQuery.

// DATACASS-335
@Test
void shouldInsertEntityAndCountByQuery() {
    User user = new User("heisenberg", "Walter", "White");
    template.insert(user).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    // 
    template.count(Query.query(where("id").is("heisenberg")), User.class).as(StepVerifier::create).expectNext(// 
    1L).verifyComplete();
    // 
    template.count(Query.query(where("id").is("foo")), User.class).as(StepVerifier::create).expectNext(// 
    0L).verifyComplete();
}
Also used : User(org.springframework.data.cassandra.domain.User) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 3 with User

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

the class ReactiveCassandraTemplateIntegrationTests method shouldInsertAndExistsByQueryEntities.

// DATACASS-335
@Test
void shouldInsertAndExistsByQueryEntities() {
    User user = new User("heisenberg", "Walter", "White");
    template.insert(user).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    // 
    template.exists(Query.query(where("id").is("heisenberg")), User.class).as(StepVerifier::create).expectNext(// 
    true).verifyComplete();
    // 
    template.exists(Query.query(where("id").is("foo")), User.class).as(StepVerifier::create).expectNext(// 
    false).verifyComplete();
}
Also used : User(org.springframework.data.cassandra.domain.User) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 4 with User

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

the class ReactiveCassandraTemplateIntegrationTests method updateShouldUpdateEntity.

// DATACASS-335
@Test
void updateShouldUpdateEntity() {
    User user = new User("heisenberg", "Walter", "White");
    template.insert(user).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    user.setFirstname("Walter Hartwell");
    template.insert(user).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    verifyUser(user.getId()).expectNext(user).verifyComplete();
}
Also used : User(org.springframework.data.cassandra.domain.User) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 5 with User

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

the class ReactiveCassandraTemplateIntegrationTests method deleteShouldRemoveEntity.

// DATACASS-335
@Test
void deleteShouldRemoveEntity() {
    User user = new User("heisenberg", "Walter", "White");
    template.insert(user).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    template.delete(user).as(StepVerifier::create).expectNext(user).verifyComplete();
    verifyUser(user.getId()).verifyComplete();
}
Also used : User(org.springframework.data.cassandra.domain.User) StepVerifier(reactor.test.StepVerifier) 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