From 666f2ec9b2446dd6a13ee0d26f81f13cdffb26e1 Mon Sep 17 00:00:00 2001 From: Yvan Peter <yvan.peter@univ-lille.fr> Date: Tue, 18 Feb 2020 13:23:07 +0100 Subject: [PATCH] Premier test valide MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Les librairies de sécurité ont été enlevées du pom pour accéder aux méthodes sans authentification --- pom.xml | 5 ++- .../controller/IngredientController.java | 19 ++++++++++++ .../pizzaland/representation/Ingredient.java | 31 +++++++++++++++++++ src/main/resources/application.properties | 1 - .../ulille/iut/pizzaland/IngredientTests.java | 21 +++++++++++++ 5 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/main/java/fr/ulille/iut/pizzaland/controller/IngredientController.java create mode 100644 src/main/java/fr/ulille/iut/pizzaland/representation/Ingredient.java create mode 100644 src/test/java/fr/ulille/iut/pizzaland/IngredientTests.java diff --git a/pom.xml b/pom.xml index e5beb63..73cd47c 100644 --- a/pom.xml +++ b/pom.xml @@ -24,10 +24,11 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> + <!-- remove to avoid 401 for the moment <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> - </dependency> + </dependency> --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> @@ -59,11 +60,13 @@ <artifactId>spring-restdocs-mockmvc</artifactId> <scope>test</scope> </dependency> + <!-- removed to avoid 401 <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-test</artifactId> <scope>test</scope> </dependency> + --> </dependencies> <build> diff --git a/src/main/java/fr/ulille/iut/pizzaland/controller/IngredientController.java b/src/main/java/fr/ulille/iut/pizzaland/controller/IngredientController.java new file mode 100644 index 0000000..3d004d4 --- /dev/null +++ b/src/main/java/fr/ulille/iut/pizzaland/controller/IngredientController.java @@ -0,0 +1,19 @@ +package fr.ulille.iut.pizzaland.controller; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import fr.ulille.iut.pizzaland.representation.Ingredient; + +@RestController +public class IngredientController { + + @GetMapping("/ingredients") + public List<Ingredient> getIngredients() { + return new ArrayList<Ingredient>(); + } + +} \ No newline at end of file diff --git a/src/main/java/fr/ulille/iut/pizzaland/representation/Ingredient.java b/src/main/java/fr/ulille/iut/pizzaland/representation/Ingredient.java new file mode 100644 index 0000000..2ba4fa2 --- /dev/null +++ b/src/main/java/fr/ulille/iut/pizzaland/representation/Ingredient.java @@ -0,0 +1,31 @@ +package fr.ulille.iut.pizzaland.representation; + +public class Ingredient { + private long id; + private String name; + + public Ingredient() { + } + + public Ingredient(long id, String name) { + this.id = id; + this.name = name; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8b13789..e69de29 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +0,0 @@ - diff --git a/src/test/java/fr/ulille/iut/pizzaland/IngredientTests.java b/src/test/java/fr/ulille/iut/pizzaland/IngredientTests.java new file mode 100644 index 0000000..1a6fe86 --- /dev/null +++ b/src/test/java/fr/ulille/iut/pizzaland/IngredientTests.java @@ -0,0 +1,21 @@ +package fr.ulille.iut.pizzaland; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.test.web.servlet.MockMvc; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +import fr.ulille.iut.pizzaland.controller.IngredientController; + +@WebMvcTest(IngredientController.class) +public class IngredientTests { + @Autowired + private MockMvc mvc; + + @Test + public void atStartup_shouldGetemptyList() throws Exception { + mvc.perform(get("/ingredients")).andExpect(status().isOk()).andExpect(content().json("[]")); + } +} \ No newline at end of file -- GitLab