Skip to content

Commit 6cf4d1d

Browse files
Refatorando para simplificação de código: - Removido CRUD de usuario e sistema. - Alterando versão do JUnit para usar o JUnit 5 para testes mais significativos. - Criado teste de lançamento de gastos
1 parent 777ed7a commit 6cf4d1d

File tree

15 files changed

+117
-303
lines changed

15 files changed

+117
-303
lines changed

testeSantanderWay/pom.xml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
<properties>
2121
<java.version>1.8</java.version>
22-
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
22+
<junit-jupiter.version>5.3.2</junit-jupiter.version>
23+
<mockito.version>2.24.0</mockito.version>
2324
</properties>
2425

2526
<dependencies>
@@ -109,7 +110,28 @@
109110
<groupId>org.springframework.boot</groupId>
110111
<artifactId>spring-boot-starter-test</artifactId>
111112
<scope>test</scope>
113+
<exclusions>
114+
<exclusion>
115+
<groupId>junit</groupId>
116+
<artifactId>junit</artifactId>
117+
</exclusion>
118+
</exclusions>
112119
</dependency>
120+
121+
<dependency>
122+
<groupId>org.junit.jupiter</groupId>
123+
<artifactId>junit-jupiter-engine</artifactId>
124+
<version>${junit-jupiter.version}</version>
125+
<scope>test</scope>
126+
</dependency>
127+
128+
<dependency>
129+
<groupId>org.mockito</groupId>
130+
<artifactId>mockito-core</artifactId>
131+
<version>${mockito.version}</version>
132+
<scope>test</scope>
133+
</dependency>
134+
113135
</dependencies>
114136

115137
<dependencyManagement>
@@ -130,6 +152,11 @@
130152
<groupId>org.springframework.boot</groupId>
131153
<artifactId>spring-boot-maven-plugin</artifactId>
132154
</plugin>
155+
<plugin>
156+
<groupId>org.apache.maven.plugins</groupId>
157+
<artifactId>maven-surefire-plugin</artifactId>
158+
<version>2.22.0</version>
159+
</plugin>
133160
</plugins>
134161
</build>
135162
</project>

testeSantanderWay/src/main/java/br/com/testesantanderway/config/security/AutenticacaoService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package br.com.testesantanderway.config.security;
22

