ProcessManagerRepository extends EventDispatchingRepository<I, P, S> implements CommandDispatcherDelegate, EventProducingRepository { @Override public final void store(P entity) { cache.store(entity); } protected  ProcessManagerRepository(); @Override @OverridingMethodsMustInvokeSuper void registerWith(BoundedContext context); @Override final EventBus eventBus(); @Override final ImmutableSet<EventClass> messageClasses(); @Override final ImmutableSet<EventClass> domesticEventClasses(); @Override final ImmutableSet<EventClass> externalEventClasses(); @Override final ImmutableSet<CommandClass> commandClasses(); @Override ImmutableSet<EventClass> outgoingEvents(); @Override final void dispatchCommand(CommandEnvelope command); @OverridingMethodsMustInvokeSuper @Override P create(I id); @Override final void store(P entity); @OverridingMethodsMustInvokeSuper @Override void close();  }
@Test @DisplayName("update entity via a custom migration") void performCustomMigration() { ProjectId id = createId(42); TestProcessManagerRepository repository = repository(); TestProcessManager pm = new TestProcessManager(id); repository.store(pm); TargetFilters targetFilters = targetFilters(Project.Column.idString(), id.toString()); Iterator<TestProcessManager> found = repository.find(targetFilters, ResponseFormat.getDefaultInstance()); assertThat(found.hasNext()).isFalse(); repository.applyMigration(id, new SetTestProcessId()); Iterator<TestProcessManager> afterMigration = repository.find(targetFilters, ResponseFormat.getDefaultInstance()); assertThat(afterMigration.hasNext()).isTrue(); TestProcessManager entityWithColumns = afterMigration.next(); Project expectedState = pm .state() .toBuilder() .setIdString(pm.getIdString()) .build(); assertThat(entityWithColumns.state()).isEqualTo(expectedState); }
@Test @DisplayName("update multiple entities via a custom migration") void performCustomMigrationForMultiple() { ProjectId id1 = createId(1); ProjectId id2 = createId(2); ProjectId id3 = createId(3); TestProcessManagerRepository repository = repository(); TestProcessManager pm1 = new TestProcessManager(id1); TestProcessManager pm2 = new TestProcessManager(id2); TestProcessManager pm3 = new TestProcessManager(id3); repository.store(pm1); repository.store(pm2); repository.store(pm3); TargetFilters filters = targetFilters(Project.Column.name(), SetTestProcessName.NEW_NAME); Iterator<TestProcessManager> found = repository.find(filters, ResponseFormat.getDefaultInstance()); assertThat(found.hasNext()).isFalse(); repository.applyMigration(ImmutableSet.of(id1, id2), new SetTestProcessName()); Iterator<TestProcessManager> foundAfterMigration = repository.find(filters, ResponseFormat.getDefaultInstance()); ImmutableList<TestProcessManager> results = ImmutableList.copyOf(foundAfterMigration); Project expectedState1 = pm1 .state() .toBuilder() .setName(SetTestProcessName.NEW_NAME) .setIdString(pm1.getIdString()) .build(); Project expectedState2 = pm2 .state() .toBuilder() .setName(SetTestProcessName.NEW_NAME) .setIdString(pm2.getIdString()) .build(); assertThat(results).hasSize(2); assertThat(results) .comparingElementsUsing(entityState()) .containsExactly(expectedState1, expectedState2); }
@Test @DisplayName("update columns via migration operation") void updateColumns() { ProjectId id = createId(42); TestProcessManagerRepository repository = repository(); TestProcessManager pm = new TestProcessManager(id); repository.store(pm); TargetFilters targetFilters = targetFilters(Project.Column.idString(), id.toString()); Iterator<TestProcessManager> found = repository.find(targetFilters, ResponseFormat.getDefaultInstance()); assertThat(found.hasNext()).isFalse(); repository.applyMigration(id, new UpdatePmColumns<>()); Iterator<TestProcessManager> afterMigration = repository.find(targetFilters, ResponseFormat.getDefaultInstance()); assertThat(afterMigration.hasNext()).isTrue(); TestProcessManager entityWithColumns = afterMigration.next(); Project expectedState = pm .state() .toBuilder() .setIdString(pm.getIdString()) .build(); assertThat(entityWithColumns.state()).isEqualTo(expectedState); }
@Test @DisplayName("update columns for multiple entities") void updateColumnsForMultiple() { ProjectId id1 = createId(1); ProjectId id2 = createId(2); ProjectId id3 = createId(3); TestProcessManagerRepository repository = repository(); TestProcessManager pm1 = new TestProcessManager(id1); TestProcessManager pm2 = new TestProcessManager(id2); TestProcessManager pm3 = new TestProcessManager(id3); repository.store(pm1); repository.store(pm2); repository.store(pm3); repository.applyMigration(ImmutableSet.of(id1, id2), new UpdatePmColumns<>()); QueryFilter filter1 = QueryFilter.eq(Project.Column.idString(), id1.toString()); QueryFilter filter2 = QueryFilter.eq(Project.Column.idString(), id2.toString()); QueryFilter filter3 = QueryFilter.eq(Project.Column.idString(), id3.toString()); TargetFilters filters = targetFilters(filter1, filter2, filter3); Iterator<TestProcessManager> found = repository.find(filters, ResponseFormat.getDefaultInstance()); ImmutableList<TestProcessManager> results = ImmutableList.copyOf(found); Project expectedState1 = pm1 .state() .toBuilder() .setIdString(pm1.getIdString()) .build(); Project expectedState2 = pm2 .state() .toBuilder() .setIdString(pm2.getIdString()) .build(); assertThat(results).hasSize(2); assertThat(results) .comparingElementsUsing(entityState()) .containsExactly(expectedState1, expectedState2); }
@Test @DisplayName("archive entity via migration") void archiveEntityViaMigration() { ProjectId id = createId(42); TestProcessManager entity = createEntity(id); repository().store(entity); repository().applyMigration(id, new MarkPmArchived<>()); Optional<TestProcessManager> found = repository().find(id); assertThat(found).isPresent(); assertThat(found.get() .isArchived()).isTrue(); }
@Test @DisplayName("delete entity via migration") void deleteEntityViaMigration() { ProjectId id = createId(42); TestProcessManager entity = createEntity(id); repository().store(entity); repository().applyMigration(id, new MarkPmDeleted<>()); Optional<TestProcessManager> found = repository().find(id); assertThat(found).isPresent(); assertThat(found.get() .isDeleted()).isTrue(); }
@Test @DisplayName("remove entity record via migration") void removeRecordViaMigration() { ProjectId id = createId(42); TestProcessManager entity = createEntity(id); repository().store(entity); repository().applyMigration(id, new RemovePmFromStorage<>()); Optional<TestProcessManager> found = repository().find(id); assertThat(found).isEmpty(); }