use of org.talend.dataprep.api.preparation.Action in project data-prep by Talend.
the class PreparationCleanerTest method shouldNotRemovePreparationActions_ownedByOnePreparation.
@Test
public void shouldNotRemovePreparationActions_ownedByOnePreparation() throws Exception {
// given
final String version = "1.2.3";
final PreparationActions content = new PreparationActions();
List<Action> actions = new ArrayList<>();
content.append(actions);
content.setAppVersion(version);
when(repository.list(PreparationActions.class)).thenReturn(Stream.of(content));
when(repository.get(content.id(), PreparationActions.class)).thenReturn(content);
// 2 preparations, with each, one step that shares the same action
final Step stepFirstPreparation = new Step(Step.ROOT_STEP.getId(), content.getId(), version);
final Step stepSecondPreparation = new Step(Step.ROOT_STEP.getId(), content.getId(), version);
// add the steps to the repository
when(repository.list(Step.class)).thenReturn(Stream.of(stepFirstPreparation, stepSecondPreparation));
when(repository.list(eq(PersistentStep.class))).thenReturn(Stream.of(stepFirstPreparation, stepSecondPreparation).map(s -> {
final PersistentStep persistentStep = new PersistentStep();
persistentStep.setId(s.id());
persistentStep.setContent(s.getContent());
return persistentStep;
}));
Preparation firstPreparation = new Preparation("1", null, stepFirstPreparation.getId(), version);
firstPreparation.setSteps(Collections.singletonList(stepFirstPreparation));
Preparation secondPreparation = new Preparation("2", null, stepSecondPreparation.getId(), version);
secondPreparation.setSteps(Collections.singletonList(stepSecondPreparation));
// add the preparations to the repository
when(repository.exist(eq(PersistentStep.class), any())).thenReturn(true);
// Remove first preparation
when(repository.list(Preparation.class)).thenReturn(Stream.of(secondPreparation));
// when
cleaner.removeOrphanSteps();
// then
// when the first preparation is removed, the shared action is not deleted
verify(repository, never()).remove(eq(content));
}
use of org.talend.dataprep.api.preparation.Action in project data-prep by Talend.
the class PreparationCleanerTest method shouldRemovePreparationActions_noPreparation.
@Test
public void shouldRemovePreparationActions_noPreparation() throws Exception {
// given
final String version = "1.2.3";
final PreparationActions content = new PreparationActions();
List<Action> actions = new ArrayList<>();
content.append(actions);
content.setAppVersion(version);
when(repository.list(PreparationActions.class)).thenReturn(Stream.of(content));
when(repository.get(content.id(), PreparationActions.class)).thenReturn(content);
// 2 preparations, with each, one step that shares the same action
final Step stepFirstPreparation = new Step(Step.ROOT_STEP.getId(), content.getId(), version);
final Step stepSecondPreparation = new Step(Step.ROOT_STEP.getId(), content.getId(), version);
// add the steps to the repository
when(repository.list(Step.class)).thenReturn(Stream.of(stepFirstPreparation, stepSecondPreparation));
when(repository.list(eq(PersistentStep.class))).thenReturn(Stream.of(stepFirstPreparation, stepSecondPreparation).map(s -> {
final PersistentStep persistentStep = new PersistentStep();
persistentStep.setId(s.id());
persistentStep.setContent(s.getContent());
return persistentStep;
}));
Preparation firstPreparation = new Preparation("1", null, stepFirstPreparation.getId(), version);
firstPreparation.setSteps(Collections.singletonList(stepFirstPreparation));
Preparation secondPreparation = new Preparation("2", null, stepSecondPreparation.getId(), version);
secondPreparation.setSteps(Collections.singletonList(stepSecondPreparation));
// when
when(repository.exist(eq(PersistentStep.class), eq(TqlBuilder.eq("contentId", content.id())))).thenReturn(false);
// Remove first and second preparations
when(repository.list(Preparation.class)).thenReturn(Stream.empty());
cleaner.removeOrphanSteps();
// then
// 2 steps content
verify(repository, times(2)).remove(eq(content));
}
Aggregations