package com.poseidon.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.web.servlet.MockMvc;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;


import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup;


public class PacienteControllerIntegrationTest extends PoseidonApplicationTests {

    private MockMvc mockMvc;

    @Autowired
    private PacienteController pacienteController;

    @BeforeMethod
    public void setUp(){
        mockMvc= standaloneSetup(pacienteController).build();
    }

    @Test
    public void paciente_cadastro() throws Exception {
        this.mockMvc.perform(get("/user/paciente")
                .param("isCadastroPaciente","true")
                .param("isDeletePaciente","false")
                .param("isPesquisaPaciente","false"))
                .andExpect(view().name("Paciente"))
                .andExpect(model().attribute("isCadastroPaciente","true"))
                .andExpect(model().attribute("isDeletePaciente","false"))
                .andExpect(model().attribute("isPesquisaPaciente","false"))
                .andExpect(model().attributeExists("cadastroPageModel"))
                .andExpect(model().attributeExists("paciente"));
    }


    @Test
    public void paciente_delete() throws Exception {
        this.mockMvc.perform(get("/user/paciente")
                .param("isCadastroPaciente","false")
                .param("isDeletePaciente","true")
                .param("isPesquisaPaciente","false"))
                .andExpect(view().name("Paciente"))
                .andExpect(model().attribute("isCadastroPaciente","false"))
                .andExpect(model().attribute("isDeletePaciente","true"))
                .andExpect(model().attribute("isPesquisaPaciente","false"))
                .andExpect(model().attributeExists("cadastroPageModel"))
                .andExpect(model().attributeExists("paciente"));
    }

    @Test
    public void paciente_pesquisa() throws Exception {
        this.mockMvc.perform(get("/user/paciente")
                .param("isCadastroPaciente","false")
                .param("isDeletePaciente","false")
                .param("isPesquisaPaciente","true"))
                .andExpect(view().name("Paciente"))
                .andExpect(model().attribute("isCadastroPaciente","false"))
                .andExpect(model().attribute("isDeletePaciente","false"))
                .andExpect(model().attribute("isPesquisaPaciente","true"))
                .andExpect(model().attributeExists("cadastroPageModel"))
                .andExpect(model().attributeExists("paciente"));
    }

    @Test
    public void pesquisarPaciente() throws Exception {
        this.mockMvc.perform(get("/user/pesquisarPaciente"))
                .andExpect(view().name("redirect:/user/paciente?" +
                        "isCadastroPaciente=false" +
                        "&isDeletePaciente=false" +
                        "&isPesquisaPaciente=true"));
    }

    @Test
    public void cadastrarPaciente() throws Exception {
        this.mockMvc.perform(get("/user/cadastrarPaciente")
                .param("nome","Frodo"))
                .andExpect(view().name("redirect:/user/paciente?" +
                        "isCadastroPaciente=true" +
                        "&isDeletePaciente=false" +
                        "&isPesquisaPaciente=false"));
    }



    @Test
    public void editarPaciente() throws Exception {
        this.mockMvc.perform(get("/user/cadastrarPaciente")
                .param("nome","Sam"))
                .andExpect(view().name("redirect:/user/paciente?" +
                        "isCadastroPaciente=true" +
                        "&isDeletePaciente=false&" +
                        "isPesquisaPaciente=false"));

        this.mockMvc.perform(get("/user/editarPaciente")
                .param("id","76")
                .param("nome","Mordor"))
                .andExpect(view().name("/paciente"));
    }

    @Test
    public void procurarPaciente() throws Exception {
        this.mockMvc.perform(get("/user/cadastrarPaciente")
                .param("nome","Saruman"))
                .andExpect(view().name("redirect:/user/paciente?" +
                        "isCadastroPaciente=true" +
                        "&isDeletePaciente=false" +
                        "&isPesquisaPaciente=false"));


        this.mockMvc.perform(get("/user/procurarPaciente")
                .param("nome","Saruman"))
                .andExpect(view().name("Paciente"));
    }

}

@@ -225,16 +225,71 @@
 .Test;%0A%0A
+import static org.hamcrest.CoreMatchers.containsString;
 %0Aimport 
@@ -4385,32 +4385,47 @@
 procurarPaciente
+CaseInsensitive
 () throws Except
@@ -4462,38 +4462,37 @@
 form(get(%22/user/
-cadast
+procu
 rarPaciente%22)%0A  
@@ -4512,37 +4512,33 @@
  .param(%22nome%22,%22
-Sarum
+g
 an%22))%0A          
@@ -4571,196 +4571,194 @@
 me(%22
-redirect:/user/paciente?%22 +%0A                        %22isCadastroPaciente=true%22 +%0A                        %22&isDeletePaciente=false%22 +%0A                        %22&isPesquisaPaciente=false%22));%0A%0A
+Paciente%22))%0A                .andExpect(model().attribute(%22pacientesJSON%22, containsString(%22Gandalf%22)));%0A    %7D%0A%0A    @Test%0A    public void procurarPacienteCaseSensitive() throws Exception %7B
 %0A   
@@ -4848,15 +4848,15 @@
 e%22,%22
-Saruman
+gandalf
 %22))%0A
@@ -4898,27 +4898,117 @@
 ame(%22Paciente%22))
+%0A                .andExpect(model().attribute(%22pacientesJSON%22, containsString(%22Gandalf%22)))
 ;%0A    %7D%0A%0A%7D%0A

add tests for case sensitive and case insensitive search #79