diff --git a/platine-management-service/src/test/java/fr/insee/survey/datacollectionmanagement/metadata/service/impl/CampaignServiceImplTest.java b/platine-management-service/src/test/java/fr/insee/survey/datacollectionmanagement/metadata/service/impl/CampaignServiceImplTest.java new file mode 100644 index 0000000..16f38c1 --- /dev/null +++ b/platine-management-service/src/test/java/fr/insee/survey/datacollectionmanagement/metadata/service/impl/CampaignServiceImplTest.java @@ -0,0 +1,125 @@ +package fr.insee.survey.datacollectionmanagement.metadata.service.impl; + +import fr.insee.survey.datacollectionmanagement.metadata.domain.Campaign; +import fr.insee.survey.datacollectionmanagement.metadata.domain.Partitioning; +import fr.insee.survey.datacollectionmanagement.metadata.dto.CampaignMoogDto; +import fr.insee.survey.datacollectionmanagement.metadata.repository.CampaignRepository; +import fr.insee.survey.datacollectionmanagement.metadata.service.CampaignService; +import fr.insee.survey.datacollectionmanagement.metadata.service.PartitioningService; +import fr.insee.survey.datacollectionmanagement.questioning.service.stub.CampaignRepositoryStub; +import fr.insee.survey.datacollectionmanagement.questioning.service.stub.PartitioningServiceStub; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import java.util.*; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; + +class CampaignServiceImplTest { + +// Stub + private CampaignRepositoryStub campaignRepositoryStub; + private PartitioningServiceStub partitioningServiceStub; +// Mockito +// private CampaignRepository campaignRepositoryMock; +// private PartitioningService partitioningServiceMock; + + private CampaignServiceImpl campaignServiceImpl; + + @BeforeEach + void init() { + Campaign c1 = new Campaign(); + c1.setId("c1"); + Partitioning partitioning1 = new Partitioning(); + partitioning1.setId("partitioning1"); + partitioning1.setOpeningDate(new Date()); + partitioning1.setClosingDate(new Date()); + Set partitionings1 = Set.of(partitioning1); + c1.setPartitionings(partitionings1); + + Campaign c2 = new Campaign(); + c2.setId("c2"); + Partitioning partitioning2 = new Partitioning(); + partitioning2.setId("partitioning1"); + partitioning2.setOpeningDate(new Date()); + partitioning2.setClosingDate(new Date()); + Set partitionings2 = Set.of(partitioning2); + c2.setPartitionings(partitionings2); + + Campaign c3 = new Campaign(); + c3.setId("c3"); + Partitioning partitioning3 = new Partitioning(); + partitioning3.setId("partitioning1"); + partitioning3.setOpeningDate(new Date()); + partitioning3.setClosingDate(new Date()); + Set partitionings3 = Set.of(partitioning3); + c3.setPartitionings(partitionings3); + + List campaigns = List.of(c1,c2,c3); + +// Stub + campaignRepositoryStub = new CampaignRepositoryStub(); + campaignRepositoryStub.setCampaigns(campaigns); + campaignServiceImpl = new CampaignServiceImpl(campaignRepositoryStub, partitioningServiceStub); + +// Mockito +// partitioningServiceMock = Mockito.mock(PartitioningService.class); +// campaignRepositoryMock = Mockito.mock(CampaignRepository.class); +// when(campaignRepositoryMock.findAll()).thenReturn(campaigns); +// campaignServiceImpl = new CampaignServiceImpl(campaignRepositoryMock, partitioningServiceMock); + + + } + + @Test + void getCampaigns() { + // given + List moogCampaigns = new ArrayList<>(); + + Collection result = campaignServiceImpl.getCampaigns(); + + // when and then + assertThat(result).isNotNull().map(CampaignMoogDto::getId).containsExactlyInAnyOrder("c1", "c2", "c3"); + assertThat(result).hasSize(3); + } + + @Test + void findbyPeriod() { + + } + + @Test + void findById() { + + } + + @Test + void findbySourceYearPeriod() { + } + + @Test + void findbySourcePeriod() { + } + + @Test + void findAll() { + } + + @Test + void insertOrUpdateCampaign() { + } + + @Test + void deleteCampaignById() { + } + + @Test + void addPartitionigToCampaign() { + } + + @Test + void isCampaignOngoing() { + } +} \ No newline at end of file diff --git a/platine-management-service/src/test/java/fr/insee/survey/datacollectionmanagement/questioning/service/stub/CampaignRepositoryStub.java b/platine-management-service/src/test/java/fr/insee/survey/datacollectionmanagement/questioning/service/stub/CampaignRepositoryStub.java new file mode 100644 index 0000000..9332e7d --- /dev/null +++ b/platine-management-service/src/test/java/fr/insee/survey/datacollectionmanagement/questioning/service/stub/CampaignRepositoryStub.java @@ -0,0 +1,185 @@ +package fr.insee.survey.datacollectionmanagement.questioning.service.stub; + +import fr.insee.survey.datacollectionmanagement.metadata.domain.Campaign; +import fr.insee.survey.datacollectionmanagement.metadata.repository.CampaignRepository; +import lombok.Setter; +import org.springframework.data.domain.Example; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.repository.query.FluentQuery; + +import java.util.List; +import java.util.Optional; +import java.util.function.Function; + +public class CampaignRepositoryStub implements CampaignRepository { + + @Setter + private List campaigns; + + @Override + public List findByPeriod(String period) { + return List.of(); + } + + @Override + public List findBySourceYearPeriod(String source, Integer year, String period) { + return List.of(); + } + + @Override + public List findBySourcePeriod(String source, String period) { + return List.of(); + } + + @Override + public void flush() { + + } + + @Override + public S saveAndFlush(S entity) { + return null; + } + + @Override + public List saveAllAndFlush(Iterable entities) { + return List.of(); + } + + @Override + public void deleteAllInBatch(Iterable entities) { + + } + + @Override + public void deleteAllByIdInBatch(Iterable strings) { + + } + + @Override + public void deleteAllInBatch() { + + } + + @Override + public Campaign getOne(String s) { + return null; + } + + @Override + public Campaign getById(String s) { + return null; + } + + @Override + public Campaign getReferenceById(String s) { + return null; + } + + @Override + public Optional findOne(Example example) { + return Optional.empty(); + } + + @Override + public List findAll(Example example) { + return List.of(); + } + + @Override + public List findAll(Example example, Sort sort) { + return List.of(); + } + + @Override + public Page findAll(Example example, Pageable pageable) { + return null; + } + + @Override + public long count(Example example) { + return 0; + } + + @Override + public boolean exists(Example example) { + return false; + } + + @Override + public R findBy(Example example, Function, R> queryFunction) { + return null; + } + + @Override + public S save(S entity) { + return null; + } + + @Override + public List saveAll(Iterable entities) { + return List.of(); + } + + @Override + public Optional findById(String s) { + return Optional.empty(); + } + + @Override + public boolean existsById(String s) { + return false; + } + + @Override + public List findAll() { + return campaigns; + } + + @Override + public List findAllById(Iterable strings) { + return List.of(); + } + + @Override + public long count() { + return 0; + } + + @Override + public void deleteById(String s) { + + } + + @Override + public void delete(Campaign entity) { + + } + + @Override + public void deleteAllById(Iterable strings) { + + } + + @Override + public void deleteAll(Iterable entities) { + + } + + @Override + public void deleteAll() { + + } + + @Override + public List findAll(Sort sort) { + return List.of(); + } + + @Override + public Page findAll(Pageable pageable) { + return null; + } +} diff --git a/platine-management-service/src/test/java/fr/insee/survey/datacollectionmanagement/questioning/service/stub/PartitioningServiceStub.java b/platine-management-service/src/test/java/fr/insee/survey/datacollectionmanagement/questioning/service/stub/PartitioningServiceStub.java new file mode 100644 index 0000000..993161a --- /dev/null +++ b/platine-management-service/src/test/java/fr/insee/survey/datacollectionmanagement/questioning/service/stub/PartitioningServiceStub.java @@ -0,0 +1,34 @@ +package fr.insee.survey.datacollectionmanagement.questioning.service.stub; + +import fr.insee.survey.datacollectionmanagement.metadata.domain.Partitioning; +import fr.insee.survey.datacollectionmanagement.metadata.enums.ParameterEnum; +import fr.insee.survey.datacollectionmanagement.metadata.service.PartitioningService; + +import java.util.Date; + +public class PartitioningServiceStub implements PartitioningService { + @Override + public Partitioning findById(String id) { + return null; + } + + @Override + public Partitioning insertOrUpdatePartitioning(Partitioning partitioning) { + return null; + } + + @Override + public void deletePartitioningById(String id) { + + } + + @Override + public boolean isOnGoing(Partitioning part, Date date) { + return false; + } + + @Override + public String findSuitableParameterValue(Partitioning part, ParameterEnum paramValue) { + return ""; + } +}