Commit 442fcd30 authored by benhoumine's avatar benhoumine

test

parent 25c467df
...@@ -39,8 +39,9 @@ public class Poubelle implements Serializable{ ...@@ -39,8 +39,9 @@ public class Poubelle implements Serializable{
} }
public Poubelle() { public Poubelle() {
super(); super();
} }
public Poubelle(Long id, Double longitude, Double latitude, Double capacity) { public Poubelle(Long id, Double longitude, Double latitude, Double capacity) {
super(); super();
this.id = id; this.id = id;
......
package isima.F2; package isima.F2;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
@SpringBootTest @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
class RamassagePoubleDepotApplicationTests { class RamassagePoubleDepotApplicationTests {
@LocalServerPort
private int port;
@Autowired
private TestRestTemplate restTemplate;
@Test @Test
void contextLoads() { public void testRunServerRamassageAppTest() throws Exception {
assertThat(this.restTemplate.getForObject("http://localhost:" + port + "/",
String.class)).isNotEmpty();
} }
} }
package isima.F2.controller;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.ArrayList;
import java.util.List;
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.boot.test.mock.mockito.MockBean;
import org.springframework.test.web.servlet.MockMvc;
import isima.f2.controllers.PoubelleController;
import isima.f2.model.Poubelle;
import isima.f2.services.ImpPoubelle;
@WebMvcTest(PoubelleController.class)
public class PoubelleControllerTest {
@MockBean
private ImpPoubelle service;
@Autowired
private MockMvc mockMvc;
@Test
public void verificationGetPoubellesMethode() throws Exception {
List<Poubelle> listRes = new ArrayList();
listRes.add(new Poubelle());
//Return null car Il n'y pas une initialisation de constructeur
when(service.getPoubelles()).thenReturn(listRes);
this.mockMvc.perform(get("/poubelles/")).andDo(print()).andExpect(status().isOk())
.andExpect(content().string(containsString("\"id\":null")));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment