Skip to content
Snippets Groups Projects
Commit 1e3a635a authored by Felix Reichenbach's avatar Felix Reichenbach
Browse files

OZG-7846 ignore deleted vorgaenge, if formIdentifier is given

parent a24c59f3
No related branches found
No related tags found
1 merge request!13Ozg 7846 filter for form engine
......@@ -94,15 +94,17 @@ public class AggregationManagerRunner implements CommandLineRunner {
void runWithTransformation(Transformation transformation, FormIdentifier formIdentifier) {
try (Execution execution = new Execution(transformation)) {
ThreadContext.put(MDC_EXECUTION, execution.id.toString());
loadVorgaengeIntoRepository(Stream.concat(
extractBatchesOfVorgaengeFromDataSource(execution, formIdentifier),
extractBatchesOfDeletedVorgaengeFromDataSource(execution)));
var vorgaenge = extractBatchesOfVorgaengeFromDataSource(execution, formIdentifier);
var deletedVorgaenge = Objects.isNull(formIdentifier) ? extractBatchesOfDeletedVorgaengeFromDataSource(execution)
: Stream.<Batch>empty();
loadVorgaengeIntoRepository(Stream.concat(vorgaenge, deletedVorgaenge));
} finally {
ThreadContext.remove(MDC_EXECUTION);
}
}
void loadVorgaengeIntoRepository(Stream<Batch> batches) {
repository.deleteAll();
batches.map(this::transformBatchToDocumentEntries).forEach(this::loadDocumentEntriesIntoRepository);
}
......
......@@ -201,15 +201,12 @@ class AggregationManagerRunnerTest {
private final FormIdentifier formIdentifier = FormIdentifierTestFactory.create();
@Mock
private Batch batchOfVorgaenge;
@Mock
private Batch batchOfDeletedVorgaenge;
@Captor
private ArgumentCaptor<Stream<Batch>> batchStreamCaptor;
@BeforeEach
void init() {
doReturn(Stream.of(batchOfVorgaenge)).when(runner).extractBatchesOfVorgaengeFromDataSource(any(), any());
doReturn(Stream.of(batchOfDeletedVorgaenge)).when(runner).extractBatchesOfDeletedVorgaengeFromDataSource(any());
doNothing().when(runner).loadVorgaengeIntoRepository(any());
}
......@@ -220,22 +217,53 @@ class AggregationManagerRunnerTest {
verify(runner).extractBatchesOfVorgaengeFromDataSource(argThat(hasTransformation), eq(formIdentifier));
}
@Nested
class TestOnFormIdentifierIsNull {
@Mock
private Batch batchOfDeletedVorgaenge;
@BeforeEach
void mock() {
doReturn(Stream.of(batchOfDeletedVorgaenge)).when(runner).extractBatchesOfDeletedVorgaengeFromDataSource(any());
}
@Test
void shouldExtractBatchesOfDeletedVorgaengeFromDataSource() {
runner.runWithTransformation(transformation, formIdentifier);
runner.runWithTransformation(transformation, null);
verify(runner).extractBatchesOfDeletedVorgaengeFromDataSource(argThat(hasTransformation));
}
@Test
void shouldLoadVorgaengeIntoRepository() {
runner.runWithTransformation(transformation, formIdentifier);
runner.runWithTransformation(transformation, null);
verify(runner).loadVorgaengeIntoRepository(batchStreamCaptor.capture());
assertThat(batchStreamCaptor.getValue()).containsExactly(batchOfVorgaenge, batchOfDeletedVorgaenge);
}
}
@Nested
class TestOnFormIdentifierIsNotNull {
@Test
void shouldNotExtractBatchesOfDeletedVorgaengeFromDataSource() {
runner.runWithTransformation(transformation, formIdentifier);
verify(runner, never()).extractBatchesOfDeletedVorgaengeFromDataSource(any());
}
@Test
void shouldLoadVorgaengeIntoRepository() {
runner.runWithTransformation(transformation, formIdentifier);
verify(runner).loadVorgaengeIntoRepository(batchStreamCaptor.capture());
assertThat(batchStreamCaptor.getValue()).containsExactly(batchOfVorgaenge);
}
}
}
@Nested
class TestLoadVorgaengeIntoRepository {
......@@ -253,6 +281,13 @@ class AggregationManagerRunnerTest {
doNothing().when(runner).loadDocumentEntriesIntoRepository(any());
}
@Test
void shouldDropCollection() {
loadVorgaengeIntoRepository();
verify(repository).deleteAll();
}
@Test
void shouldTransform() {
loadVorgaengeIntoRepository();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment