Skip to content
Snippets Groups Projects
Commit 666f2ec9 authored by Yvan Peter's avatar Yvan Peter
Browse files

Premier test valide

Les librairies de sécurité ont été enlevées du pom pour accéder aux méthodes sans authentification
parent 297417ea
Branches
No related tags found
No related merge requests found
...@@ -24,10 +24,11 @@ ...@@ -24,10 +24,11 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> </dependency>
<!-- remove to avoid 401 for the moment
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId> <artifactId>spring-boot-starter-security</artifactId>
</dependency> </dependency> -->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
...@@ -59,11 +60,13 @@ ...@@ -59,11 +60,13 @@
<artifactId>spring-restdocs-mockmvc</artifactId> <artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- removed to avoid 401
<dependency> <dependency>
<groupId>org.springframework.security</groupId> <groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId> <artifactId>spring-security-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
-->
</dependencies> </dependencies>
<build> <build>
......
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
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
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment