Search in sources :

Example 16 with User

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();
}
Also used : User(org.springframework.data.cassandra.domain.User) Test(org.junit.jupiter.api.Test)

Example 17 with User

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'");
}
Also used : VersionedUser(org.springframework.data.cassandra.domain.VersionedUser) User(org.springframework.data.cassandra.domain.User) Test(org.junit.jupiter.api.Test)

Example 18 with User

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);
}
Also used : VersionedUser(org.springframework.data.cassandra.domain.VersionedUser) User(org.springframework.data.cassandra.domain.User) Test(org.junit.jupiter.api.Test)

Example 19 with 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();
}
Also used : User(org.springframework.data.cassandra.domain.User) Query(org.springframework.data.cassandra.core.query.Query) Test(org.junit.jupiter.api.Test)

Example 20 with User

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);
}
Also used : User(org.springframework.data.cassandra.domain.User) 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