[R2] Unit test method for find doctors
This commit is contained in:
parent
232a4e4567
commit
55e5462afa
@ -1,22 +1,31 @@
|
|||||||
package com.mirna.hospitalmanagementapi.unit.application.service;
|
package com.mirna.hospitalmanagementapi.unit.application.service;
|
||||||
|
|
||||||
|
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 static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.AfterAll;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.TestInstance;
|
import org.junit.jupiter.api.TestInstance;
|
||||||
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
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 org.springframework.test.context.ActiveProfiles;
|
||||||
|
|
||||||
import com.mirna.hospitalmanagementapi.HospitalManagementApiApplication;
|
import com.mirna.hospitalmanagementapi.HospitalManagementApiApplication;
|
||||||
import com.mirna.hospitalmanagementapi.application.services.DoctorServiceImpl;
|
import com.mirna.hospitalmanagementapi.application.services.DoctorServiceImpl;
|
||||||
import com.mirna.hospitalmanagementapi.domain.dtos.AddressDTO;
|
import com.mirna.hospitalmanagementapi.domain.dtos.AddressDTO;
|
||||||
import com.mirna.hospitalmanagementapi.domain.dtos.DoctorDTO;
|
import com.mirna.hospitalmanagementapi.domain.dtos.DoctorDTO;
|
||||||
|
import com.mirna.hospitalmanagementapi.domain.dtos.DoctorPublicDataDTO;
|
||||||
import com.mirna.hospitalmanagementapi.domain.entities.Doctor;
|
import com.mirna.hospitalmanagementapi.domain.entities.Doctor;
|
||||||
import com.mirna.hospitalmanagementapi.domain.enums.Specialty;
|
import com.mirna.hospitalmanagementapi.domain.enums.Specialty;
|
||||||
|
import com.mirna.hospitalmanagementapi.domain.repositories.DoctorRepository;
|
||||||
|
|
||||||
import jakarta.validation.ConstraintViolationException;
|
import jakarta.validation.ConstraintViolationException;
|
||||||
|
|
||||||
@ -33,6 +42,30 @@ public class DoctorServiceTest {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private DoctorServiceImpl doctorService;
|
private DoctorServiceImpl doctorService;
|
||||||
|
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a valid doctor.
|
* Create a valid doctor.
|
||||||
*/
|
*/
|
||||||
@ -58,4 +91,17 @@ public class DoctorServiceTest {
|
|||||||
|
|
||||||
assertThrows(ConstraintViolationException.class, () -> doctorService.addDoctor(doctorDTO));
|
assertThrows(ConstraintViolationException.class, () -> doctorService.addDoctor(doctorDTO));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds doctors stored in the database with pagination
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@DisplayName("Should find doctors with pagination")
|
||||||
|
public void testFindDoctors() throws Exception {
|
||||||
|
Pageable pageable = PageRequest.of(0, 3);
|
||||||
|
|
||||||
|
Page<DoctorPublicDataDTO> doctors = doctorService.findDoctors(pageable);
|
||||||
|
|
||||||
|
assertEquals(doctors.getSize(), 3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user