Skip to content

Commit

Permalink
Merge branch '1-create-table-for-medtype' of https://github.com/E-Hay…
Browse files Browse the repository at this point in the history
…van/e-hayvan-backend into 1-create-table-for-medtype
  • Loading branch information
ituitis20-karadagd20 committed Jan 3, 2024
2 parents 2a878f9 + d0f1975 commit 3a95915
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Customer {
public Integer getUserID() {
return UserID;
}
public void setUserID(int userID) {
public void setUserID(Integer userID) {
UserID = userID;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void setUp() {
@Transactional
public void onEachTestStart() {
testAppointment = new Appointment();
testAppointment.setAppointmentID(13);
testAppointment.setAppointmentID(0);
testAppointment.setPetOwnerID(new PetOwner());
testAppointment.setPetID(new Pet());
testAppointment.setVetID(new Veterinarian());
Expand Down Expand Up @@ -171,17 +171,17 @@ public void testServiceGetAllAppointments() {
List<Appointment> listOfAllAddedAppointments = new ArrayList<>();
Appointment returnedAppointment;

testAppointment.setAppointmentID(17);
testAppointment.setAppointmentID(0);
returnedAppointment = testAppointmentRepository.save(testAppointment);
listOfAllAddedAppointments.add(returnedAppointment);

testAppointment.setAppointmentID(18);
testAppointment.setAppointmentID(0);
returnedAppointment = testAppointmentRepository.save(testAppointment);
listOfAllAddedAppointments.addLast(returnedAppointment);
listOfAllAddedAppointments.add(returnedAppointment);

testAppointment.setAppointmentID(19);
testAppointment.setAppointmentID(0);
returnedAppointment = testAppointmentRepository.save(testAppointment);
listOfAllAddedAppointments.addLast(returnedAppointment);
listOfAllAddedAppointments.add(returnedAppointment);

List<AppointmentDTO> appointmentList = testAppointmentService.getAllAppointments();

Expand Down Expand Up @@ -210,15 +210,15 @@ public void testServiceGetAllAppointmentsForPetOwner() {
List<PetOwner> listOfAllAddedPetOwner = new ArrayList<>();

PetOwner otherPetOwner = new PetOwner();
otherPetOwner.setPetOwnerID(17);
otherPetOwner.setPetOwnerID(0);
otherPetOwner.setUser(new Customer());
otherPetOwner.getUser().setEmail("damacana@gmail.com");
otherPetOwner.getUser().setPassword("Sopa");
otherPetOwner.getUser().setSurname("Geyik");
otherPetOwner.getUser().setName("Erdem");
listOfAllAddedPetOwner.add(testPetOwnerRepository.save(otherPetOwner));

otherPetOwner.setPetOwnerID(19);
otherPetOwner.setPetOwnerID(0);
otherPetOwner.setUser(new Customer());
otherPetOwner.getUser().setEmail("topcuyum@gmail.com");
otherPetOwner.getUser().setPassword("Gec bile kaldim");
Expand All @@ -230,19 +230,19 @@ public void testServiceGetAllAppointmentsForPetOwner() {
List<Appointment> listOfAllAddedAppointments = new ArrayList<>();
Appointment returnedAppointment;

testAppointment.setAppointmentID(17);
testAppointment.setAppointmentID(0);
testAppointment.getPetOwnerID().setPetOwnerID(listOfAllAddedPetOwner.get(0).getPetOwnerID());
returnedAppointment = testAppointmentRepository.save(testAppointment);
listOfAllAddedAppointmentsForPetOwner.add(returnedAppointment);
listOfAllAddedAppointments.add(returnedAppointment);

testAppointment.setAppointmentID(18);
testAppointment.setAppointmentID(0);
testAppointment.getPetOwnerID().setPetOwnerID(listOfAllAddedPetOwner.get(0).getPetOwnerID());
returnedAppointment = testAppointmentRepository.save(testAppointment);
listOfAllAddedAppointmentsForPetOwner.addLast(returnedAppointment);
listOfAllAddedAppointments.add(returnedAppointment);

testAppointment.setAppointmentID(19);
testAppointment.setAppointmentID(0);
testAppointment.getPetOwnerID().setPetOwnerID(listOfAllAddedPetOwner.get(1).getPetOwnerID());
returnedAppointment = testAppointmentRepository.save(testAppointment);
// listOfAllAddedAppointmentsForPetOwner.addLast(returnedAppointment);
Expand Down Expand Up @@ -280,7 +280,7 @@ public void testServiceGetAllAppointmentsForVeterinarian() {
List<Veterinarian> listOfAllAddedVeterinarian = new ArrayList<>();

Veterinarian otherVeterinarian = new Veterinarian();
otherVeterinarian.setVetID(15);
otherVeterinarian.setVetID(0);
otherVeterinarian.setClinic("cincinella");
otherVeterinarian.setUser(new Customer());
otherVeterinarian.getUser().setUserTypeID(new UserType(2));
Expand All @@ -290,7 +290,7 @@ public void testServiceGetAllAppointmentsForVeterinarian() {
otherVeterinarian.getUser().setPassword("akaryakit");
listOfAllAddedVeterinarian.add(testVeterinarianRepository.save(otherVeterinarian));

otherVeterinarian.setVetID(16);
otherVeterinarian.setVetID(0);
otherVeterinarian.setClinic("Medico");
otherVeterinarian.setUser(new Customer());
otherVeterinarian.getUser().setUserTypeID(new UserType(2));
Expand All @@ -304,19 +304,19 @@ public void testServiceGetAllAppointmentsForVeterinarian() {
List<Appointment> listOfAllAddedAppointments = new ArrayList<>();
Appointment returnedAppointment;

testAppointment.setAppointmentID(17);
testAppointment.setAppointmentID(0);
testAppointment.getVetID().setVetID(listOfAllAddedVeterinarian.get(0).getVetID());
returnedAppointment = testAppointmentRepository.save(testAppointment);
listOfAllAddedAppointmentsForVeterinarian.add(returnedAppointment);
listOfAllAddedAppointments.add(returnedAppointment);

testAppointment.setAppointmentID(18);
testAppointment.setAppointmentID(0);
testAppointment.getVetID().setVetID(listOfAllAddedVeterinarian.get(0).getVetID());
returnedAppointment = testAppointmentRepository.save(testAppointment);
listOfAllAddedAppointmentsForVeterinarian.addLast(returnedAppointment);
listOfAllAddedAppointments.add(returnedAppointment);

testAppointment.setAppointmentID(19);
testAppointment.setAppointmentID(0);
testAppointment.getVetID().setVetID(listOfAllAddedVeterinarian.get(1).getVetID());
returnedAppointment = testAppointmentRepository.save(testAppointment);
// listOfAllAddedAppointmentsForVeterinarian.addLast(returnedAppointment);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.production.ehayvanbackendapi.ServiceTests;

import com.production.ehayvanbackendapi.DTO.AppointmentDTO;
import com.production.ehayvanbackendapi.DTO.CustomerDTO;
import com.production.ehayvanbackendapi.DTO.PetDTO;
import com.production.ehayvanbackendapi.DTO.ScheduleDTO;
Expand Down Expand Up @@ -27,6 +28,8 @@

import java.time.LocalDate;
import java.time.Month;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -62,7 +65,7 @@ public void setUp() {
@Transactional
public void onEachTestStart() {
testCustomer = new Customer();
testCustomer.setUserID(1);
testCustomer.setUserID(0);
testCustomer.setName("Meth");
testCustomer.setSurname("Fulled");
testCustomer.setPassword("Finn");
Expand Down Expand Up @@ -115,4 +118,46 @@ public void testServiceDeleteCustomer() {
searchedCustomer = testCustomerRepository.findById(returnedCustomer.getUserID());
assertThat(searchedCustomer.isPresent()).isEqualTo(false);
}

@Test
@Transactional
public void testServiceGetAllCustomer() {
List<Customer> listOfAllAddedCustomers = new ArrayList<>();

testCustomer.setUserID(0);
listOfAllAddedCustomers.add(testCustomerRepository.save(testCustomer));

testCustomer.setUserID(0);
listOfAllAddedCustomers.add(testCustomerRepository.save(testCustomer));

testCustomer.setUserID(0);
listOfAllAddedCustomers.add(testCustomerRepository.save(testCustomer));

List<CustomerDTO> customerList = testCustomerService.getAllCustomers();

// we include seeded data before tests start. So we expect that size of returned list
// is added_items_size + 2. (Seeded Customer for PetOwner and Seeded Customer for Veterinarian)

assertThat(customerList.size() - 2).isEqualTo(listOfAllAddedCustomers.size());

// @TODO CihatAltiparmak : Find more chic solution, it's hard coded.
// check if there is seeded data's user id
assertThat(customerList.stream().map(
CustomerDTO::getUserID).toList().contains(1))
.isEqualTo(true);

assertThat(customerList.stream().map(
CustomerDTO::getUserID).toList().contains(1))
.isEqualTo(true);

for (Customer addedCustomer : listOfAllAddedCustomers) {
assertThat(customerList.stream().map(
CustomerDTO::getUserID).toList().contains(addedCustomer.getUserID()))
.isEqualTo(true);
}

for (Customer addedCustomer : listOfAllAddedCustomers) {
testCustomerRepository.deleteById(addedCustomer.getUserID());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void setUp() {
@Transactional
public void onEachTestStart() {
testMedType = new MedType();
testMedType.setMedTypeID(11);
testMedType.setMedTypeID(0);
testMedType.setMedications(List.of());
testMedType.setMedType("Nigde Buyuksehir Belediye Spor");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public void setUp() {
@Transactional
public void onEachTestStart() {
testMedication = new Medication();
testMedication.setMedicationID(0);
testMedication.setMedicationName("Akyazi Sifasi");
testMedication.setPetID(new Pet());
testMedication.setScheduleID(new Schedule());
Expand All @@ -61,7 +62,6 @@ public void onEachTestStart() {
testMedication.getScheduleID().setDoseCount(1773);
testMedication.setMedTypeID(new MedType());
testMedication.getMedTypeID().setMedTypeID(1);
testMedication.setMedicationID(1);

testCreateOrUpdateMedicationDTO = new CreateOrUpdateMedicationDTO(testMedicationMapper.convertToDto(testMedication));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void setUp() {
@Transactional
public void onEachTestStart() {
testPetOwner = new PetOwner();
testPetOwner.setPetOwnerID(0);
testPetOwner.setUser(new Customer());
testPetOwner.getUser().setUserTypeID(new UserType(1));
testPetOwner.getUser().setName("And i return to nothingness");
Expand Down Expand Up @@ -135,12 +136,14 @@ public void testServiceUpdatePetOwner() {
@Test
@Transactional
public void testServiceUpdateAssignedVeterinarian() {
testPetOwner.setPetOwnerID(0);
testPetOwner.setVet(new Veterinarian());
testPetOwner.getVet().setClinic("sun of the run");
testPetOwner.setAppointments(List.of());
PetOwner returnedPetOwner = testPetOwnerRepository.save(testPetOwner);

Veterinarian otherVeterinarian = new Veterinarian();
otherVeterinarian.setVetID(0);
otherVeterinarian.setClinic("goke bakma duragi");
otherVeterinarian = testVeterinarianRepository.save(otherVeterinarian);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public void setUp() {
@Transactional
public void onEachTestStart() {
testPet = new Pet();
testPet.setPetID(0);
testPet.setPetName("Ingiliz Ati");
testPet.setPetTypeID(new PetType());
testPet.getPetTypeID().setPetTypeID(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void setUp() {
@Transactional
public void onEachTestStart() {
testPetType = new PetType();
testPetType.setPetTypeID(17);
testPetType.setPetTypeID(0);
testPetType.setPets(List.of());
testPetType.setType("micky mouse");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void setUp() {
@Transactional
public void onEachTestStart() {
testSchedule = new Schedule();
testSchedule.setScheduleID(10);
testSchedule.setScheduleID(0);
testSchedule.setDoseCount(12);
testSchedule.setDoseFrequency(1000);
testSchedule.setBeginningDate(LocalDate.of(1995, Month.APRIL, 30));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void setUp() {
@Transactional
public void onEachTestStart() {
testUserType = new UserType();
testUserType.setUserTypeID(13);
testUserType.setUserTypeID(0);
testUserType.setType("Ingiliz Helvacisi");
testUserType.setUsers(List.of());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public void setUp() {
public void onEachTestStart() {

testVeterinarian = new Veterinarian();
testVeterinarian.setVetID(0);
testVeterinarian.setClinic("cincinella");
testVeterinarian.setUser(new Customer());
testVeterinarian.getUser().setUserTypeID(new UserType(2));
Expand Down

0 comments on commit 3a95915

Please sign in to comment.