-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Formatage tp-2 et correction des diffs non significatifs entre énoncé…
… et solution
- Loading branch information
Pierre-Yves Fourmond
committed
Oct 26, 2023
1 parent
eda1996
commit c147b7d
Showing
10 changed files
with
102 additions
and
131 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
55 changes: 21 additions & 34 deletions
55
src/main/java/com/octo/ajava/infra/api_client/TMDBHttpClient.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,48 +1,35 @@ | ||
package com.octo.ajava.infra.api_client; | ||
|
||
import static java.util.Collections.emptyList; | ||
|
||
import com.octo.ajava.infra.api_client.entities.PaginatedTMDBMovies; | ||
import com.octo.ajava.infra.api_client.entities.TMDBMovie; | ||
|
||
import java.time.Duration; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.List; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.web.client.RestTemplateBuilder; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import org.springframework.web.util.DefaultUriBuilderFactory; | ||
|
||
@Service | ||
@ConditionalOnProperty(name = "film.source", havingValue = "TMDB") | ||
public class TMDBHttpClient { | ||
|
||
private static final String BEARER = "Bearer "; | ||
|
||
private WebClient webClient; | ||
|
||
public TMDBHttpClient( | ||
@Value("${tmdb.baseUrl}") String urlTmdb, | ||
@Value("${tmdb.token}") String jetonTmdb | ||
) { | ||
webClient = WebClient.builder() | ||
.baseUrl(urlTmdb) | ||
.defaultHeader(HttpHeaders.AUTHORIZATION, BEARER + jetonTmdb) | ||
.build(); | ||
} | ||
|
||
|
||
public PaginatedTMDBMovies recupererLesFilmsPopulaires() { | ||
return webClient.get() | ||
.uri("/movie/popular") | ||
.retrieve() | ||
.bodyToMono(PaginatedTMDBMovies.class) | ||
.block(); | ||
} | ||
private static final String BEARER = "Bearer "; | ||
|
||
private WebClient webClient; | ||
|
||
public TMDBHttpClient( | ||
@Value("${tmdb.baseUrl}") String urlTmdb, @Value("${tmdb.token}") String jetonTmdb) { | ||
webClient = | ||
WebClient.builder() | ||
.baseUrl(urlTmdb) | ||
.defaultHeader(HttpHeaders.AUTHORIZATION, BEARER + jetonTmdb) | ||
.build(); | ||
} | ||
|
||
public PaginatedTMDBMovies recupererLesFilmsPopulaires() { | ||
return webClient | ||
.get() | ||
.uri("/movie/popular") | ||
.retrieve() | ||
.bodyToMono(PaginatedTMDBMovies.class) | ||
.block(); | ||
} | ||
} |
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
39 changes: 21 additions & 18 deletions
39
src/test/java/com/octo/ajava/infra/controllers/FilmControllerFTest.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,34 +1,37 @@ | ||
package com.octo.ajava.infra.controllers; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.octo.ajava.AjavaApplication; | ||
import com.octo.ajava.ObjectMapperBuilder; | ||
import com.octo.ajava.domain.Film; | ||
import io.restassured.RestAssured; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@SpringBootTest( | ||
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, | ||
classes = AjavaApplication.class | ||
) | ||
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, | ||
classes = AjavaApplication.class) | ||
class FilmControllerFTest { | ||
|
||
@Test | ||
void recuperTousLesFilms_devrait_renvoyer_une_HTTP_200_et_une_liste_de_film() throws Exception { | ||
// Given | ||
@Test | ||
void recuperTousLesFilms_devrait_renvoyer_une_HTTP_200_et_une_liste_de_film() throws Exception { | ||
// Given | ||
|
||
// When | ||
var response = RestAssured.given() | ||
.get("/api/films") | ||
.then() | ||
.statusCode(HttpStatus.OK.value()) | ||
.extract().response().asString(); | ||
// When | ||
var response = | ||
RestAssured.given() | ||
.get("/api/films") | ||
.then() | ||
.statusCode(HttpStatus.OK.value()) | ||
.extract() | ||
.response() | ||
.asString(); | ||
|
||
// Then | ||
Film[] listeDeFilms = ObjectMapperBuilder.handle().readValue(response, Film[].class); | ||
// Then | ||
Film[] listeDeFilms = ObjectMapperBuilder.handle().readValue(response, Film[].class); | ||
|
||
assertThat(listeDeFilms.length).isEqualTo(22); | ||
} | ||
} | ||
assertThat(listeDeFilms.length).isEqualTo(22); | ||
} | ||
} |
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