Skip to content

Commit

Permalink
Formatage tp-2 et correction des diffs non significatifs entre énoncé
Browse files Browse the repository at this point in the history
 et solution
  • Loading branch information
Pierre-Yves Fourmond committed Oct 26, 2023
1 parent 9752981 commit 06801c3
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 160 deletions.
29 changes: 15 additions & 14 deletions src/main/java/com/octo/ajava/infra/api_client/TMDBHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,29 @@ public class TMDBHttpClient {
private WebClient webClient;

public TMDBHttpClient(
@Value("${tmdb.baseUrl}") String urlTmdb,
@Value("${tmdb.token}") String jetonTmdb
) {
webClient = WebClient.builder()
@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();
return webClient
.get()
.uri("/movie/popular")
.retrieve()
.bodyToMono(PaginatedTMDBMovies.class)
.block();
}

public PaginatedTMDBMovies chercherDesFilms(String query) {
return webClient.get()
.uri("/search/movie?query=" + query)
.retrieve()
.bodyToMono(PaginatedTMDBMovies.class)
.block();
return webClient
.get()
.uri("/search/movie?query=" + query)
.retrieve()
.bodyToMono(PaginatedTMDBMovies.class)
.block();
}
}
28 changes: 17 additions & 11 deletions src/main/java/com/octo/ajava/infra/mapper/TMDBFilmMapper.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
package com.octo.ajava.infra.mapper;

import static java.util.Collections.emptyList;

import com.octo.ajava.domain.Film;
import com.octo.ajava.infra.api_client.entities.PaginatedTMDBMovies;
import java.util.Collections;
import com.octo.ajava.infra.api_client.entities.TMDBMovie;
import java.util.ArrayList;
import java.util.List;

import static java.util.Collections.emptyList;
import org.springframework.stereotype.Component;

