Search in sources :

Example 26 with User

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

the class AsyncCassandraTemplateIntegrationTests method shouldInsertEntityAndExistsByQuery.

// DATACASS-512
@Test
void shouldInsertEntityAndExistsByQuery() {
    User user = new User("heisenberg", "Walter", "White");
    getUninterruptibly(template.insert(user));
    assertThat(getUninterruptibly(template.exists(Query.query(where("id").is("heisenberg")), User.class))).isTrue();
    assertThat(getUninterruptibly(template.exists(Query.query(where("id").is("foo")), User.class))).isFalse();
}
Also used : User(org.springframework.data.cassandra.domain.User) Test(org.junit.jupiter.api.Test)

Example 27 with User

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

the class CassandraTemplateIntegrationTests method updateShouldRemoveFields.

// DATACASS-182
@Test
void updateShouldRemoveFields() {
    User user = new User("heisenberg", "Walter", "White");
    template.insert(user);
    user.setFirstname(null);
    template.update(user);
    User loaded = template.selectOneById(user.getId(), User.class);
    assertThat(loaded.getFirstname()).isNull();
    assertThat(loaded.getId()).isEqualTo("heisenberg");
}
Also used : User(org.springframework.data.cassandra.domain.User) Test(org.junit.jupiter.api.Test)

Example 28 with User

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

the class CassandraTemplateIntegrationTests method stream.

// DATACASS-182
@Test
void stream() {
    User user = new User("heisenberg", "Walter", "White");
    template.insert(user);
    Stream<User> stream = template.stream("SELECT * FROM users", User.class);
    assertThat(stream.collect(Collectors.toList())).hasSize(1).contains(user);
}
Also used : User(org.springframework.data.cassandra.domain.User) Test(org.junit.jupiter.api.Test)

Example 29 with User

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

the class CassandraTemplateIntegrationTests method updateShouldUpdateEntityWithLwt.

// DATACASS-292
@Test
void updateShouldUpdateEntityWithLwt() {
    UpdateOptions lwtOptions = UpdateOptions.builder().withIfExists().build();
    User user = new User("heisenberg", "Walter", "White");
    template.insert(user);
    user.setFirstname("Walter Hartwell");
    WriteResult lwt = template.update(user, lwtOptions);
    assertThat(lwt.wasApplied()).isTrue();
}
Also used : User(org.springframework.data.cassandra.domain.User) Test(org.junit.jupiter.api.Test)

Example 30 with User

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

the class CassandraTemplateIntegrationTests method insertShouldNotUpdateEntityWithLwt.

// DATACASS-250, DATACASS-573
@Test
void insertShouldNotUpdateEntityWithLwt() {
    InsertOptions lwtOptions = InsertOptions.builder().withIfNotExists().build();
    User user = new User("heisenberg", "Walter", "White");
    template.insert(user, lwtOptions);
    user.setFirstname("Walter Hartwell");
    EntityWriteResult<User> lwt = template.insert(user, lwtOptions);
    assertThat(lwt.wasApplied()).isFalse();
    assertThat(template.selectOneById(user.getId(), User.class).getFirstname()).isEqualTo("Walter");
}
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