Skip to content

Commit

Permalink
mise à jour avec les nouveaux tests de master
Browse files Browse the repository at this point in the history
  • Loading branch information
OCTO-CLEM committed May 29, 2023
1 parent a3127ac commit bbace13
Show file tree
Hide file tree
Showing 17 changed files with 172 additions and 185 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Pour démarrer l'application, jouer la commande suivante :
./gradlew.bat bootRun
```

L'application démarre sur le port par défaut de Spring-Boot, **8080**.
L'application démarre sur le port par défaut de Spring-Boot, **8080**. <br>
Et swagger se trouve ici : http://localhost:8080/swagger-ui/index.html
### La base de données
Expand All @@ -41,16 +42,19 @@ fichier `docker-compose.yml`
---
## Prerequis pour l'API TMDB

- Doc pour le tp 2 : https://developer.themoviedb.org/reference/movie-popular-list
- Doc pour le tp 3 : https://developer.themoviedb.org/reference/search-movie
- Doc pour le tp 7 : https://developer.themoviedb.org/reference/movie-details

# TP 1 - Lister des Films

* Objectif : Exposer la liste des films sur la route `http://localhost:8080/api/films`
* Compléter le usecase `RecupererLesFilmsUseCase`, afin qu'il renvoie la liste de films "in memory"
* Il existe une classe avec des `InMemoryFilmRepository` avec des fausses donneés dedans vous pouvez vous en servir
* Se servir de l'Injection de Dépendence pour utiliser un `FilmRepository`
## Accès à l'API avec Swagger-UI

Ouvrir la page http://localhost:8080/swagger-ui/index.html
![Swagger UI](doc/img/swagger.png)
* Vous pourrez aussi avant de démarrer le swagger pour tester l'application corriger ou écrire les tests existants pour chaques classes
---
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ dependencies {
testImplementation "org.mockito:mockito-core:${mockitoVersion}"
testImplementation "org.mockito:mockito-junit-jupiter:${mockitoVersion}"

testImplementation "io.rest-assured:rest-assured:5.2.0"

}

spotless {
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/com/octo/ajava/AjavaApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@
@SpringBootApplication
public class AjavaApplication {

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 void main(String[] args) {
SpringApplication.run(AjavaApplication.class, args);
}
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/.env

This file was deleted.

1 change: 1 addition & 0 deletions src/main/resources/.env.exemple
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TMDB_JETON_ACCES=<METTRE ICI LE JETON TMDB>
22 changes: 19 additions & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
########## SPRING
server.port=8080
server.servlet.session.timeout=60
########## DB
spring.datasource.url=jdbc:postgresql://localhost:15432/ajavadb
spring.datasource.username=admin
spring.datasource.password=passwd
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.open-in-view=false
spring.jpa.properties.jakarta.persistence.sharedCache.mode=NONE
########## SECURITY
spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:8090/realms/octo
spring.session.timeout=60
########## SWAGGER UI
########## SWAGGER
springdoc.swagger-ui.docExpansion=none
########## CHOIX FILM REPO
springdoc.swagger-ui.oauth.clientId=octo-api
springdoc.swagger-ui.oauth.clientSecret=uAUgImRefxbqHLafd4LbCU9kiQevHgUc
springdoc.swagger-ui.tagsSorter=alpha
########## API TMDB
tmdb.baseUrl=https://api.themoviedb.org/3
# /!\ Attention ! Ne pas commit des secrets dans le git !
tmdb.token=${TMDB_JETON_ACCES}
########## CHOIX FILM REPOS
# valeurs possibles: IN_MEMORY ou TMDB
film.source=IN_MEMORY
film.source=IN_MEMORY
29 changes: 0 additions & 29 deletions src/test/java/com/octo/ajava/ApiIntegrationTest.java

This file was deleted.

31 changes: 31 additions & 0 deletions src/test/java/com/octo/ajava/ObjectMapperBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.octo.ajava;

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);

return objectMapper;
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.octo.ajava.domain.usecases;

import static com.octo.ajava.fixture.FilmFixture.uneListeDeFilms;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;

import com.octo.ajava.domain.Film;
import static com.octo.ajava.fixture.FilmFixture.deuxFilmsPopulaires;
import com.octo.ajava.infra.repositories.InMemoryFilmRepository;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.mockito.BDDMockito.given;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.List;

@ExtendWith(MockitoExtension.class)
public class RecupererLesFilmsUseCaseUTest {

Expand All @@ -22,7 +22,7 @@ public class RecupererLesFilmsUseCaseUTest {
@Test
void executer_devrait_renvoyer_une_liste_de_films_in_memory() {
// Given
List<Film> filmsAttendus = uneListeDeFilms();
List<Film> filmsAttendus = deuxFilmsPopulaires();
given(inMemoryFilmRepository.recupererLesFilms()).willReturn(filmsAttendus);

// When
Expand Down
62 changes: 18 additions & 44 deletions src/test/java/com/octo/ajava/fixture/FilmFixture.java
Original file line number Diff line number Diff line change
@@ -1,56 +1,30 @@
package com.octo.ajava.fixture;

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

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

public class FilmFixture {

public static List<Film> uneListeDeFilms() {
return List.of(
new Film(
1,
"Pulp Fiction",
"Les vies de deux hommes de main...",
List.of("Policier", "Drame"),
LocalDate.of(1994, 9, 23)),
new Film(
2,
"Les Dents de la Mer",
"Un shérif local, un biologiste marin et un vieux marin...",
List.of("Aventure", "Thriller"),
LocalDate.of(1975, 6, 20)));
}

public static List<Film> deuxFilmsProvenantDeTMDB() {
public static List<Film> deuxFilmsPopulaires() {
return List.of(
new Film(
297761,
"Suicide Squad",
"From DC Comics comes the Suicide Squad...",
List.of(),
LocalDate.of(2016, 8, 3)),
new Film(
324668,
"Jason Bourne",
"The most dangerous former operative of the CIA...",
List.of(),
LocalDate.of(2016, 7, 27)));
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> deuxFilmsRecherchesProvenantDeTMDB() {
return List.of(
new Film(
414906,
"The Batman",
"In his second year of fighting crime, Batman...",
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...",
List.of(),
LocalDate.of(2005, 6, 23)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.octo.ajava.infra.controllers;

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
)
class FilmControllerFTest {

@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();

// Then
Film[] listeDeFilms = ObjectMapperBuilder.handle().readValue(response, Film[].class);

assertThat(listeDeFilms.length).isEqualTo(22);
}
}

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions src/test/resources/.env.exemple
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TMDB_JETON_ACCES=<METTRE ICI LE JETON TMDB>
Loading

0 comments on commit bbace13

Please sign in to comment.