|
51 | 51 | import com.chutneytesting.server.core.domain.execution.report.ScenarioExecutionReport;
|
52 | 52 | import com.chutneytesting.server.core.domain.execution.report.ServerReportStatus;
|
53 | 53 | import com.chutneytesting.server.core.domain.instrument.ChutneyMetrics;
|
54 |
| -import com.chutneytesting.server.core.domain.scenario.ExternalDataset; |
55 | 54 | import com.chutneytesting.server.core.domain.scenario.TestCase;
|
56 | 55 | import com.chutneytesting.server.core.domain.scenario.TestCaseMetadataImpl;
|
57 | 56 | import com.chutneytesting.server.core.domain.scenario.TestCaseRepository;
|
|
62 | 61 | import com.fasterxml.jackson.databind.ObjectMapper;
|
63 | 62 | import java.time.LocalDateTime;
|
64 | 63 | import java.util.List;
|
| 64 | +import java.util.Map; |
65 | 65 | import java.util.Optional;
|
66 | 66 | import java.util.Random;
|
67 | 67 | import java.util.concurrent.ExecutorService;
|
@@ -582,6 +582,97 @@ public void should_not_use_scenario_default_dataset_when_campaign_nor_scenario_i
|
582 | 582 | assertThat(executionRequest.tags).containsExactly("TAG");
|
583 | 583 | }
|
584 | 584 |
|
| 585 | + @Test |
| 586 | + public void should_execute_by_id_with_inline_dataset() { |
| 587 | + // Given |
| 588 | + Long campaignId = 1L; |
| 589 | + String env = "env"; |
| 590 | + var scenarios = Lists.list(firstTestCase.id()).stream().map(id -> new Campaign.CampaignScenario(id, null)).toList(); |
| 591 | + Campaign campaign = new Campaign(1L, "campaign1", null, scenarios, env, false, false, "UNKNOWN", List.of("TAG")); |
| 592 | + var datatable = List.of(Map.of("HEADER", "VALUE")); |
| 593 | + var constants = Map.of("HEADER", "VALUE"); |
| 594 | + DataSet dataSet = DataSet.builder().withName("").withDatatable(datatable).withConstants(constants).build(); |
| 595 | + when(campaignRepository.findById(eq(1L))).thenReturn(campaign); |
| 596 | + |
| 597 | + // When |
| 598 | + CampaignExecution campaignExecution = sut.executeByIdWithEnvAndDataset(campaignId, env, dataSet, "USER"); |
| 599 | + |
| 600 | + // Then |
| 601 | + assertThat(campaign.externalDatasetId).isNull(); |
| 602 | + assertThat(campaignExecution.externalDataset).isNotNull(); |
| 603 | + assertThat(campaignExecution.externalDataset.getDatasetId()).isNull(); |
| 604 | + assertThat(campaignExecution.externalDataset.getConstants()).isEqualTo(constants); |
| 605 | + assertThat(campaignExecution.externalDataset.getDatatable()).isEqualTo(datatable); |
| 606 | + assertThat(campaignExecution.scenarioExecutionReports()).isNotEmpty(); |
| 607 | + assertThat(campaignExecution.scenarioExecutionReports().get(0).execution().externalDataset()).isPresent(); |
| 608 | + assertThat(campaignExecution.scenarioExecutionReports().get(0).execution().externalDataset().get().getConstants()).isEqualTo(constants); |
| 609 | + assertThat(campaignExecution.scenarioExecutionReports().get(0).execution().externalDataset().get().getDatatable()).isEqualTo(datatable); |
| 610 | + } |
| 611 | + |
| 612 | + @Test |
| 613 | + public void should_execute_by_id_with_known_dataset() { |
| 614 | + // Given |
| 615 | + Long campaignId = 1L; |
| 616 | + String env = "env"; |
| 617 | + var scenarios = Lists.list(firstTestCase.id()).stream().map(id -> new Campaign.CampaignScenario(id, null)).toList(); |
| 618 | + Campaign campaign = new Campaign(1L, "campaign1", null, scenarios, env, false, false, "UNKNOWN", List.of("TAG")); |
| 619 | + DataSet dataSet = DataSet.builder().withName("").withId("DATASET_ID").build(); |
| 620 | + when(campaignRepository.findById(eq(1L))).thenReturn(campaign); |
| 621 | + when(datasetRepository.findById(eq("DATASET_ID"))).thenReturn(DataSet.builder().withName("DATASET_ID").withId("DATASET_ID").build()); |
| 622 | + |
| 623 | + // When |
| 624 | + CampaignExecution campaignExecution = sut.executeByIdWithEnvAndDataset(campaignId, env, dataSet, "USER"); |
| 625 | + |
| 626 | + // Then |
| 627 | + assertThat(campaign.externalDatasetId).isNull(); |
| 628 | + assertThat(campaignExecution.externalDataset).isNotNull(); |
| 629 | + assertThat(campaignExecution.externalDataset.getConstants()).isEmpty(); |
| 630 | + assertThat(campaignExecution.externalDataset.getDatatable()).isEmpty(); |
| 631 | + assertThat(campaignExecution.externalDataset.getDatasetId()).isNotNull(); |
| 632 | + assertThat(campaignExecution.externalDataset.getDatasetId()).isEqualTo("DATASET_ID"); |
| 633 | + assertThat(campaignExecution.scenarioExecutionReports().get(0).execution().externalDataset()).isPresent(); |
| 634 | + assertThat(campaignExecution.scenarioExecutionReports().get(0).execution().externalDataset().get().getDatasetId()).isEqualTo("DATASET_ID"); |
| 635 | + } |
| 636 | + |
| 637 | + @Test |
| 638 | + public void should_execute_by_id_with_default_dataset() { |
| 639 | + // Given |
| 640 | + Long campaignId = 1L; |
| 641 | + String env = "env"; |
| 642 | + var scenarios = Lists.list(firstTestCase.id()).stream().map(id -> new Campaign.CampaignScenario(id, null)).toList(); |
| 643 | + Campaign campaign = new Campaign(1L, "campaign1", null, scenarios, env, false, false, "DATASET_ID", List.of("TAG")); |
| 644 | + when(campaignRepository.findById(eq(1L))).thenReturn(campaign); |
| 645 | + when(datasetRepository.findById(eq("DATASET_ID"))).thenReturn(DataSet.builder().withName("DATASET_ID").withId("DATASET_ID").build()); |
| 646 | + |
| 647 | + // When |
| 648 | + CampaignExecution campaignExecution = sut.executeByIdWithEnvAndDataset(campaignId, env, null, "USER"); |
| 649 | + |
| 650 | + // Then |
| 651 | + assertThat(campaign.externalDatasetId).isNotNull(); |
| 652 | + assertThat(campaignExecution.externalDataset).isNotNull(); |
| 653 | + assertThat(campaignExecution.externalDataset.getConstants()).isEmpty(); |
| 654 | + assertThat(campaignExecution.externalDataset.getDatatable()).isEmpty(); |
| 655 | + assertThat(campaignExecution.externalDataset.getDatasetId()).isNotNull(); |
| 656 | + assertThat(campaignExecution.externalDataset.getDatasetId()).isEqualTo("DATASET_ID"); |
| 657 | + } |
| 658 | + |
| 659 | + @Test |
| 660 | + public void should_execute_by_id_without_any_dataset() { |
| 661 | + // Given |
| 662 | + Long campaignId = 1L; |
| 663 | + String env = "env"; |
| 664 | + var scenarios = Lists.list(firstTestCase.id()).stream().map(id -> new Campaign.CampaignScenario(id, null)).toList(); |
| 665 | + Campaign campaign = new Campaign(1L, "campaign1", null, scenarios, env, false, false, null, List.of("TAG")); |
| 666 | + when(campaignRepository.findById(eq(1L))).thenReturn(campaign); |
| 667 | + |
| 668 | + // When |
| 669 | + CampaignExecution campaignExecution = sut.executeByIdWithEnvAndDataset(campaignId, env, null, "USER"); |
| 670 | + |
| 671 | + // Then |
| 672 | + assertThat(campaign.externalDatasetId).isNull(); |
| 673 | + assertThat(campaignExecution.externalDataset).isNull(); |
| 674 | + } |
| 675 | + |
585 | 676 | private final static Random campaignIdGenerator = new Random();
|
586 | 677 |
|
587 | 678 | private Long generateId() {
|
|
0 commit comments