33
import br.com.testesantanderway.modelo.Sistema;
4-
import br.com.testesantanderway.repository.ClienteRepository;
4+
import br.com.testesantanderway.repository.SistemaRepository;
55
import org.springframework.beans.factory.annotation.Autowired;
66
import org.springframework.security.core.userdetails.UserDetails;
77
import org.springframework.security.core.userdetails.UserDetailsService;
@@ -14,7 +14,7 @@
1414
public class AutenticacaoService implements UserDetailsService {
1515

1616
@Autowired
17-
private ClienteRepository repository;
17+
private SistemaRepository repository;
1818

1919
@Override
2020
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

testeSantanderWay/src/main/java/br/com/testesantanderway/config/security/AutenticacaoViaTokenFilter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package br.com.testesantanderway.config.security;
22

33
import br.com.testesantanderway.modelo.Sistema;
4-
import br.com.testesantanderway.repository.ClienteRepository;
4+
import br.com.testesantanderway.repository.SistemaRepository;
55
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
66
import org.springframework.security.core.context.SecurityContextHolder;
77
import org.springframework.web.filter.OncePerRequestFilter;
@@ -16,9 +16,9 @@ public class AutenticacaoViaTokenFilter extends OncePerRequestFilter {
1616
private static final String BEARER = "Bearer ";
1717

1818
private ServicoDeToken tokenService;
19-
private ClienteRepository repository;
19+
private SistemaRepository repository;
2020

21-
public AutenticacaoViaTokenFilter(ServicoDeToken tokenService, ClienteRepository repository) {
21+
public AutenticacaoViaTokenFilter(ServicoDeToken tokenService, SistemaRepository repository) {
2222
this.tokenService = tokenService;
2323
this.repository = repository;
2424
}

testeSantanderWay/src/main/java/br/com/testesantanderway/config/security/ConfigSeguranca.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package br.com.testesantanderway.config.security;
22

3-
import br.com.testesantanderway.repository.ClienteRepository;
3+
import br.com.testesantanderway.repository.SistemaRepository;
44
import org.springframework.beans.factory.annotation.Autowired;
55
import org.springframework.context.annotation.Bean;
66
import org.springframework.context.annotation.Configuration;
@@ -23,7 +23,7 @@ public class ConfigSeguranca extends WebSecurityConfigurerAdapter {
2323
@Autowired
2424
private ServicoDeToken tokenService;
2525
@Autowired
26-
private ClienteRepository clienteRepository;
26+
private SistemaRepository sistemaRepository;
2727

2828
@Override
2929
@Bean
@@ -54,7 +54,7 @@ protected void configure(HttpSecurity http) throws Exception {
5454
.anyRequest().authenticated()
5555
.and().csrf().disable()
5656
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
57-
.and().addFilterBefore(new AutenticacaoViaTokenFilter(tokenService, clienteRepository), UsernamePasswordAuthenticationFilter.class);
57+
.and().addFilterBefore(new AutenticacaoViaTokenFilter(tokenService, sistemaRepository), UsernamePasswordAuthenticationFilter.class);
5858
}
5959

6060
//Recursos estáticos(js, css, img, etc.)

testeSantanderWay/src/main/java/br/com/testesantanderway/controller/ClienteController.java

Lines changed: 0 additions & 91 deletions
This file was deleted.

testeSantanderWay/src/main/java/br/com/testesantanderway/controller/GastosController.java renamed to testeSantanderWay/src/main/java/br/com/testesantanderway/controller/GastoController.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import br.com.testesantanderway.dto.GastosDTO;
88
import br.com.testesantanderway.modelo.Gasto;
99
import br.com.testesantanderway.repository.GastoRepository;
10+
import br.com.testesantanderway.service.GastoService;
1011
import org.springframework.beans.factory.annotation.Autowired;
1112
import org.springframework.cache.annotation.Cacheable;
1213
import org.springframework.data.domain.Page;
@@ -21,13 +22,16 @@
2122

2223
@RestController
2324
@RequestMapping("/gastos")
24-
public class GastosController {
25+
public class GastoController {
2526
@Autowired
2627
private ServicoDeToken servicoDeToken;
2728

2829
@Autowired
2930
private GastoRepository gastoRepository;
3031

32+
@Autowired
33+
private GastoService gastoService;
34+
3135
@GetMapping
3236
@Cacheable(value = "gastoDeCliente")
3337
public Page<GastosDTO> listagemDeGastos(@RequestParam(required = false) String descricao,
@@ -49,8 +53,7 @@ public Page<GastosDTO> listagemDeGastos(@RequestParam(required = false) String d
4953
@PutMapping
5054
public ResponseEntity lancarGastosCartao(HttpServletRequest request, @RequestBody GastoForm form) {
5155
Gasto gasto = form.converter(servicoDeToken.getCodigo(AutenticacaoViaTokenFilter.recuperarToken(request)));
52-
integrarCategoria(gasto);
53-
gastoRepository.save(gasto);
56+
gastoService.lancarGastosCartao(gasto);
5457
return ResponseEntity.ok().build();
5558
}
5659

@@ -74,12 +77,4 @@ public ResponseEntity<DetalheGastosDTO> listagemDeGastosPorData(@PathVariable St
7477
// return ResponseEntity.created(uri).body(new GastosDTO(categoriaCadastro));
7578
// }
7679

77-
private void integrarCategoria(Gasto gasto){
78-
if(gasto.getCategoria() == null){
79-
Optional<String> categoria = gastoRepository.findCategoriaByDescricao(gasto.getDescricao());
80-
if(categoria.isPresent()){
81-
gasto.setCategoria(categoria.get());
82-
}
83-
}
84-
}
8580
}

testeSantanderWay/src/main/java/br/com/testesantanderway/controller/UsuarioController.java

Lines changed: 0 additions & 86 deletions
This file was deleted.

testeSantanderWay/src/main/java/br/com/testesantanderway/controller/form/AtualizacaoClienteForm.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package br.com.testesantanderway.controller.form;
22

33
import br.com.testesantanderway.modelo.Sistema;
4-
import br.com.testesantanderway.repository.ClienteRepository;
4+
import br.com.testesantanderway.repository.SistemaRepository;
55
import org.hibernate.validator.constraints.Length;
66
import javax.validation.constraints.NotEmpty;
77
import javax.validation.constraints.NotNull;
@@ -36,13 +36,13 @@ public void setSenha(String senha) {
3636
this.senha = senha;
3737
}
3838

39-
public Sistema atualizar(String id, ClienteRepository clienteRepository) {
40-
Sistema sistema = clienteRepository.findById(id).orElseThrow(() -> new RuntimeException("Não encontrado"));
39+
public Sistema atualizar(String id, SistemaRepository sistemaRepository) {
40+
Sistema sistema = sistemaRepository.findById(id).orElseThrow(() -> new RuntimeException("Não encontrado"));
4141

4242
sistema.setEmail(this.email);
4343
sistema.setSenha(this.senha);
4444

45-
clienteRepository.save(sistema);
45+
sistemaRepository.save(sistema);
4646

4747
return sistema;
4848
}

0 commit comments

Comments
 (0)