refatorando
parent
27fa5053cb
commit
1b5bbd02c0
@ -1,10 +1,10 @@
|
||||
package br.com.ae3tecnologia.ms.tangerino.repository;
|
||||
|
||||
import br.com.ae3tecnologia.ms.tangerino.model.PtoAjusteModel;
|
||||
import br.com.ae3tecnologia.ms.tangerino.model.PtoAdjustModel;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface PtoAjusteRepository extends JpaRepository<PtoAjusteModel, Integer> {
|
||||
public interface PtoAdjustRepository extends JpaRepository<PtoAdjustModel, Integer> {
|
||||
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package br.com.ae3tecnologia.ms.tangerino.repository;
|
||||
|
||||
import br.com.ae3tecnologia.ms.tangerino.model.PtoEventoModel;
|
||||
import br.com.ae3tecnologia.ms.tangerino.model.PtoEventModel;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface PtoEventoRepository extends JpaRepository<PtoEventoModel, Integer> {
|
||||
public interface PtoEventRepository extends JpaRepository<PtoEventModel, Integer> {
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package br.com.ae3tecnologia.ms.tangerino.service;
|
||||
|
||||
import br.com.ae3tecnologia.ms.tangerino.model.PtoEquipamentModel;
|
||||
import br.com.ae3tecnologia.ms.tangerino.repository.PtoEquipamentRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class PtoEquipamentService {
|
||||
|
||||
@Autowired
|
||||
private PtoEquipamentRepository repository;
|
||||
|
||||
public List<PtoEquipamentModel> findByInativo(Boolean inativo){
|
||||
Optional optional = repository.findByInactiveEquals(inativo);
|
||||
if(optional.isPresent() && !optional.isEmpty()){
|
||||
return (List<PtoEquipamentModel>) optional.get();
|
||||
}
|
||||
return Arrays.asList();
|
||||
}
|
||||
|
||||
public PtoEquipamentModel save(PtoEquipamentModel equipamentoModel){
|
||||
return repository.save(equipamentoModel);
|
||||
}
|
||||
|
||||
public List<PtoEquipamentModel> findAll(){
|
||||
return repository.findAll();
|
||||
}
|
||||
|
||||
public PtoEquipamentModel findById(int id){
|
||||
Optional<PtoEquipamentModel> optional = repository.findById(id);
|
||||
return optional.isPresent() ? optional.get() : null;
|
||||
}
|
||||
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package br.com.ae3tecnologia.ms.tangerino.service;
|
||||
|
||||
import br.com.ae3tecnologia.ms.tangerino.model.PtoEquipamentoModel;
|
||||
import br.com.ae3tecnologia.ms.tangerino.repository.PtoEquipamentoRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class PtoEquipamentoService {
|
||||
@Autowired
|
||||
private PtoEquipamentoRepository repository;
|
||||
|
||||
public List<PtoEquipamentoModel> findByInativo(Boolean inativo){
|
||||
Optional optional = repository.findByInativoEquals(inativo);
|
||||
if(optional.isPresent() && !optional.isEmpty()){
|
||||
return (List<PtoEquipamentoModel>) optional.get();
|
||||
}
|
||||
return Arrays.asList();
|
||||
}
|
||||
|
||||
public PtoEquipamentoModel save(PtoEquipamentoModel equipamentoModel){
|
||||
return repository.save(equipamentoModel);
|
||||
}
|
||||
|
||||
public List<PtoEquipamentoModel> findAll(){
|
||||
return repository.findAll();
|
||||
}
|
||||
|
||||
public PtoEquipamentoModel findById(int id){
|
||||
Optional<PtoEquipamentoModel> optional = repository.findById(id);
|
||||
return optional.isPresent() ? optional.get() : null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package br.com.ae3tecnologia.ms.tangerino.service;
|
||||
|
||||
import br.com.ae3tecnologia.ms.tangerino.model.PtoEventModel;
|
||||
import br.com.ae3tecnologia.ms.tangerino.repository.PtoEventRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class PtoEventService {
|
||||
|
||||
@Autowired
|
||||
private PtoEventRepository repository;
|
||||
|
||||
public PtoEventModel save(PtoEventModel eventoModel){
|
||||
return repository.save(eventoModel);
|
||||
}
|
||||
|
||||
public List<PtoEventModel> findAll(){
|
||||
return repository.findAll();
|
||||
}
|
||||
|
||||
public PtoEventModel findById(int id){
|
||||
Optional<PtoEventModel> optional = repository.findById(id);
|
||||
return optional.isPresent() ? optional.get() : null;
|
||||
}
|
||||
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package br.com.ae3tecnologia.ms.tangerino.service;
|
||||
|
||||
import br.com.ae3tecnologia.ms.tangerino.model.PtoEventoModel;
|
||||
import br.com.ae3tecnologia.ms.tangerino.repository.PtoEventoRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class PtoEventoService {
|
||||
|
||||
@Autowired
|
||||
private PtoEventoRepository repository;
|
||||
|
||||
public PtoEventoModel save(PtoEventoModel eventoModel){
|
||||
return repository.save(eventoModel);
|
||||
}
|
||||
|
||||
public List<PtoEventoModel> findAll(){
|
||||
return repository.findAll();
|
||||
}
|
||||
|
||||
public PtoEventoModel findById(int id){
|
||||
Optional<PtoEventoModel> optional = repository.findById(id);
|
||||
return optional.isPresent() ? optional.get() : null;
|
||||
}
|
||||
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package br.com.ae3tecnologia.ms.tangerino.controller;
|
||||
|
||||
import br.com.ae3tecnologia.ms.tangerino.model.PtoEquipamentoModel;
|
||||
import br.com.ae3tecnologia.ms.tangerino.model.PtoEventoModel;
|
||||
import br.com.ae3tecnologia.ms.tangerino.service.PtoEquipamentoService;
|
||||
import br.com.ae3tecnologia.ms.tangerino.service.PtoEventoService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
class PtoEventoControllerTest {
|
||||
@Mock
|
||||
PtoEventoService eventoService;
|
||||
@Mock
|
||||
PtoEquipamentoService equipamentoService;
|
||||
@InjectMocks
|
||||
PtoEventoController controller;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deveExtrairPontos() {
|
||||
controller.extrairPontos();
|
||||
}
|
||||
|
||||
@Test
|
||||
void deveObterPontosPorRelogio() throws JsonProcessingException {
|
||||
// when(eventoService.)
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("employerId", 2775694);
|
||||
map.put("offset", 1037355);
|
||||
List<PtoEventoModel> ptoEventoModels = controller.obterPontosPorRelogio(map);
|
||||
Assertions.assertTrue(ptoEventoModels.size() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deveExtrairEventos(){
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void deveObterRelogios(){
|
||||
List<PtoEquipamentoModel> ptoEquipamentoModels = controller.obterRelogios(false);
|
||||
Assertions.assertNotEquals(null, ptoEquipamentoModels);
|
||||
Assertions.assertFalse(ptoEquipamentoModels.isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
//Generated with love by TestMe :) Please report issues and submit feature requests at: http://weirddev.com/forum#!/testme
|
@ -0,0 +1,96 @@
|
||||
package br.com.ae3tecnologia.ms.tangerino.controller;
|
||||
|
||||
import br.com.ae3tecnologia.ms.tangerino.model.PtoEquipamentModel;
|
||||
import br.com.ae3tecnologia.ms.tangerino.model.PtoEventModel;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class PtoExtractRestControllerTest {
|
||||
@Mock
|
||||
PtoExtractRestController controller;
|
||||
PtoEquipamentModel equipamento01;
|
||||
PtoEquipamentModel equipamento02;
|
||||
PtoEventModel evento01;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
equipamento01 = new PtoEquipamentModel(
|
||||
123,
|
||||
"00004004340003529",
|
||||
1,
|
||||
1,
|
||||
GregorianCalendar.getInstance().getTime(),
|
||||
null,
|
||||
"default",
|
||||
true
|
||||
);
|
||||
equipamento02 = new PtoEquipamentModel(
|
||||
124,
|
||||
"00004004330063478",
|
||||
1,
|
||||
1,
|
||||
GregorianCalendar.getInstance().getTime(),
|
||||
null,
|
||||
"default",
|
||||
true
|
||||
);
|
||||
evento01 = new PtoEventModel(
|
||||
1,
|
||||
123,
|
||||
1,
|
||||
LocalDate.now(),
|
||||
LocalTime.now(),
|
||||
"123123123123",
|
||||
123,
|
||||
123,
|
||||
false,
|
||||
1,
|
||||
"202304",
|
||||
LocalDateTime.now()
|
||||
);
|
||||
MockitoAnnotations.openMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void mustObteinPunchTangerinoAPIMock() throws JsonProcessingException {
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("serialNumber", equipamento01.getSerialNumber());
|
||||
map.put("page", 1);
|
||||
map.put("size", 50);
|
||||
when(controller.getToken()).thenReturn("1231231231313");
|
||||
when(controller.gePunchTangerinoAPI(map)).thenReturn(Arrays.asList(evento01));
|
||||
List<PtoEventModel> ptoEventModels = controller.gePunchTangerinoAPI(map);
|
||||
Assertions.assertTrue(ptoEventModels.size() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deveExtrairEventosMock() {
|
||||
when(controller.extractEventsAndReturnLastNsr(evento01.getNsr(), List.of(evento01), equipamento01)).thenReturn(Integer.valueOf("124"));
|
||||
Integer lastNsr = controller.extractEventsAndReturnLastNsr(evento01.getNsr(), Arrays.asList(evento01), equipamento01);
|
||||
Assertions.assertEquals(124, lastNsr);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deveObterRelogiosAtivosMock() {
|
||||
when(controller.getWatches(false)).thenReturn(Arrays.asList(equipamento01, equipamento02));
|
||||
List<PtoEquipamentModel> ptoEquipamentModels = controller.getWatches(false);
|
||||
Assertions.assertNotEquals(null, ptoEquipamentModels);
|
||||
Assertions.assertFalse(ptoEquipamentModels.isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
//Generated with love by TestMe :) Please report issues and submit feature requests at: http://weirddev.com/forum#!/testme
|
Loading…
Reference in New Issue