Skip to content

Commit e373556

Browse files
committed
feat(server): Add test for execution, remove unused code
1 parent 53f6e4f commit e373556

File tree

4 files changed

+92
-52
lines changed

4 files changed

+92
-52
lines changed

chutney/server/src/main/java/com/chutneytesting/campaign/api/dto/ExternalDatasetDto.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

chutney/server/src/main/java/com/chutneytesting/dataset/domain/DatasetService.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static java.util.stream.Collectors.toList;
2121

2222
import com.chutneytesting.campaign.domain.CampaignRepository;
23-
import com.chutneytesting.dataset.api.DataSetDto;
2423
import com.chutneytesting.scenario.domain.gwt.GwtTestCase;
2524
import com.chutneytesting.server.core.domain.dataset.DataSet;
2625
import com.chutneytesting.server.core.domain.dataset.DataSetNotFoundException;
@@ -108,11 +107,4 @@ public void remove(String datasetName) {
108107
updateCampaigns(datasetName, "");
109108
}
110109

111-
public static void hasNoDuplicatedHeaders(DataSetDto dataset) {
112-
List<String> duplicates = dataset.duplicatedHeaders();
113-
if (!duplicates.isEmpty()) {
114-
throw new IllegalArgumentException( duplicates.size() + " column(s) have duplicated headers: [" + String.join(", ", duplicates) +"]");
115-
}
116-
}
117-
118110
}

chutney/server/src/main/java/com/chutneytesting/execution/api/CampaignExecutionUiController.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,21 @@
1717
package com.chutneytesting.execution.api;
1818

1919
import static com.chutneytesting.campaign.api.dto.CampaignExecutionReportMapper.toDto;
20-
import static com.chutneytesting.dataset.api.DataSetMapper.fromDto;
21-
import static com.chutneytesting.dataset.domain.DatasetService.hasNoDuplicatedHeaders;
22-
import static java.util.Optional.ofNullable;
2320

2421
import com.chutneytesting.campaign.api.dto.CampaignExecutionReportDto;
2522
import com.chutneytesting.campaign.api.dto.CampaignExecutionReportMapper;
26-
import com.chutneytesting.dataset.api.DataSetDto;
27-
import com.chutneytesting.dataset.api.DataSetMapper;
2823
import com.chutneytesting.dataset.api.ExternalDatasetDto;
2924
import com.chutneytesting.dataset.api.KeyValue;
3025
import com.chutneytesting.execution.api.report.surefire.SurefireCampaignExecutionReportBuilder;
3126
import com.chutneytesting.execution.api.report.surefire.SurefireScenarioExecutionReportBuilder;
3227
import com.chutneytesting.execution.domain.campaign.CampaignExecutionEngine;
3328
import com.chutneytesting.security.infra.SpringUserService;
3429
import com.chutneytesting.server.core.domain.dataset.DataSet;
35-
import com.chutneytesting.server.core.domain.scenario.ExternalDataset;
3630
import com.chutneytesting.server.core.domain.scenario.campaign.CampaignExecution;
3731
import jakarta.servlet.http.HttpServletResponse;
3832
import java.util.List;
39-
import java.util.Map;
4033
import java.util.Optional;
4134
import java.util.stream.Collectors;
42-
import javax.xml.crypto.Data;
4335
import org.slf4j.Logger;
4436
import org.slf4j.LoggerFactory;
4537
import org.springframework.http.HttpStatus;
@@ -51,7 +43,6 @@
5143
import org.springframework.web.bind.annotation.PostMapping;
5244
import org.springframework.web.bind.annotation.RequestBody;
5345
import org.springframework.web.bind.annotation.RequestMapping;
54-
import org.springframework.web.bind.annotation.RequestParam;
5546
import org.springframework.web.bind.annotation.ResponseStatus;
5647
import org.springframework.web.bind.annotation.RestController;
5748

chutney/server/src/test/java/com/chutneytesting/execution/domain/campaign/CampaignExecutionEngineTest.java

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import com.chutneytesting.server.core.domain.execution.report.ScenarioExecutionReport;
5252
import com.chutneytesting.server.core.domain.execution.report.ServerReportStatus;
5353
import com.chutneytesting.server.core.domain.instrument.ChutneyMetrics;
54-
import com.chutneytesting.server.core.domain.scenario.ExternalDataset;
5554
import com.chutneytesting.server.core.domain.scenario.TestCase;
5655
import com.chutneytesting.server.core.domain.scenario.TestCaseMetadataImpl;
5756
import com.chutneytesting.server.core.domain.scenario.TestCaseRepository;
@@ -62,6 +61,7 @@
6261
import com.fasterxml.jackson.databind.ObjectMapper;
6362
import java.time.LocalDateTime;
6463
import java.util.List;
64+
import java.util.Map;
6565
import java.util.Optional;
6666
import java.util.Random;
6767
import java.util.concurrent.ExecutorService;
@@ -582,6 +582,97 @@ public void should_not_use_scenario_default_dataset_when_campaign_nor_scenario_i
582582
assertThat(executionRequest.tags).containsExactly("TAG");
583583
}
584584

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+
585676
private final static Random campaignIdGenerator = new Random();
586677

587678
private Long generateId() {

0 commit comments

Comments
 (0)