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