@Test
public void shouldRemoveStepRowMetadata() {

    // given
    final DataSetMetadata metadata = new DataSetMetadata();
    metadata.setId("ds-1234");
    final Step step1 = new Step();
    step1.setId(UUID.randomUUID().toString());
    step1.setRowMetadata("srmd-1");
    final Step step2 = new Step();
    step2.setId(UUID.randomUUID().toString());
    step2.setRowMetadata("srmd-2");
    step2.setParent(step1.id());
    final Step step3 = new Step();
    step3.setId(UUID.randomUUID().toString());
    step3.setRowMetadata(null); // Intentionally left to null
    step3.setParent(step2.id());
    final PersistentPreparation preparation = new PersistentPreparation();
    preparation.setHeadId(step3.id());
    when(preparationUtils.listSteps(eq(preparation.getHeadId()), eq(preparationRepository)))
            .thenReturn(Arrays.asList(Step.ROOT_STEP, step1, step2, step3));
    when(preparationRepository.list(eq(PersistentPreparation.class), eq(TqlBuilder.eq("dataSetId", "ds-1234"))))
            .thenReturn(Stream.of(preparation), Stream.of(preparation));
    when(preparationRepository.get(eq(step1.id()), eq(Step.class))).thenReturn(step1);
    when(preparationRepository.get(eq(step2.id()), eq(Step.class))).thenReturn(step2);
    when(datasetClient.getDataSetMetadata(any())).thenReturn(metadata);
    // when
    preparationEventUtil.performUpdateEvent(metadata.getId());
    // then
    verify(cacheEventProcessingUtil, times(2)).processCleanCacheEvent(any(ContentCacheKey.class), any());
    verify(preparationRepository, times(1)).add(any(Preparation.class));
    verify(preparationRepository, times(1)).remove(eq(StepRowMetadata.class),
            eq(TqlBuilder.in("id", "srmd-1", "srmd-2")));
    verify(securityProxy, times(2)).asTechnicalUser();
    verify(securityProxy, times(1)).asTechnicalUserForDataSet();
    verify(securityProxy, times(3)).releaseIdentity();
}