use of org.springframework.data.cassandra.domain.User in project spring-data-cassandra by spring-projects.
the class CdiRepositoryTests method testCdiRepository.
// DATACASS-149, DATACASS-495
@Test
void testCdiRepository() {
assertThat(repository).isNotNull();
repository.deleteAll();
User bean = new User();
bean.setId("username");
bean.setFirstname("first");
bean.setLastname("last");
repository.save(bean);
assertThat(repository.existsById(bean.getId())).isTrue();
Optional<User> retrieved = repository.findById(bean.getId());
assertThat(retrieved).hasValueSatisfying(actual -> {
assertThat(actual.getId()).isEqualTo(bean.getId());
assertThat(actual.getFirstname()).isEqualTo(bean.getFirstname());
assertThat(actual.getLastname()).isEqualTo(bean.getLastname());
});
assertThat(repository.count()).isEqualTo(1);
assertThat(repository.existsById(bean.getId())).isTrue();
repository.delete(bean);
assertThat(repository.count()).isEqualTo(0);
assertThat(repository.findById(bean.getId())).isNotPresent();
}
use of org.springframework.data.cassandra.domain.User in project spring-data-cassandra by spring-projects.
the class AsyncCassandraTemplateUnitTests method deleteByIdShouldRemoveEntity.
// DATACASS-292
@Test
void deleteByIdShouldRemoveEntity() {
when(resultSet.wasApplied()).thenReturn(true);
User user = new User("heisenberg", "Walter", "White");
ListenableFuture<Boolean> future = template.deleteById(user.getId(), User.class);
assertThat(getUninterruptibly(future)).isTrue();
verify(session).executeAsync(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 AsyncCassandraTemplateUnitTests method updateShouldUpdateEntity.
// DATACASS-292, DATACASS-618
@Test
void updateShouldUpdateEntity() {
when(resultSet.wasApplied()).thenReturn(true);
User user = new User("heisenberg", "Walter", "White");
ListenableFuture<User> future = template.update(user);
assertThat(getUninterruptibly(future)).isEqualTo(user);
verify(session).executeAsync(statementCaptor.capture());
assertThat(render(statementCaptor.getValue())).isEqualTo("UPDATE users SET firstname='Walter', lastname='White' WHERE id='heisenberg'");
assertThat(beforeConvert).isSameAs(user);
assertThat(beforeSave).isSameAs(user);
}
use of org.springframework.data.cassandra.domain.User in project spring-data-cassandra by spring-projects.
the class CassandraTemplateIntegrationTests method deleteByQueryShouldRemoveEntity.
// DATACASS-343
@Test
void deleteByQueryShouldRemoveEntity() {
User user = new User("heisenberg", "Walter", "White");
template.insert(user);
Query query = Query.query(where("id").is("heisenberg"));
assertThat(template.delete(query, User.class)).isTrue();
assertThat(template.selectOneById(user.getId(), User.class)).isNull();
}
use of org.springframework.data.cassandra.domain.User in project spring-data-cassandra by spring-projects.
the class CassandraTemplateIntegrationTests method insertShouldInsertEntity.
// DATACASS-292, DATACASS-573
@Test
void insertShouldInsertEntity() {
User user = new User("heisenberg", "Walter", "White");
assertThat(template.selectOneById(user.getId(), User.class)).isNull();
User result = template.insert(user);
assertThat(result).isSameAs(user);
assertThat(template.selectOneById(user.getId(), User.class)).isEqualTo(user);
}
Aggregations