Skip to content

Commit

Permalink
MET-5412 possible case of redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
jeortizquan committed Oct 17, 2023
1 parent d25f247 commit 3eacc08
Showing 1 changed file with 80 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@
import eu.europeana.metis.core.workflow.Workflow;
import eu.europeana.metis.core.workflow.WorkflowExecution;
import eu.europeana.metis.core.workflow.WorkflowStatus;
import eu.europeana.metis.core.workflow.plugins.AbstractMetisPlugin;
import eu.europeana.metis.core.workflow.plugins.DataStatus;
import eu.europeana.metis.core.workflow.plugins.ExecutablePlugin;
import eu.europeana.metis.core.workflow.plugins.ExecutablePluginFactory;
import eu.europeana.metis.core.workflow.plugins.ExecutionProgress;
import eu.europeana.metis.core.workflow.plugins.IndexToPreviewPlugin;
import eu.europeana.metis.core.workflow.plugins.IndexToPreviewPluginMetadata;
import eu.europeana.metis.core.workflow.plugins.IndexToPublishPlugin;
import eu.europeana.metis.core.workflow.plugins.IndexToPublishPluginMetadata;
import eu.europeana.metis.core.workflow.plugins.PluginStatus;
import eu.europeana.metis.exception.BadContentException;
import org.bson.types.ObjectId;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
Expand Down Expand Up @@ -60,66 +63,104 @@ class RedirectionTest {
@Test
void redirectionReview() throws BadContentException {
int priority = 0;
IndexToPreviewPluginMetadata indexToPreviewPluginMetadata = getIndexToPreviewPluginMetadata();
IndexToPreviewPlugin indexToPreviewPlugin = getIndexToPreviewPlugin(indexToPreviewPluginMetadata, getExecutionProgress());
PluginWithExecutionId<ExecutablePlugin> indexToPreviewPluginPluginWithExecutionId =
new PluginWithExecutionId<>("executionId", indexToPreviewPlugin);

final String datasetId = "datasetId";
final ObjectId objectId = new ObjectId();
Workflow workflow = getWorkflow(datasetId, objectId, getIndexToPublishPluginMetadata(indexToPreviewPlugin, indexToPreviewPluginMetadata));
Dataset dataset = getTestDataset(datasetId);
PluginWithExecutionId<ExecutablePlugin> predecessor = new PluginWithExecutionId<>("executionId", indexToPreviewPlugin);

when(workflowExecutionDao.getLatestSuccessfulExecutablePlugin(anyString(), any(), anyBoolean()))
.thenReturn(indexToPreviewPluginPluginWithExecutionId);
when(dataEvolutionUtils.getRootAncestor(any()))
.thenReturn(indexToPreviewPluginPluginWithExecutionId);

WorkflowExecution workflowExecution = workflowExecutionFactory.createWorkflowExecution(workflow, dataset, predecessor, priority);

AbstractMetisPlugin<IndexToPublishPluginMetadata> abstractMetisPlugin = workflowExecution.getMetisPlugins().stream().findFirst().get();
assertEquals(false, abstractMetisPlugin.getPluginMetadata().isPerformRedirects());
}

@NotNull
private static Workflow getWorkflow(String datasetId, ObjectId objectId, IndexToPublishPluginMetadata indexToPublishPluginMetadata) {
Workflow workflow = new Workflow();
workflow.setDatasetId(datasetId);
workflow.setId(objectId);
workflow.setMetisPluginsMetadata(List.of(indexToPublishPluginMetadata));
return workflow;
}

@NotNull
private static IndexToPublishPluginMetadata getIndexToPublishPluginMetadata(IndexToPreviewPlugin indexToPreviewPlugin, IndexToPreviewPluginMetadata indexToPreviewPluginMetadata) {
IndexToPublishPluginMetadata indexToPublishPluginMetadata = new IndexToPublishPluginMetadata();
indexToPublishPluginMetadata.setIncrementalIndexing(false);
indexToPublishPluginMetadata.setHarvestDate(Date.from(Instant.now()));
indexToPublishPluginMetadata.setPreserveTimestamps(false);
indexToPublishPluginMetadata.setEnabled(true);
indexToPublishPluginMetadata.setDatasetIdsToRedirectFrom(List.of());
// IndexToPublishPlugin indexToPublishPlugin = (IndexToPublishPlugin) ExecutablePluginFactory.createPlugin(indexToPublishPluginMetadata);

IndexToPreviewPluginMetadata indexToPreviewPluginMetadata = new IndexToPreviewPluginMetadata();
indexToPreviewPluginMetadata.setIncrementalIndexing(false);
indexToPreviewPluginMetadata.setHarvestDate(Date.from(Instant.now().minus(100, ChronoUnit.MINUTES)));
indexToPreviewPluginMetadata.setPreserveTimestamps(false);
indexToPreviewPluginMetadata.setEnabled(true);
indexToPreviewPluginMetadata.setDatasetIdsToRedirectFrom(List.of());
indexToPublishPluginMetadata.setPerformRedirects(true);
indexToPublishPluginMetadata.setPreviousRevisionInformation(indexToPreviewPlugin);
indexToPreviewPluginMetadata.setRevisionNamePreviousPlugin("revisionName");
return indexToPublishPluginMetadata;
}

@NotNull
private static IndexToPreviewPlugin getIndexToPreviewPlugin(IndexToPreviewPluginMetadata indexToPreviewPluginMetadata, ExecutionProgress executionProgress) {
IndexToPreviewPlugin indexToPreviewPlugin = (IndexToPreviewPlugin) ExecutablePluginFactory.createPlugin(indexToPreviewPluginMetadata);
ExecutionProgress executionProgress = new ExecutionProgress();
executionProgress.setStatus(TaskState.PROCESSED);
executionProgress.setExpectedRecords(1);
executionProgress.setProcessedRecords(1);
executionProgress.setTotalDatabaseRecords(1);
indexToPreviewPlugin.setExecutionProgress(executionProgress);
indexToPreviewPlugin.setPluginStatus(PluginStatus.FINISHED);
indexToPreviewPlugin.setStartedDate(Date.from(Instant.now().minus(90, ChronoUnit.MINUTES)));
indexToPreviewPlugin.setFinishedDate(Date.from(Instant.now().minus(60, ChronoUnit.MINUTES)));
indexToPreviewPlugin.setDataStatus(DataStatus.VALID);
return indexToPreviewPlugin;
}

PluginWithExecutionId<ExecutablePlugin> indexToPreviewPluginPluginWithExecutionId = new PluginWithExecutionId<>("executionId", indexToPreviewPlugin);

indexToPreviewPluginPluginWithExecutionId.getPlugin().getFinishedDate();

when(workflowExecutionDao.getLatestSuccessfulExecutablePlugin(anyString(), any(), anyBoolean()))
.thenReturn(indexToPreviewPluginPluginWithExecutionId);
when(dataEvolutionUtils.getRootAncestor(any()))
.thenReturn(indexToPreviewPluginPluginWithExecutionId);

final String datasetId = "datasetId";
final ObjectId objectId = new ObjectId();
@NotNull
private static ExecutionProgress getExecutionProgress() {
ExecutionProgress executionProgress = new ExecutionProgress();
executionProgress.setStatus(TaskState.PROCESSED);
executionProgress.setExpectedRecords(1);
executionProgress.setProcessedRecords(1);
executionProgress.setTotalDatabaseRecords(1);
return executionProgress;
}

Workflow workflow = new Workflow();
workflow.setDatasetId(datasetId);
workflow.setId(objectId);
workflow.setMetisPluginsMetadata(List.of(indexToPublishPluginMetadata));
@NotNull
private static IndexToPreviewPluginMetadata getIndexToPreviewPluginMetadata() {
IndexToPreviewPluginMetadata indexToPreviewPluginMetadata = new IndexToPreviewPluginMetadata();
indexToPreviewPluginMetadata.setIncrementalIndexing(false);
indexToPreviewPluginMetadata.setHarvestDate(Date.from(Instant.now().minus(100, ChronoUnit.MINUTES)));
indexToPreviewPluginMetadata.setPreserveTimestamps(false);
indexToPreviewPluginMetadata.setEnabled(true);
indexToPreviewPluginMetadata.setDatasetIdsToRedirectFrom(List.of());
indexToPreviewPluginMetadata.setPerformRedirects(true);
return indexToPreviewPluginMetadata;
}

@NotNull
private static Dataset getTestDataset(String datasetId) {
Dataset dataset = new Dataset();
dataset.setDatasetId(datasetId);
dataset.setCountry(Country.NETHERLANDS);
dataset.setLanguage(Language.NL);
dataset.setCountry(Country.GERMANY);
dataset.setDescription("");
dataset.setOrganizationId("1482250000001617026");
dataset.setCreatedByUserId("1482250000016772002");
dataset.setLanguage(Language.MUL);
dataset.setDatasetIdsToRedirectFrom(List.of());
dataset.setOrganizationName("Organization");
dataset.setOrganizationName("Europeana Foundation");
dataset.setCreatedByUserId("userId");
dataset.setCreatedDate(Date.from(Instant.now().minus(120, ChronoUnit.MINUTES)));
dataset.setUpdatedDate(Date.from(Instant.now()));

PluginWithExecutionId<ExecutablePlugin> predecessor = new PluginWithExecutionId<>("executionId", indexToPreviewPlugin);

WorkflowExecution workflowExecution = workflowExecutionFactory.createWorkflowExecution(workflow, dataset, predecessor, priority);

// add assertion
dataset.setReplacedBy("");
dataset.setDataProvider("Kunsthochschule Kassel");
dataset.setProvider("EFG");
dataset.setIntermediateProvider("");
dataset.setNotes("");
dataset.setEcloudDatasetId("377ac607-f729-483d-a86d-2c005150c46d");
return dataset;
}


}

0 comments on commit 3eacc08

Please sign in to comment.