Search in sources :

Example 1 with ReactiveBeforeConvertCallback

use of org.springframework.data.cassandra.core.mapping.event.ReactiveBeforeConvertCallback in project spring-data-cassandra by spring-projects.

the class ReactiveCassandraTemplateUnitTests method setUp.

@BeforeEach
void setUp() {
    when(driverContext.getCodecRegistry()).thenReturn(codecRegistry);
    when(session.getContext()).thenReturn(driverContext);
    when(session.execute(any(Statement.class))).thenReturn(Mono.just(reactiveResultSet));
    when(row.getColumnDefinitions()).thenReturn(columnDefinitions);
    ReactiveEntityCallbacks callbacks = ReactiveEntityCallbacks.create();
    callbacks.addEntityCallback((ReactiveBeforeSaveCallback<Object>) (entity, tableName, statement) -> {
        assertThat(tableName).isNotNull();
        assertThat(statement).isNotNull();
        beforeSave = entity;
        return Mono.just(entity);
    });
    callbacks.addEntityCallback((ReactiveBeforeConvertCallback<Object>) (entity, tableName) -> {
        assertThat(tableName).isNotNull();
        beforeConvert = entity;
        return Mono.just(entity);
    });
    template = new ReactiveCassandraTemplate(session);
    template.setUsePreparedStatements(false);
    template.setEntityCallbacks(callbacks);
}
Also used : Strictness(org.mockito.quality.Strictness) BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers(org.mockito.ArgumentMatchers) StepVerifier(reactor.test.StepVerifier) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) DefaultCodecRegistry(com.datastax.oss.driver.internal.core.type.codec.registry.DefaultCodecRegistry) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) Mock(org.mockito.Mock) Filter(org.springframework.data.cassandra.core.query.Filter) VersionedUser(org.springframework.data.cassandra.domain.VersionedUser) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) Captor(org.mockito.Captor) ReactiveBeforeConvertCallback(org.springframework.data.cassandra.core.mapping.event.ReactiveBeforeConvertCallback) ArgumentCaptor(org.mockito.ArgumentCaptor) User(org.springframework.data.cassandra.domain.User) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) NoNodeAvailableException(com.datastax.oss.driver.api.core.NoNodeAvailableException) Assertions(org.assertj.core.api.Assertions) ReactiveSession(org.springframework.data.cassandra.ReactiveSession) Row(com.datastax.oss.driver.api.core.cql.Row) ColumnDefinition(com.datastax.oss.driver.api.core.cql.ColumnDefinition) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) CodecRegistry(com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry) Criteria(org.springframework.data.cassandra.core.query.Criteria) Update(org.springframework.data.cassandra.core.query.Update) ReactiveEntityCallbacks(org.springframework.data.mapping.callback.ReactiveEntityCallbacks) DriverContext(com.datastax.oss.driver.api.core.context.DriverContext) ReactiveResultSet(org.springframework.data.cassandra.ReactiveResultSet) Mono(reactor.core.publisher.Mono) ReactiveBeforeSaveCallback(org.springframework.data.cassandra.core.mapping.event.ReactiveBeforeSaveCallback) Query(org.springframework.data.cassandra.core.query.Query) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) Flux(reactor.core.publisher.Flux) List(java.util.List) DataTypes(com.datastax.oss.driver.api.core.type.DataTypes) Statement(com.datastax.oss.driver.api.core.cql.Statement) ReactiveEntityCallbacks(org.springframework.data.mapping.callback.ReactiveEntityCallbacks) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) Statement(com.datastax.oss.driver.api.core.cql.Statement) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)1 NoNodeAvailableException (com.datastax.oss.driver.api.core.NoNodeAvailableException)1 DriverContext (com.datastax.oss.driver.api.core.context.DriverContext)1 ColumnDefinition (com.datastax.oss.driver.api.core.cql.ColumnDefinition)1 ColumnDefinitions (com.datastax.oss.driver.api.core.cql.ColumnDefinitions)1 Row (com.datastax.oss.driver.api.core.cql.Row)1 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)1 Statement (com.datastax.oss.driver.api.core.cql.Statement)1 DataTypes (com.datastax.oss.driver.api.core.type.DataTypes)1 CodecRegistry (com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry)1 DefaultCodecRegistry (com.datastax.oss.driver.internal.core.type.codec.registry.DefaultCodecRegistry)1 List (java.util.List)1 Assertions (org.assertj.core.api.Assertions)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 ArgumentCaptor (org.mockito.ArgumentCaptor)1 ArgumentMatchers (org.mockito.ArgumentMatchers)1 Captor (org.mockito.Captor)1 Mock (org.mockito.Mock)1