[R2] Unit test for find doctors use case
This commit is contained in:
parent
776c56a9be
commit
232a4e4567
@ -0,0 +1,80 @@
|
||||
package com.mirna.hospitalmanagementapi.unit.application.usecase.doctor;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import com.mirna.hospitalmanagementapi.HospitalManagementApiApplication;
|
||||
import com.mirna.hospitalmanagementapi.application.usecase.doctor.FindDoctorsUseCase;
|
||||
import com.mirna.hospitalmanagementapi.domain.dtos.AddressDTO;
|
||||
import com.mirna.hospitalmanagementapi.domain.dtos.DoctorDTO;
|
||||
import com.mirna.hospitalmanagementapi.domain.entities.Doctor;
|
||||
import com.mirna.hospitalmanagementapi.domain.enums.Specialty;
|
||||
import com.mirna.hospitalmanagementapi.domain.repositories.DoctorRepository;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Mirna Gama
|
||||
* @version 1.0
|
||||
*/
|
||||
@SpringBootTest(classes = HospitalManagementApiApplication.class)
|
||||
@TestInstance(Lifecycle.PER_CLASS)
|
||||
@ActiveProfiles("test")
|
||||
public class FindDoctorsUseCaseTest {
|
||||
|
||||
@Autowired
|
||||
private FindDoctorsUseCase findDoctors;
|
||||
|
||||
@Autowired
|
||||
private DoctorRepository doctorRepository;
|
||||
|
||||
@BeforeAll
|
||||
public void init() {
|
||||
DoctorDTO doctorDTO1 = new DoctorDTO("test1", "test1@gmail.com", "123456", "99999999", Specialty.ORTHOPEDICS,
|
||||
new AddressDTO("TEST STREET", "NEIGHBORHOOD", "12345678", "CITY", "ST", null, null));
|
||||
|
||||
DoctorDTO doctorDTO2 = new DoctorDTO("test2", "test2@gmail.com", "789101", "99999999", Specialty.ORTHOPEDICS,
|
||||
new AddressDTO("TEST STREET", "NEIGHBORHOOD", "12345678", "CITY", "ST", null, null));
|
||||
|
||||
DoctorDTO doctorDTO3 = new DoctorDTO("test3", "test3@gmail.com", "112131", "99999999", Specialty.ORTHOPEDICS,
|
||||
new AddressDTO("TEST STREET", "NEIGHBORHOOD", "12345678", "CITY", "ST", null, null));
|
||||
|
||||
doctorRepository.save(new Doctor(doctorDTO1));
|
||||
doctorRepository.save(new Doctor(doctorDTO2));
|
||||
doctorRepository.save(new Doctor(doctorDTO3));
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public void terminate() {
|
||||
doctorRepository.deleteAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Should execute findAll method with pagination successfully
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("Should execute findAll method with pagination")
|
||||
public void testFindDoctors() throws Exception {
|
||||
Pageable pageable = PageRequest.of(0, 3);
|
||||
|
||||
Page<Doctor> doctors = findDoctors.execute(pageable);
|
||||
|
||||
assertEquals(doctors.getSize(), 3);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user