Attention une mise à jour du service Gitlab va être effectuée le mardi 30 novembre entre 17h30 et 18h00. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes. Cette mise à jour intermédiaire en version 14.0.12 nous permettra de rapidement pouvoir mettre à votre disposition une version plus récente.

Commit 18f09c05 authored by Jujube Orange's avatar Jujube Orange
Browse files

refactor(clea-ws): remove configurable api path prefix

Its a convention which do not change from one environment to another.
parent c9683744
......@@ -6,7 +6,6 @@ import fr.gouv.clea.ws.exception.CleaBadRequestException;
import fr.gouv.clea.ws.model.DecodedVisit;
import fr.gouv.clea.ws.service.IReportService;
import fr.gouv.clea.ws.utils.BadArgumentsLoggerService;
import fr.gouv.clea.ws.utils.UriConstants;
import fr.gouv.clea.ws.vo.ReportRequest;
import fr.gouv.clea.ws.vo.Visit;
import lombok.RequiredArgsConstructor;
......@@ -27,7 +26,7 @@ import java.util.Set;
import java.util.stream.Collectors;
@RestController
@RequestMapping(path = "${controller.path.prefix}")
@RequestMapping(path = "/api/clea")
@RequiredArgsConstructor
@Slf4j
public class CleaController implements CleaWsRestAPI {
......@@ -43,8 +42,7 @@ public class CleaController implements CleaWsRestAPI {
private final Validator validator;
@Override
@PostMapping(path = UriConstants.API_V1
+ UriConstants.REPORT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PostMapping(path = "/v1/wreport", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ReportResponse report(@RequestBody ReportRequest reportRequestVo) {
ReportRequest filtered = this.filterReports(reportRequestVo, webRequest);
List<DecodedVisit> reported = List.of();
......
package fr.gouv.clea.ws.utils;
public class UriConstants {
public static final String REPORT = "/wreport";
public static final String API_V1 = "/v1";
}
......@@ -9,10 +9,6 @@ clea:
qrCodesTopic: cleaQrCodes
statsTopic: cleaStats
controller:
path:
prefix: /api/clea
management:
endpoints:
web:
......
......@@ -2,7 +2,6 @@ package fr.gouv.clea.ws.configuration;
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.gouv.clea.ws.dto.ApiError;
import fr.gouv.clea.ws.utils.UriConstants;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.security.Keys;
......@@ -30,7 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class JwtValidationFilterTest {
private final MockHttpServletRequest request = new MockHttpServletRequest(
"POST", UriConstants.API_V1 + UriConstants.REPORT
"POST", "/api/clea/v1/wreport"
);
private final MockHttpServletResponse response = new MockHttpServletResponse();
......
......@@ -4,7 +4,6 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.gouv.clea.ws.dto.ApiError;
import fr.gouv.clea.ws.service.impl.ReportService;
import fr.gouv.clea.ws.utils.UriConstants;
import fr.gouv.clea.ws.vo.ReportRequest;
import fr.gouv.clea.ws.vo.Visit;
import io.jsonwebtoken.Jwts;
......@@ -18,7 +17,6 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.mock.mockito.MockBean;
......@@ -51,9 +49,6 @@ class CleaControllerAuthEnabledTest {
*/
private static final String privateJwtKet = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCSnywoJusbV6UYYbyf8KrQ5V5MD1X8zo40oCuF5IRYQ4mb+9brS11BbuEn6UJDUuCDiAs0vcunwa71Hv6dakKcqfAZaIvQEpacbfVJDY7TX9QxrbJYUlEkJsbj2zOA+3g+G+taw007I74rPUfA7axN9eRGknl2+pkXQS3bConLZR5U7MT/9r9me4HPC4Z8kRcE5Pvvh4US9Bad9fZkRY5q+KaI8qxvjoeqDgumZVHRDuIfwOPcPTkefTc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YHAE30NpfTZNnSqV55gMCkUOKBqSSPG9Jm+5zoL2hOV0MKkAoPh1wFdo9iRf1Q2q3Y+NOrvAoGAU2RldX35DEub3EtWl70wEvNx1DuGPCBPL5OyMsJzJh3x5cpzHZc5B9TLjIT3YeRjKiaZxtJ/evulCw/ugScEFph4GtvJZgZYutVRO8LdsqYlb+1ikE/Hd9sqhp7PhDJhfQSV3uLGrfX5fd+bizNAr8swwAFxu35N8vdKOKHtnp8=";
@Value("${controller.path.prefix}" + UriConstants.API_V1)
private String pathPrefix;
@Autowired
private TestRestTemplate restTemplate;
......@@ -77,7 +72,7 @@ class CleaControllerAuthEnabledTest {
new ReportRequest(visits, 0L), CleaControllerTest.newJsonHeader()
);
ResponseEntity<String> response = restTemplate
.postForEntity(pathPrefix + UriConstants.REPORT, request, String.class);
.postForEntity("/api/clea/v1/wreport", request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
......@@ -100,7 +95,7 @@ class CleaControllerAuthEnabledTest {
HttpEntity<ReportRequest> reportEntity = new HttpEntity<>(new ReportRequest(visits, 0L), headers);
ResponseEntity<String> response = restTemplate
.postForEntity(pathPrefix + UriConstants.REPORT, reportEntity, String.class);
.postForEntity("/api/clea/v1/wreport", reportEntity, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
......@@ -149,7 +144,7 @@ class CleaControllerAuthEnabledTest {
headers
);
ResponseEntity<String> response = restTemplate
.postForEntity(pathPrefix + UriConstants.REPORT, request, String.class);
.postForEntity("/api/clea/v1/wreport", request, String.class);
Mockito.verify(reportService).report(reportRequestArgumentCaptor.capture());
assertThat(reportRequestArgumentCaptor.getValue().getPivotDateAsNtpTimestamp()).isEqualTo(2L);
assertThat(reportRequestArgumentCaptor.getValue().getVisits())
......
......@@ -5,7 +5,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import fr.gouv.clea.ws.dto.ApiError;
import fr.gouv.clea.ws.service.impl.ReportService;
import fr.gouv.clea.ws.utils.UriConstants;
import fr.gouv.clea.ws.vo.ReportRequest;
import fr.gouv.clea.ws.vo.Visit;
import org.apache.commons.lang3.RandomStringUtils;
......@@ -19,7 +18,6 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.mock.mockito.MockBean;
......@@ -42,9 +40,6 @@ class CleaControllerTest {
@Captor
private ArgumentCaptor<ReportRequest> reportRequestArgumentCaptor;
@Value("${controller.path.prefix}" + UriConstants.API_V1)
private String pathPrefix;
@Autowired
private TestRestTemplate restTemplate;
......@@ -70,7 +65,7 @@ class CleaControllerTest {
List<Visit> visits = List.of(new Visit("qrCode", 0L));
HttpEntity<ReportRequest> request = new HttpEntity<>(new ReportRequest(visits, 0L), newJsonHeader());
ResponseEntity<String> response = restTemplate
.postForEntity(pathPrefix + UriConstants.REPORT, request, String.class);
.postForEntity("/api/clea/v1/wreport", request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
}
......@@ -78,7 +73,7 @@ class CleaControllerTest {
@Test
void testWhenReportRequestWithInvalidMediaTypeThenGetUnsupportedMediaType() {
ResponseEntity<String> response = restTemplate
.postForEntity(pathPrefix + UriConstants.REPORT, "foo", String.class);
.postForEntity("/api/clea/v1/wreport", "foo", String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
verifyNoMoreInteractions(reportService);
......@@ -88,7 +83,7 @@ class CleaControllerTest {
void testWhenReportRequestWithNullVisitListThenGetBadRequest() {
HttpEntity<ReportRequest> request = new HttpEntity<>(new ReportRequest(null, 0L), newJsonHeader());
ResponseEntity<String> response = restTemplate
.postForEntity(pathPrefix + UriConstants.REPORT, request, String.class);
.postForEntity("/api/clea/v1/wreport", request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
verifyNoMoreInteractions(reportService);
......@@ -99,7 +94,7 @@ class CleaControllerTest {
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", 1);
ResponseEntity<String> response = restTemplate.postForEntity(
pathPrefix + UriConstants.REPORT,
"/api/clea/v1/wreport",
new HttpEntity<>(jsonObject.toString(), newJsonHeader()),
String.class
);
......@@ -114,7 +109,7 @@ class CleaControllerTest {
List<Visit> visits = List.of(new Visit(RandomStringUtils.randomAlphanumeric(20), RandomUtils.nextLong()));
HttpEntity<ReportRequest> request = new HttpEntity<>(new ReportRequest(visits, null), newJsonHeader());
ResponseEntity<String> response = restTemplate
.postForEntity(pathPrefix + UriConstants.REPORT, request, String.class);
.postForEntity("/api/clea/v1/wreport", request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
verifyNoMoreInteractions(reportService);
ApiError apiError = objectMapper.readValue(response.getBody(), ApiError.class);
......@@ -140,7 +135,7 @@ class CleaControllerTest {
String badJson = json.replace("0", "a");
HttpEntity<String> request = new HttpEntity<>(badJson, newJsonHeader());
ResponseEntity<String> response = restTemplate
.postForEntity(pathPrefix + UriConstants.REPORT, request, String.class);
.postForEntity("/api/clea/v1/wreport", request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
verifyNoMoreInteractions(reportService);
ApiError apiError = objectMapper.readValue(response.getBody(), ApiError.class);
......@@ -155,7 +150,7 @@ class CleaControllerTest {
void nullVisitList() throws JsonProcessingException {
HttpEntity<ReportRequest> request = new HttpEntity<>(new ReportRequest(null, 0L), newJsonHeader());
ResponseEntity<String> response = restTemplate
.postForEntity(pathPrefix + UriConstants.REPORT, request, String.class);
.postForEntity("/api/clea/v1/wreport", request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
verifyNoMoreInteractions(reportService);
ApiError apiError = objectMapper.readValue(response.getBody(), ApiError.class);
......@@ -170,7 +165,7 @@ class CleaControllerTest {
void emptyVisitList() throws JsonProcessingException {
HttpEntity<ReportRequest> request = new HttpEntity<>(new ReportRequest(List.of(), 0L), newJsonHeader());
ResponseEntity<String> response = restTemplate
.postForEntity(pathPrefix + UriConstants.REPORT, request, String.class);
.postForEntity("/api/clea/v1/wreport", request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
verifyNoMoreInteractions(reportService);
ApiError apiError = objectMapper.readValue(response.getBody(), ApiError.class);
......@@ -188,7 +183,7 @@ class CleaControllerTest {
newJsonHeader()
);
ResponseEntity<String> response = restTemplate
.postForEntity(pathPrefix + UriConstants.REPORT, request, String.class);
.postForEntity("/api/clea/v1/wreport", request, String.class);
Mockito.verify(reportService).report(reportRequestArgumentCaptor.capture());
assertThat(reportRequestArgumentCaptor.getValue().getPivotDateAsNtpTimestamp()).isEqualTo(3L);
assertThat(reportRequestArgumentCaptor.getValue().getVisits().size()).isEqualTo(1);
......@@ -210,7 +205,7 @@ class CleaControllerTest {
newJsonHeader()
);
ResponseEntity<String> response = restTemplate
.postForEntity(pathPrefix + UriConstants.REPORT, request, String.class);
.postForEntity("/api/clea/v1/wreport", request, String.class);
Mockito.verify(reportService).report(reportRequestArgumentCaptor.capture());
assertThat(reportRequestArgumentCaptor.getValue().getPivotDateAsNtpTimestamp()).isEqualTo(3L);
assertThat(reportRequestArgumentCaptor.getValue().getVisits().size()).isEqualTo(1);
......@@ -232,7 +227,7 @@ class CleaControllerTest {
newJsonHeader()
);
ResponseEntity<String> response = restTemplate
.postForEntity(pathPrefix + UriConstants.REPORT, request, String.class);
.postForEntity("/api/clea/v1/wreport", request, String.class);
Mockito.verify(reportService).report(reportRequestArgumentCaptor.capture());
assertThat(reportRequestArgumentCaptor.getValue().getPivotDateAsNtpTimestamp()).isEqualTo(3L);
assertThat(reportRequestArgumentCaptor.getValue().getVisits().size()).isEqualTo(1);
......@@ -254,7 +249,7 @@ class CleaControllerTest {
newJsonHeader()
);
ResponseEntity<String> response = restTemplate
.postForEntity(pathPrefix + UriConstants.REPORT, request, String.class);
.postForEntity("/api/clea/v1/wreport", request, String.class);
Mockito.verify(reportService).report(reportRequestArgumentCaptor.capture());
assertThat(reportRequestArgumentCaptor.getValue().getPivotDateAsNtpTimestamp()).isEqualTo(3L);
assertThat(reportRequestArgumentCaptor.getValue().getVisits().size()).isEqualTo(1);
......@@ -276,7 +271,7 @@ class CleaControllerTest {
String badJson = json.replace("2", "a");
HttpEntity<String> request = new HttpEntity<>(badJson, newJsonHeader());
ResponseEntity<String> response = restTemplate
.postForEntity(pathPrefix + UriConstants.REPORT, request, String.class);
.postForEntity("/api/clea/v1/wreport", request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
verifyNoMoreInteractions(reportService);
ApiError apiError = objectMapper.readValue(response.getBody(), ApiError.class);
......@@ -293,7 +288,7 @@ class CleaControllerTest {
String json = objectMapper.writeValueAsString(reportRequest);
HttpEntity<String> request = new HttpEntity<>(json, newJsonHeader());
ResponseEntity<String> response = restTemplate
.postForEntity(pathPrefix + UriConstants.REPORT, request, String.class);
.postForEntity("/api/clea/v1/wreport", request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
verifyNoMoreInteractions(reportService);
ApiError apiError = objectMapper.readValue(response.getBody(), ApiError.class);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment