Search in sources :

Example 21 with User

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

the class CassandraTemplateIntegrationTests method selectByQueryWithKeyspaceShouldRetrieveData.

// DATACASS-767
@Test
void selectByQueryWithKeyspaceShouldRetrieveData() {
    assumeThat(cassandraVersion.isGreaterThanOrEqualTo(CASSANDRA_4)).isTrue();
    QueryOptions queryOptions = QueryOptions.builder().keyspace(CqlIdentifier.fromCql(keyspace)).build();
    User user = new User("heisenberg", "Walter", "White");
    template.insert(user);
    Query query = Query.query(where("id").is("heisenberg")).queryOptions(queryOptions);
    assertThat(template.select(query, User.class)).isNotEmpty();
}
Also used : User(org.springframework.data.cassandra.domain.User) Query(org.springframework.data.cassandra.core.query.Query) QueryOptions(org.springframework.data.cassandra.core.cql.QueryOptions) Test(org.junit.jupiter.api.Test)

Example 22 with User

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

the class CassandraTemplateIntegrationTests method shouldNotOverrideLaterMutation.

// DATACASS-155
@Test
void shouldNotOverrideLaterMutation() {
    Instant now = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant();
    User user = new User("heisenberg", "Walter", "White");
    template.insert(user);
    // more recent mutation
    user.setFirstname("John");
    template.update(user);
    // previous mutation
    user.setFirstname("Greg");
    template.update(user, UpdateOptions.builder().timestamp(now.minusSeconds(120)).build());
    User loaded = template.selectOneById(user.getId(), User.class);
    assertThat(loaded.getFirstname()).isEqualTo("John");
}
Also used : User(org.springframework.data.cassandra.domain.User) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test)

Example 23 with User

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

the class CassandraTemplateIntegrationTests method insertShouldNotRemoveFields.

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

Example 24 with User

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

the class CassandraTemplateUnitTests method deleteByIdShouldRemoveEntity.

// DATACASS-292
@Test
void deleteByIdShouldRemoveEntity() {
    when(resultSet.wasApplied()).thenReturn(true);
    User user = new User("heisenberg", "Walter", "White");
    boolean deleted = template.deleteById(user.getId(), User.class);
    assertThat(deleted).isTrue();
    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) Test(org.junit.jupiter.api.Test)

Example 25 with User

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

the class CassandraTemplateUnitTests method selectUsingCqlShouldReturnMappedResults.

// DATACASS-292
@Test
void selectUsingCqlShouldReturnMappedResults() {
    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.TEXT);
    when(row.getObject(0)).thenReturn("myid");
    when(row.getObject(1)).thenReturn("Walter");
    when(row.getObject(2)).thenReturn("White");
    List<User> list = template.select("SELECT * FROM users", User.class);
    assertThat(list).hasSize(1).contains(new User("myid", "Walter", "White"));
    verify(session).execute(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) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) 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