use of org.springframework.data.cassandra.core.mapping.event.BeforeSaveCallback in project spring-data-cassandra by spring-projects.
the class CassandraTemplateUnitTests method setUp.
@BeforeEach
void setUp() {
when(driverContext.getCodecRegistry()).thenReturn(codecRegistry);
when(session.getContext()).thenReturn(driverContext);
when(session.execute(any(Statement.class))).thenReturn(resultSet);
when(row.getColumnDefinitions()).thenReturn(columnDefinitions);
EntityCallbacks callbacks = EntityCallbacks.create();
callbacks.addEntityCallback((BeforeSaveCallback<Object>) (entity, tableName, statement) -> {
assertThat(tableName).isNotNull();
assertThat(statement).isNotNull();
beforeSave = entity;
return entity;
});
callbacks.addEntityCallback((BeforeConvertCallback<Object>) (entity, tableName) -> {
assertThat(tableName).isNotNull();
beforeConvert = entity;
return entity;
});
template = new CassandraTemplate(session);
template.setUsePreparedStatements(false);
template.setEntityCallbacks(callbacks);
}
use of org.springframework.data.cassandra.core.mapping.event.BeforeSaveCallback in project spring-data-cassandra by spring-projects.
the class AsyncCassandraTemplateUnitTests method setUp.
@BeforeEach
void setUp() {
when(driverContext.getCodecRegistry()).thenReturn(codecRegistry);
when(session.getContext()).thenReturn(driverContext);
when(session.executeAsync(any(Statement.class))).thenReturn(new TestResultSetFuture(resultSet));
when(row.getColumnDefinitions()).thenReturn(columnDefinitions);
EntityCallbacks callbacks = EntityCallbacks.create();
callbacks.addEntityCallback((BeforeSaveCallback<Object>) (entity, tableName, statement) -> {
assertThat(tableName).isNotNull();
assertThat(statement).isNotNull();
beforeSave = entity;
return entity;
});
callbacks.addEntityCallback((BeforeConvertCallback<Object>) (entity, tableName) -> {
assertThat(tableName).isNotNull();
beforeConvert = entity;
return entity;
});
template = new AsyncCassandraTemplate(session);
template.setUsePreparedStatements(false);
template.setEntityCallbacks(callbacks);
}
Aggregations