use of org.springframework.data.cassandra.domain.User in project spring-data-cassandra by spring-projects.
the class ReactiveCassandraTemplateUnitTests method updateShouldUpdateEntityWithLwt.
// DATACASS-575
@Test
void updateShouldUpdateEntityWithLwt() {
when(reactiveResultSet.rows()).thenReturn(Flux.just(row));
UpdateOptions options = UpdateOptions.builder().ifCondition(where("firstname").is("Walter")).build();
User user = new User("heisenberg", "Walter", "White");
//
template.update(user, options).as(//
StepVerifier::create).expectNextCount(//
1).verifyComplete();
verify(session).execute(statementCaptor.capture());
assertThat(render(statementCaptor.getValue())).isEqualTo("UPDATE users SET firstname='Walter', lastname='White' WHERE id='heisenberg' IF firstname='Walter'");
}
use of org.springframework.data.cassandra.domain.User in project spring-data-cassandra by spring-projects.
the class ReactiveCassandraTemplateIntegrationTests method deleteByQueryShouldRemoveEntityWithLwt.
// DATACASS-606
@Test
void deleteByQueryShouldRemoveEntityWithLwt() {
DeleteOptions lwtOptions = DeleteOptions.builder().withIfExists().build();
User user = new User("heisenberg", "Walter", "White");
template.insert(user).as(StepVerifier::create).expectNextCount(1).verifyComplete();
Query query = Query.query(where("id").is("heisenberg")).queryOptions(lwtOptions);
//
template.delete(query, User.class).as(//
StepVerifier::create).expectNext(//
true).verifyComplete();
//
template.delete(query, User.class).as(//
StepVerifier::create).expectNext(//
false).verifyComplete();
}
use of org.springframework.data.cassandra.domain.User in project spring-data-cassandra by spring-projects.
the class ReactiveCassandraTemplateUnitTests method deleteShouldRemoveEntity.
// DATACASS-335
@Test
void deleteShouldRemoveEntity() {
when(reactiveResultSet.wasApplied()).thenReturn(true);
when(reactiveResultSet.rows()).thenReturn(Flux.just(row));
User user = new User("heisenberg", "Walter", "White");
template.delete(user).as(StepVerifier::create).expectNext(user).verifyComplete();
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 ReactiveCassandraTemplateUnitTests method updateShouldUpdateEntityWithOptions.
// DATACASS-575
@Test
void updateShouldUpdateEntityWithOptions() {
when(reactiveResultSet.rows()).thenReturn(Flux.just(row));
UpdateOptions updateOptions = UpdateOptions.builder().withIfExists().build();
User user = new User("heisenberg", "Walter", "White");
//
template.update(user, updateOptions).as(//
StepVerifier::create).expectNextCount(//
1).verifyComplete();
verify(session).execute(statementCaptor.capture());
assertThat(render(statementCaptor.getValue())).isEqualTo("UPDATE users SET firstname='Walter', lastname='White' WHERE id='heisenberg' IF EXISTS");
}
use of org.springframework.data.cassandra.domain.User in project spring-data-cassandra by spring-projects.
the class ReactiveCassandraRepositoryIntegrationTests method setUp.
@BeforeEach
void setUp() throws Exception {
TableMetadata users = session.getKeyspace().flatMap(it -> session.getMetadata().getKeyspace(it)).flatMap(it -> it.getTable(CqlIdentifier.fromCql("users"))).get();
if (!users.getIndexes().containsKey(CqlIdentifier.fromCql("IX_lastname"))) {
session.execute("CREATE INDEX IX_lastname ON users (lastname);");
Thread.sleep(500);
}
factory = new ReactiveCassandraRepositoryFactory(operations);
factory.setRepositoryBaseClass(SimpleReactiveCassandraRepository.class);
factory.setBeanClassLoader(classLoader);
factory.setBeanFactory(beanFactory);
repository = factory.getRepository(UserRepository.class);
groupRepostitory = factory.getRepository(GroupRepository.class);
repository.deleteAll().concatWith(groupRepostitory.deleteAll()).as(StepVerifier::create).verifyComplete();
dave = new User("42", "Dave", "Matthews");
oliver = new User("4", "Oliver August", "Matthews");
carter = new User("49", "Carter", "Beauford");
boyd = new User("45", "Boyd", "Tinsley");
repository.saveAll(Arrays.asList(oliver, dave, carter, boyd)).as(StepVerifier::create).expectNextCount(4).verifyComplete();
}
Aggregations