-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat-tu: implements tests To Campaign
- Loading branch information
Showing
3 changed files
with
344 additions
and
0 deletions.
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
.../insee/survey/datacollectionmanagement/metadata/service/impl/CampaignServiceImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Partitioning> 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<Partitioning> 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<Partitioning> partitionings3 = Set.of(partitioning3); | ||
c3.setPartitionings(partitionings3); | ||
|
||
List<Campaign> 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<CampaignMoogDto> moogCampaigns = new ArrayList<>(); | ||
|
||
Collection<CampaignMoogDto> 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() { | ||
} | ||
} |
185 changes: 185 additions & 0 deletions
185
...nsee/survey/datacollectionmanagement/questioning/service/stub/CampaignRepositoryStub.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Campaign> campaigns; | ||
|
||
@Override | ||
public List<Campaign> findByPeriod(String period) { | ||
return List.of(); | ||
} | ||
|
||
@Override | ||
public List<Campaign> findBySourceYearPeriod(String source, Integer year, String period) { | ||
return List.of(); | ||
} | ||
|
||
@Override | ||
public List<Campaign> findBySourcePeriod(String source, String period) { | ||
return List.of(); | ||
} | ||
|
||
@Override | ||
public void flush() { | ||
|
||
} | ||
|
||
@Override | ||
public <S extends Campaign> S saveAndFlush(S entity) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public <S extends Campaign> List<S> saveAllAndFlush(Iterable<S> entities) { | ||
return List.of(); | ||
} | ||
|
||
@Override | ||
public void deleteAllInBatch(Iterable<Campaign> entities) { | ||
|
||
} | ||
|
||
@Override | ||
public void deleteAllByIdInBatch(Iterable<String> 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 <S extends Campaign> Optional<S> findOne(Example<S> example) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public <S extends Campaign> List<S> findAll(Example<S> example) { | ||
return List.of(); | ||
} | ||
|
||
@Override | ||
public <S extends Campaign> List<S> findAll(Example<S> example, Sort sort) { | ||
return List.of(); | ||
} | ||
|
||
@Override | ||
public <S extends Campaign> Page<S> findAll(Example<S> example, Pageable pageable) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public <S extends Campaign> long count(Example<S> example) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public <S extends Campaign> boolean exists(Example<S> example) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public <S extends Campaign, R> R findBy(Example<S> example, Function<FluentQuery.FetchableFluentQuery<S>, R> queryFunction) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public <S extends Campaign> S save(S entity) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public <S extends Campaign> List<S> saveAll(Iterable<S> entities) { | ||
return List.of(); | ||
} | ||
|
||
@Override | ||
public Optional<Campaign> findById(String s) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public boolean existsById(String s) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public List<Campaign> findAll() { | ||
return campaigns; | ||
} | ||
|
||
@Override | ||
public List<Campaign> findAllById(Iterable<String> 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<? extends String> strings) { | ||
|
||
} | ||
|
||
@Override | ||
public void deleteAll(Iterable<? extends Campaign> entities) { | ||
|
||
} | ||
|
||
@Override | ||
public void deleteAll() { | ||
|
||
} | ||
|
||
@Override | ||
public List<Campaign> findAll(Sort sort) { | ||
return List.of(); | ||
} | ||
|
||
@Override | ||
public Page<Campaign> findAll(Pageable pageable) { | ||
return null; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...see/survey/datacollectionmanagement/questioning/service/stub/PartitioningServiceStub.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ""; | ||
} | ||
} |