-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ScheduleServiceTest, CustomerServiceTest;
Fix typo in AppointmentServiceTest; Added parameter to application.properties for postgresql max connection error
- Loading branch information
1 parent
1aa6180
commit 70d646b
Showing
5 changed files
with
241 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
118 changes: 118 additions & 0 deletions
118
src/test/java/com/production/ehayvanbackendapi/ServiceTests/CustomerServiceTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package com.production.ehayvanbackendapi.ServiceTests; | ||
|
||
import com.production.ehayvanbackendapi.DTO.CustomerDTO; | ||
import com.production.ehayvanbackendapi.DTO.PetDTO; | ||
import com.production.ehayvanbackendapi.DTO.ScheduleDTO; | ||
import com.production.ehayvanbackendapi.DTO.request.CreateOrUpdateCustomerDTO; | ||
import com.production.ehayvanbackendapi.DTO.request.CreateOrUpdatePetDTO; | ||
import com.production.ehayvanbackendapi.DTO.request.CreateOrUpdateScheduleDTO; | ||
import com.production.ehayvanbackendapi.Entities.*; | ||
import com.production.ehayvanbackendapi.Mappers.CustomerMapper; | ||
import com.production.ehayvanbackendapi.Mappers.PetMapper; | ||
import com.production.ehayvanbackendapi.Mappers.ScheduleMapper; | ||
import com.production.ehayvanbackendapi.Repositories.CustomerRepository; | ||
import com.production.ehayvanbackendapi.Repositories.PetRepository; | ||
import com.production.ehayvanbackendapi.Repositories.ScheduleRepository; | ||
import com.production.ehayvanbackendapi.Services.CustomerService; | ||
import com.production.ehayvanbackendapi.Services.PetService; | ||
import com.production.ehayvanbackendapi.Services.ScheduleService; | ||
import com.production.ehayvanbackendapi.TestUtils.DataSeed; | ||
import org.junit.jupiter.api.*; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.SpyBean; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.LocalDate; | ||
import java.time.Month; | ||
import java.util.Optional; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@SpringBootTest | ||
@AutoConfigureMockMvc | ||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
public class CustomerServiceTest { | ||
@SpyBean | ||
@Autowired | ||
private CustomerService testCustomerService; | ||
|
||
@SpyBean | ||
@Autowired | ||
private CustomerRepository testCustomerRepository; | ||
|
||
@Autowired | ||
DataSeed dataSeed; | ||
|
||
private Customer testCustomer; | ||
|
||
private CreateOrUpdateCustomerDTO testCreateOrUpdateCustomerDTO; | ||
|
||
@Autowired | ||
private CustomerMapper testCustomerMapper; | ||
|
||
@BeforeAll | ||
public void setUp() { | ||
dataSeed.loadSeedToDatabase(); | ||
} | ||
|
||
@BeforeEach | ||
@Transactional | ||
public void onEachTestStart() { | ||
testCustomer = new Customer(); | ||
testCustomer.setUserID(1); | ||
testCustomer.setName("Meth"); | ||
testCustomer.setSurname("Fulled"); | ||
testCustomer.setPassword("Finn"); | ||
testCustomer.setEmail("[email protected]"); | ||
|
||
testCreateOrUpdateCustomerDTO = new CreateOrUpdateCustomerDTO(testCustomerMapper.convertToDto(testCustomer)); | ||
} | ||
|
||
@AfterEach | ||
public void onEachTestEnd() { | ||
testCreateOrUpdateCustomerDTO = null; | ||
testCustomer = null; | ||
} | ||
|
||
@Test | ||
public void testServiceGetByIdWhichNoExists() { | ||
int testCustomerId = 0; | ||
CustomerDTO returnedCustomerDTO = testCustomerService.getCustomerById(testCustomerId); | ||
assertThat(returnedCustomerDTO).isNull(); | ||
} | ||
|
||
@Test | ||
@Transactional | ||
public void testServiceGetByIdWhichInDatabase() { | ||
Customer returnedCustomer = testCustomerRepository.save(testCustomer); | ||
CustomerDTO returnedCustomerDTO = testCustomerService.getCustomerById(returnedCustomer.getUserID()); | ||
|
||
assertThat(returnedCustomerDTO).isNotNull(); | ||
assertThat(returnedCustomerDTO.getUserID()).isEqualTo(returnedCustomer.getUserID()); | ||
assertThat(returnedCustomerDTO.getName()).isEqualTo(returnedCustomer.getName()); | ||
assertThat(returnedCustomerDTO.getSurname()).isEqualTo(returnedCustomer.getSurname()); | ||
assertThat(returnedCustomerDTO.getPassword()).isEqualTo(returnedCustomer.getPassword()); | ||
assertThat(returnedCustomerDTO.getEmail()).isEqualTo(returnedCustomer.getEmail()); | ||
|
||
testCustomerRepository.deleteById(returnedCustomer.getUserID()); | ||
} | ||
|
||
@Test | ||
@Transactional | ||
public void testServiceDeleteCustomer() { | ||
// firstly save new Customer | ||
Customer returnedCustomer = testCustomerRepository.save(testCustomer); | ||
Optional<Customer> searchedCustomer = testCustomerRepository.findById(returnedCustomer.getUserID()); | ||
assertThat(searchedCustomer.isPresent()).isEqualTo(true); | ||
|
||
CustomerDTO deletedCustomer = testCustomerService.deleteCustomer(returnedCustomer.getUserID()); | ||
|
||
assertThat(deletedCustomer.getUserID()).isEqualTo(returnedCustomer.getUserID()); | ||
|
||
searchedCustomer = testCustomerRepository.findById(returnedCustomer.getUserID()); | ||
assertThat(searchedCustomer.isPresent()).isEqualTo(false); | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
src/test/java/com/production/ehayvanbackendapi/ServiceTests/ScheduleServiceTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package com.production.ehayvanbackendapi.ServiceTests; | ||
|
||
import com.production.ehayvanbackendapi.DTO.PetDTO; | ||
import com.production.ehayvanbackendapi.DTO.ScheduleDTO; | ||
import com.production.ehayvanbackendapi.DTO.request.CreateOrUpdatePetDTO; | ||
import com.production.ehayvanbackendapi.DTO.request.CreateOrUpdateScheduleDTO; | ||
import com.production.ehayvanbackendapi.Entities.*; | ||
import com.production.ehayvanbackendapi.Mappers.PetMapper; | ||
import com.production.ehayvanbackendapi.Mappers.ScheduleMapper; | ||
import com.production.ehayvanbackendapi.Repositories.PetRepository; | ||
import com.production.ehayvanbackendapi.Repositories.ScheduleRepository; | ||
import com.production.ehayvanbackendapi.Services.PetService; | ||
import com.production.ehayvanbackendapi.Services.ScheduleService; | ||
import com.production.ehayvanbackendapi.TestUtils.DataSeed; | ||
import org.junit.jupiter.api.*; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.SpyBean; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.LocalDate; | ||
import java.time.Month; | ||
import java.util.Optional; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@SpringBootTest | ||
@AutoConfigureMockMvc | ||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
public class ScheduleServiceTest { | ||
@SpyBean | ||
@Autowired | ||
private ScheduleService testScheduleService; | ||
|
||
@SpyBean | ||
@Autowired | ||
private ScheduleRepository testScheduleRepository; | ||
|
||
@Autowired | ||
DataSeed dataSeed; | ||
|
||
private Schedule testSchedule; | ||
|
||
private CreateOrUpdateScheduleDTO testCreateOrUpdateScheduleDTO; | ||
|
||
@Autowired | ||
private ScheduleMapper testScheduleMapper; | ||
|
||
@BeforeAll | ||
public void setUp() { | ||
dataSeed.loadSeedToDatabase(); | ||
} | ||
|
||
@BeforeEach | ||
@Transactional | ||
public void onEachTestStart() { | ||
testSchedule = new Schedule(); | ||
testSchedule.setScheduleID(10); | ||
testSchedule.setDoseCount(12); | ||
testSchedule.setDoseFrequency(1000); | ||
testSchedule.setBeginningDate(LocalDate.of(1995, Month.APRIL, 30)); | ||
|
||
testCreateOrUpdateScheduleDTO = new CreateOrUpdateScheduleDTO(testScheduleMapper.convertToDto(testSchedule)); | ||
} | ||
|
||
@AfterEach | ||
public void onEachTestEnd() { | ||
testCreateOrUpdateScheduleDTO = null; | ||
testSchedule = null; | ||
} | ||
|
||
@Test | ||
public void testServiceGetByIdWhichNoExists() { | ||
int testScheduleId = 0; | ||
ScheduleDTO returnedScheduleDTO = testScheduleService.getScheduleById(testScheduleId); | ||
assertThat(returnedScheduleDTO).isNull(); | ||
} | ||
|
||
@Test | ||
@Transactional | ||
public void testServiceGetByIdWhichInDatabase() { | ||
Schedule returnedSchedule = testScheduleRepository.save(testSchedule); | ||
ScheduleDTO returnedScheduleDTO = testScheduleService.getScheduleById(returnedSchedule.getScheduleID()); | ||
|
||
assertThat(returnedScheduleDTO).isNotNull(); | ||
assertThat(returnedScheduleDTO.getScheduleID()).isEqualTo(returnedSchedule.getScheduleID()); | ||
assertThat(returnedScheduleDTO.getBeginningDate()).isEqualTo(returnedSchedule.getBeginningDate()); | ||
assertThat(returnedScheduleDTO.getDoseCount()).isEqualTo(returnedSchedule.getDoseCount()); | ||
|
||
testScheduleRepository.deleteById(returnedSchedule.getScheduleID()); | ||
} | ||
|
||
@Test | ||
@Transactional | ||
public void testServiceDeleteSchedule() { | ||
// firstly save new Pet | ||
Schedule returnedSchedule = testScheduleRepository.save(testSchedule); | ||
Optional<Schedule> searchedSchedule = testScheduleRepository.findById(returnedSchedule.getScheduleID()); | ||
assertThat(searchedSchedule.isPresent()).isEqualTo(true); | ||
|
||
ScheduleDTO deletedSchedule = testScheduleService.deleteSchedule(returnedSchedule.getScheduleID()); | ||
|
||
assertThat(deletedSchedule.getScheduleID()).isEqualTo(returnedSchedule.getScheduleID()); | ||
|
||
searchedSchedule = testScheduleRepository.findById(returnedSchedule.getScheduleID()); | ||
assertThat(searchedSchedule.isPresent()).isEqualTo(false); | ||
} | ||
} |