Skip to content

Commit

Permalink
Formatage tp-1 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 982f148 commit 910d083
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 51 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies {
// à décommenter lors du tp4
// implementation "org.springframework.security:spring-security-config:${springSecurityVersion}"
// implementation "org.springframework.security:spring-security-oauth2-client:${springSecurityVersion}"
// testImplementation "org.springframework.security:spring-security-test:${springSecurityVersion}"

implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:${springDocVersion}"

Expand All @@ -47,7 +48,6 @@ dependencies {
implementation 'me.paulschwarz:spring-dotenv:3.0.0'

testImplementation "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
// testImplementation "org.springframework.security:spring-security-test:${springSecurityVersion}"
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
testImplementation 'org.testcontainers:junit-jupiter'
testImplementation 'org.testcontainers:postgresql'
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/octo/ajava/AjavaApplication.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.octo.ajava;

import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.SignStyle;
import java.time.temporal.ChronoField;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand Down
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;
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.octo.ajava.domain.usecases;

import com.octo.ajava.domain.Film;
import static com.octo.ajava.fixture.FilmFixture.deuxFilmsPopulaires;
import com.octo.ajava.infra.repositories.InMemoryFilmRepository;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;

import com.octo.ajava.domain.Film;
import com.octo.ajava.infra.repositories.InMemoryFilmRepository;
import java.util.List;
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 Down
30 changes: 13 additions & 17 deletions src/test/java/com/octo/ajava/fixture/FilmFixture.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
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)));
}

}
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
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

// When
var response = RestAssured.given()
var response =
RestAssured.given()
.get("/api/films")
.then()
.statusCode(HttpStatus.OK.value())
.extract().response().asString();
.extract()
.response()
.asString();

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

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

0 comments on commit 910d083

Please sign in to comment.