-
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.
Merge pull request #53 from InseeFr/devProcessAllSurveysEndpoint
Add all campaigns files treatment
- Loading branch information
Showing
27 changed files
with
478 additions
and
229 deletions.
There are no files selected for viewing
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
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
58 changes: 40 additions & 18 deletions
58
src/main/java/fr/insee/genesis/controller/rest/HealthCheckController.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 |
---|---|---|
@@ -1,35 +1,57 @@ | ||
package fr.insee.genesis.controller.rest; | ||
|
||
import fr.insee.genesis.domain.ports.api.ScheduleApiPort; | ||
import fr.insee.genesis.domain.ports.api.SurveyUnitUpdateApiPort; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.info.BuildProperties; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.Optional; | ||
|
||
@RequestMapping("/health-check") | ||
@RestController | ||
public class HealthCheckController { | ||
private final SurveyUnitUpdateApiPort surveyUnitUpdateApiPort; | ||
private final ScheduleApiPort scheduleApiPort; | ||
@Value("${fr.insee.genesis.version}") | ||
private String projectVersion; | ||
|
||
@Autowired | ||
public HealthCheckController(SurveyUnitUpdateApiPort surveyUnitUpdateApiPort, ScheduleApiPort scheduleApiPort) { | ||
this.surveyUnitUpdateApiPort = surveyUnitUpdateApiPort; | ||
this.scheduleApiPort = scheduleApiPort; | ||
} | ||
|
||
@Autowired(required = false) | ||
private Optional<BuildProperties> buildProperties; | ||
@GetMapping("") | ||
public ResponseEntity<String> healthcheck() { | ||
return ResponseEntity.ok( | ||
""" | ||
OK | ||
Version %s | ||
User %s | ||
""" | ||
.formatted( | ||
projectVersion, | ||
SecurityContextHolder.getContext().getAuthentication().getName() | ||
)); | ||
} | ||
|
||
@GetMapping("") | ||
public ResponseEntity<String> healthcheck(){ | ||
return ResponseEntity.ok( | ||
""" | ||
OK | ||
Version %s | ||
User %s | ||
""" | ||
@GetMapping("mongoDb") | ||
public ResponseEntity<String> healthcheckMongo() { | ||
return ResponseEntity.ok( | ||
""" | ||
MongoDB OK | ||
%s Responses | ||
%s Schedules | ||
""" | ||
.formatted( | ||
buildProperties.map(BuildProperties::getVersion).orElse("n.a"), | ||
SecurityContextHolder.getContext().getAuthentication().getName() | ||
) ); | ||
} | ||
surveyUnitUpdateApiPort.countResponses(), | ||
scheduleApiPort.countSchedules() | ||
)); | ||
} | ||
|
||
} |
319 changes: 171 additions & 148 deletions
319
src/main/java/fr/insee/genesis/controller/rest/ResponseController.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
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
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
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
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
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
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
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
67 changes: 67 additions & 0 deletions
67
src/test/java/fr/insee/genesis/controller/rest/HealthCheckControllerTest.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,67 @@ | ||
package fr.insee.genesis.controller.rest; | ||
|
||
import fr.insee.genesis.domain.dtos.CollectedVariableDto; | ||
import fr.insee.genesis.domain.dtos.DataState; | ||
import fr.insee.genesis.domain.dtos.Mode; | ||
import fr.insee.genesis.domain.dtos.SurveyUnitUpdateDto; | ||
import fr.insee.genesis.domain.dtos.VariableDto; | ||
import fr.insee.genesis.domain.ports.api.SurveyUnitUpdateApiPort; | ||
import fr.insee.genesis.domain.service.SurveyUnitUpdateImpl; | ||
import fr.insee.genesis.stubs.ScheduleApiPortStub; | ||
import fr.insee.genesis.stubs.SurveyUnitUpdatePersistencePortStub; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Slf4j | ||
class HealthCheckControllerTest { | ||
static HealthCheckController healthCheckController; | ||
|
||
static SurveyUnitUpdatePersistencePortStub surveyUnitUpdatePersistencePortStub; | ||
static ScheduleApiPortStub scheduleApiPortStub; | ||
|
||
@BeforeAll | ||
static void init() { | ||
surveyUnitUpdatePersistencePortStub = new SurveyUnitUpdatePersistencePortStub(); | ||
SurveyUnitUpdateApiPort surveyUnitUpdateApiPort = new SurveyUnitUpdateImpl(surveyUnitUpdatePersistencePortStub); | ||
List<VariableDto> externalVariableDtoList = new ArrayList<>(); | ||
VariableDto variableDto = VariableDto.builder().idVar("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); | ||
externalVariableDtoList.add(variableDto); | ||
|
||
List<CollectedVariableDto> collectedVariableDtoList = new ArrayList<>(); | ||
CollectedVariableDto collectedVariableDto = new CollectedVariableDto("TESTIDVAR", List.of(new String[]{"V1", "V2"}), "TESTIDLOOP", "TESTIDPARENT"); | ||
collectedVariableDtoList.add(collectedVariableDto); | ||
surveyUnitUpdatePersistencePortStub.getMongoStub().add(SurveyUnitUpdateDto.builder() | ||
.idCampaign("TESTIDCAMPAIGN") | ||
.mode(Mode.WEB) | ||
.idUE("TESTIDUE") | ||
.idQuest("TESTIDQUESTIONNAIRE") | ||
.state(DataState.COLLECTED) | ||
.fileDate(LocalDateTime.of(2023, 1, 1, 0, 0, 0)) | ||
.recordDate(LocalDateTime.of(2024, 1, 1, 0, 0, 0)) | ||
.externalVariables(externalVariableDtoList) | ||
.collectedVariables(collectedVariableDtoList) | ||
.build()); | ||
|
||
|
||
scheduleApiPortStub = new ScheduleApiPortStub(); | ||
|
||
healthCheckController = new HealthCheckController( | ||
surveyUnitUpdateApiPort, | ||
scheduleApiPortStub | ||
); | ||
} | ||
|
||
@Test | ||
void mongoCountTest() { | ||
ResponseEntity<String> response = healthCheckController.healthcheckMongo(); | ||
log.info(response.getBody()); | ||
Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); | ||
} | ||
} |
Oops, something went wrong.