Search in sources :

Example 36 with User

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

the class CassandraTemplateIntegrationTests method updateShouldUpdateEntityByQuery.

// DATACASS-343
@Test
void updateShouldUpdateEntityByQuery() {
    User person = new User("heisenberg", "Walter", "White");
    template.insert(person);
    Query query = Query.query(where("id").is("heisenberg"));
    boolean result = template.update(query, Update.empty().set("firstname", "Walter Hartwell"), User.class);
    assertThat(result).isTrue();
    assertThat(template.selectOneById(person.getId(), User.class).getFirstname()).isEqualTo("Walter Hartwell");
}
Also used : User(org.springframework.data.cassandra.domain.User) Query(org.springframework.data.cassandra.core.query.Query) Test(org.junit.jupiter.api.Test)

Example 37 with User

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

the class CassandraTemplateUnitTests method insertShouldNotApplyInsert.

// DATACASS-292
@Test
void insertShouldNotApplyInsert() {
    when(resultSet.wasApplied()).thenReturn(false);
    User user = new User("heisenberg", "Walter", "White");
    WriteResult writeResult = template.insert(user, InsertOptions.builder().build());
    assertThat(writeResult.wasApplied()).isFalse();
}
Also used : VersionedUser(org.springframework.data.cassandra.domain.VersionedUser) User(org.springframework.data.cassandra.domain.User) Test(org.junit.jupiter.api.Test)

Example 38 with User

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

the class CassandraTemplateUnitTests method selectOneByIdShouldReturnMappedResults.

// DATACASS-292
@Test
void selectOneByIdShouldReturnMappedResults() {
    when(resultSet.iterator()).thenReturn(Collections.singleton(row).iterator());
    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.ASCII);
    when(row.getObject(0)).thenReturn("myid");
    when(row.getObject(1)).thenReturn("Walter");
    when(row.getObject(2)).thenReturn("White");
    User user = template.selectOneById("myid", User.class);
    assertThat(user).isEqualTo(new User("myid", "Walter", "White"));
    verify(session).execute(statementCaptor.capture());
    assertThat(render(statementCaptor.getValue())).isEqualTo("SELECT * FROM users WHERE id='myid' LIMIT 1");
}
Also used : VersionedUser(org.springframework.data.cassandra.domain.VersionedUser) User(org.springframework.data.cassandra.domain.User) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) Test(org.junit.jupiter.api.Test)

Example 39 with User

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

the class AsyncCassandraTemplateIntegrationTests method insertShouldNotUpdateEntityWithLwt.

// DATACASS-250
@Test
void insertShouldNotUpdateEntityWithLwt() {
    InsertOptions lwtOptions = InsertOptions.builder().withIfNotExists().build();
    User user = new User("heisenberg", "Walter", "White");
    getUninterruptibly(template.insert(user, lwtOptions));
    user.setFirstname("Walter Hartwell");
    ListenableFuture<EntityWriteResult<User>> lwt = template.insert(user, lwtOptions);
    assertThat(getUninterruptibly(lwt).wasApplied()).isFalse();
    assertThat(getUser(user.getId()).getFirstname()).isEqualTo("Walter");
}
Also used : User(org.springframework.data.cassandra.domain.User) Test(org.junit.jupiter.api.Test)

Example 40 with User

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

the class AsyncCassandraTemplateIntegrationTests method deleteColumnsByQueryShouldRemoveColumn.

// DATACASS-343
@Test
void deleteColumnsByQueryShouldRemoveColumn() {
    User user = new User("heisenberg", "Walter", "White");
    getUninterruptibly(template.insert(user));
    Query query = Query.query(where("id").is("heisenberg")).columns(Columns.from("lastname"));
    assertThat(getUninterruptibly(template.delete(query, User.class))).isTrue();
    User loaded = getUser(user.getId());
    assertThat(loaded.getFirstname()).isEqualTo("Walter");
    assertThat(loaded.getLastname()).isNull();
}
Also used : User(org.springframework.data.cassandra.domain.User) Query(org.springframework.data.cassandra.core.query.Query) 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