Skip to content

Instantly share code, notes, and snippets.

View netodevel's full-sized avatar
🏠
Working from home

José Vieira Neto netodevel

🏠
Working from home
  • São Paulo, Brasil
View GitHub Profile
# DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.url=jdbc:mysql://localhost/meubanco_test
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.tomcat.test-on-borrow=true
spring.datasource.tomcat.validation-query=SELECT 1
spring.datasource.sql-script-encoding=UTF-8
# JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration)
spring.jpa.hibernate.naming.strategy=org.hibernate.cfg.ImprovedNamingStrategy
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import br.com.paydomestic.DemoApplication;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = DemoApplication.class)
import org.junit.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
public class SalarioMinimoControllerTest extends DemoApplicationTests {
private MockMvc mockMvc;
package com.example;
import org.springframework.stereotype.Controller;
@Controller
public class SalarioMinimoController {
}
package com.example;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
package com.example;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class SalarioMinimoController {
@GetMapping("/salarios")
package com.example;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
package com.example;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class SalarioMinimoController {
@Test
public void testPOSTSaveSalarioMinimoController() throws Exception {
this.mockMvc.perform(MockMvcRequestBuilders.post("/salarios")
.param("estado", "BR")
.param("salario", "800")
.param("dataInicio", "01/01/2016")
.param("dataFim", "02/02/2016")
).andExpect(MockMvcResultMatchers.redirectedUrl("/salarios/novo"));
}
@PostMapping("/salarios")
public String save(@Valid @ModelAttribute("salarioMinimo") SalarioMinimo salarioMinimo, BindingResult bindingResult, RedirectAttributes redirectAttributes) {
try {
salarioMinimoService.save(salarioMinimo);
redirectAttributes.addFlashAttribute("sucesso", "Salário salvo com sucesso.");
} catch (Exception e) {
e.printStackTrace();
redirectAttributes.addFlashAttribute("error", "Problema ao salvar salário.");
}
return "redirect:/salarios/novo";