@Component
public class TMDBFilmMapper {

public List<Film> convertirEnFilms(PaginatedTMDBMovies paginatedTMDBMovies) {
var movies = paginatedTMDBMovies.getMovies();
List<TMDBMovie> movies = paginatedTMDBMovies.getMovies();

if (movies == null) {
return emptyList();
}

return movies.stream().map(tmdbMovie -> new Film(
tmdbMovie.getId(),
tmdbMovie.getTitle(),
tmdbMovie.getOverview(),
emptyList(),
tmdbMovie.getReleaseDate()
)).toList();
List<Film> list = new ArrayList<>();
for (TMDBMovie movie : movies) {
Film film =
new Film(
movie.getId(),
movie.getTitle(),
movie.getOverview(),
emptyList(),
movie.getReleaseDate());
list.add(film);
}
return list;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.octo.ajava.domain.Film;
import com.octo.ajava.domain.repositories.FilmRepository;
import com.octo.ajava.infra.api_client.TMDBHttpClient;
import com.octo.ajava.infra.api_client.entities.TMDBMovie;
import com.octo.ajava.infra.api_client.entities.PaginatedTMDBMovies;
import com.octo.ajava.infra.mapper.TMDBFilmMapper;
import java.util.List;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand All @@ -23,8 +23,7 @@ public TMDBFilmRepository(TMDBHttpClient tmdbHttpClient, TMDBFilmMapper tmdbFilm

@Override
public List<Film> recupererLesFilms() {
var tmdbResponse =
this.tmdbHttpClient.recupererLesFilmsPopulaires();
return this.tmdbFilmMapper.convertirEnFilms(tmdbResponse);
PaginatedTMDBMovies paginatedTMDBMovies = this.tmdbHttpClient.recupererLesFilmsPopulaires();
return this.tmdbFilmMapper.convertirEnFilms(paginatedTMDBMovies);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ springdoc.swagger-ui.docExpansion=none
# valeurs possibles: IN_MEMORY ou TMDB
film.source=TMDB
tmdb.baseUrl=https://api.themoviedb.org/3
tmdb.token=${TMDB_JETON_ACCES}
tmdb.token=${TMDB_JETON_ACCES}
32 changes: 15 additions & 17 deletions src/test/java/com/octo/ajava/ObjectMapperBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,27 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;

import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.SignStyle;
import java.time.temporal.ChronoField;

public class ObjectMapperBuilder {

public static final DateTimeFormatter FORMATEUR_DATE =
(new DateTimeFormatterBuilder())
.appendValue(ChronoField.DAY_OF_MONTH, 2)
.appendLiteral('/')
.appendValue(ChronoField.MONTH_OF_YEAR, 2)
.appendLiteral('/')
.appendValue(ChronoField.YEAR_OF_ERA, 4, 10, SignStyle.EXCEEDS_PAD)
.toFormatter();

public static ObjectMapper handle() {
var objectMapper = new ObjectMapper();
JavaTimeModule javaTimeModule = new JavaTimeModule();
javaTimeModule.addSerializer(new LocalDateSerializer(FORMATEUR_DATE));
objectMapper.registerModule(javaTimeModule);
private static final DateTimeFormatter FORMATEUR_DATE =
(new DateTimeFormatterBuilder())
.appendValue(ChronoField.DAY_OF_MONTH, 2)
.appendLiteral('/')
.appendValue(ChronoField.MONTH_OF_YEAR, 2)
.appendLiteral('/')
.appendValue(ChronoField.YEAR_OF_ERA, 4, 10, SignStyle.EXCEEDS_PAD)
.toFormatter();

return objectMapper;
}
public static ObjectMapper handle() {
var objectMapper = new ObjectMapper();
JavaTimeModule javaTimeModule = new JavaTimeModule();
javaTimeModule.addSerializer(new LocalDateSerializer(FORMATEUR_DATE));
objectMapper.registerModule(javaTimeModule);
return objectMapper;
}
}
53 changes: 25 additions & 28 deletions src/test/java/com/octo/ajava/fixture/FilmFixture.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
package com.octo.ajava.fixture;

import com.octo.ajava.domain.Film;
import static java.util.Collections.emptyList;

import com.octo.ajava.domain.Film;
import java.time.LocalDate;
import java.util.List;

public class FilmFixture {

public static List<Film> deuxFilmsPopulaires() {
return List.of(
new Film(
502356,
"The Super Mario Bros. Movie",
"While working underground to fix a water main, Brooklyn plumbers—and brothers—Mario and Luigi are transported down a mysterious pipe and wander into a magical new world. But when the brothers are separated, Mario embarks on an epic quest to find Luigi.",
emptyList(),
LocalDate.of(2023, 4, 5)
),
new Film(
76600,
"Avatar: The Way of Water",
"Set more than a decade after the events of the first film, learn the story of the Sully family (Jake, Neytiri, and their kids), the trouble that follows them, the lengths they go to keep each other safe, the battles they fight to stay alive, and the tragedies they endure.",
emptyList(),
LocalDate.of(2022, 12, 14)
)
);
new Film(
502356,
"The Super Mario Bros. Movie",
"While working underground to fix a water main, Brooklyn plumbers—and brothers—Mario and Luigi are transported down a mysterious pipe and wander into a magical new world. But when the brothers are separated, Mario embarks on an epic quest to find Luigi.",
emptyList(),
LocalDate.of(2023, 4, 5)),
new Film(
76600,
"Avatar: The Way of Water",
"Set more than a decade after the events of the first film, learn the story of the Sully family (Jake, Neytiri, and their kids), the trouble that follows them, the lengths they go to keep each other safe, the battles they fight to stay alive, and the tragedies they endure.",
emptyList(),
LocalDate.of(2022, 12, 14)));
}

public static List<Film> deuxFilmsRecherches() {
return List.of(
new Film(
414906,
"The Batman",
"In his second year of fighting crime, Batman uncovers corruption in Gotham City that connects to his own family while facing a serial killer known as the Riddler.",
List.of(),
LocalDate.of(2022, 3, 1)),
new Film(
272,
"Batman Begins",
"Driven by tragedy, billionaire Bruce Wayne dedicates his life to uncovering and defeating the corruption that plagues his home, Gotham City. Unable to work within the system, he instead creates a new identity, a symbol of fear for the criminal underworld - The Batman.",
List.of(),
LocalDate.of(2005, 6, 10)));
new Film(
414906,
"The Batman",
"In his second year of fighting crime, Batman uncovers corruption in Gotham City that connects to his own family while facing a serial killer known as the Riddler.",
List.of(),
LocalDate.of(2022, 3, 1)),
new Film(
272,
"Batman Begins",
"Driven by tragedy, billionaire Bruce Wayne dedicates his life to uncovering and defeating the corruption that plagues his home, Gotham City. Unable to work within the system, he instead creates a new identity, a symbol of fear for the criminal underworld - The Batman.",
List.of(),
LocalDate.of(2005, 6, 10)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public class TMDBJsonResponseFixture {

public static String deuxFilms() {
return """
public static String deuxFilms() {
return """
{
"page": 1,
"results": [
Expand Down Expand Up @@ -52,5 +52,5 @@ public static String deuxFilms() {
"total_results": 146
}
""";
}
}
}
91 changes: 42 additions & 49 deletions src/test/java/com/octo/ajava/fixture/TMDBMovieFixture.java
Original file line number Diff line number Diff line change
@@ -1,59 +1,52 @@
package com.octo.ajava.fixture;

import com.octo.ajava.infra.api_client.entities.TMDBMovie;

import java.time.LocalDate;
import java.util.List;

public class TMDBMovieFixture {

public static List<TMDBMovie> deuxFilmsPopulairesVenantDeTMTB() {
return List.of(
new TMDBMovie(
502356,
"The Super Mario Bros. Movie",
"en",
"The Super Mario Bros. Movie",
"While working underground to fix a water main, Brooklyn plumbers—and brothers—Mario and Luigi are transported down a mysterious pipe and wander into a magical new world. But when the brothers are separated, Mario embarks on an epic quest to find Luigi.",
LocalDate.of(2023, 4, 5),
8501,
8
),
new TMDBMovie(
76600,
"Avatar: The Way of Water",
"en",
"Avatar: The Way of Water",
"Set more than a decade after the events of the first film, learn the story of the Sully family (Jake, Neytiri, and their kids), the trouble that follows them, the lengths they go to keep each other safe, the battles they fight to stay alive, and the tragedies they endure.",
LocalDate.of(2022, 12, 14),
1453,
8
)
);
}
public static List<TMDBMovie> deuxFilmsPopulairesVenantDeTMTB() {
return List.of(
new TMDBMovie(
502356,
"The Super Mario Bros. Movie",
"en",
"The Super Mario Bros. Movie",
"While working underground to fix a water main, Brooklyn plumbers—and brothers—Mario and Luigi are transported down a mysterious pipe and wander into a magical new world. But when the brothers are separated, Mario embarks on an epic quest to find Luigi.",
LocalDate.of(2023, 4, 5),
8501,
8),
new TMDBMovie(
76600,
"Avatar: The Way of Water",
"en",
"Avatar: The Way of Water",
"Set more than a decade after the events of the first film, learn the story of the Sully family (Jake, Neytiri, and their kids), the trouble that follows them, the lengths they go to keep each other safe, the battles they fight to stay alive, and the tragedies they endure.",
LocalDate.of(2022, 12, 14),
1453,
8));
}

public static List<TMDBMovie> deuxFilmsRecherchesVenantDeTMTB() {
return List.of(
new TMDBMovie(
414906,
"The Batman",
"en",
"The Batman",
"In his second year of fighting crime, Batman uncovers corruption in Gotham City that connects to his own family while facing a serial killer known as the Riddler.",
LocalDate.of(2022, 3, 1),
153,
8
),
new TMDBMovie(
272,
"Batman Begins",
"en",
"Batman Begins",
"Driven by tragedy, billionaire Bruce Wayne dedicates his life to uncovering and defeating the corruption that plagues his home, Gotham City. Unable to work within the system, he instead creates a new identity, a symbol of fear for the criminal underworld - The Batman.",
LocalDate.of(2005, 6, 10),
42,
8
)
);
}
public static List<TMDBMovie> deuxFilmsRecherchesVenantDeTMTB() {
return List.of(
new TMDBMovie(
414906,
"The Batman",
"en",
"The Batman",
"In his second year of fighting crime, Batman uncovers corruption in Gotham City that connects to his own family while facing a serial killer known as the Riddler.",
LocalDate.of(2022, 3, 1),
153,
8),
new TMDBMovie(
272,
"Batman Begins",
"en",
"Batman Begins",
"Driven by tragedy, billionaire Bruce Wayne dedicates his life to uncovering and defeating the corruption that plagues his home, Gotham City. Unable to work within the system, he instead creates a new identity, a symbol of fear for the criminal underworld - The Batman.",
LocalDate.of(2005, 6, 10),
42,
8));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.verify;

import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
import com.github.tomakehurst.wiremock.junit5.WireMockTest;
import com.octo.ajava.fixture.TMDBJsonResponseFixture;
Expand All @@ -21,7 +22,8 @@ class TMDBHttpClientITest {

private TMDBHttpClient tmdbHttpClient;

@Value("${tmdb.token}") String jetonTmdb;
@Value("${tmdb.token}")
String jetonTmdb;

@BeforeAll()
public void prepare(WireMockRuntimeInfo wmRuntimeInfo) {
Expand All @@ -37,9 +39,8 @@ public void recupererLesFilmsPopulaires() {
var result = tmdbHttpClient.recupererLesFilmsPopulaires();

// then
verify(getRequestedFor(
urlEqualTo("/movie/popular"))
.withHeader("Authorization", equalTo("Bearer " + jetonTmdb))
);
verify(
getRequestedFor(urlEqualTo("/movie/popular"))
.withHeader("Authorization", equalTo("Bearer " + jetonTmdb)));
}
}
}
Loading

0 comments on commit 06801c3

Please sign in to comment.