This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example; | |
import org.springframework.stereotype.Controller; | |
@Controller | |
public class SalarioMinimoController { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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")); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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"; |