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();
}
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");
}
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");
}
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'");
}
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");
}
Aggregations