-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Added test cases for notification.
- Loading branch information
1 parent
ebb9990
commit ba76e5a
Showing
2 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
.../test/java/com/pemits/webcare/api/notification/repository/NotificationRepositoryTest.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,123 @@ | ||
package com.pemits.webcare.api.notification.repository; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import com.github.springtestdbunit.annotation.DatabaseSetup; | ||
import com.pemits.webcare.BaseJpaTest; | ||
import com.pemits.webcare.api.doctor.repository.DoctorRepository; | ||
import com.pemits.webcare.api.notification.entity.Notification; | ||
import com.pemits.webcare.api.patient.repository.PatientRepository; | ||
import com.pemits.webcare.api.user.entity.User; | ||
import com.pemits.webcare.core.constant.AppConstant; | ||
import com.pemits.webcare.core.enums.NotificationStatus; | ||
|
||
public class NotificationRepositoryTest extends BaseJpaTest { | ||
|
||
private static final long MOCK_DOCTOR_ID = 1L; | ||
private static final long MOCK_PATIENT_ID = 1L; | ||
private static final long MOCK_PATIENT_ID_2 = 2L; | ||
private static final long MOCK_NOTIFICATION_ID = 1L; | ||
|
||
@Autowired | ||
private NotificationRepository repository; | ||
|
||
@Autowired | ||
private PatientRepository patientRepository; | ||
|
||
@Autowired | ||
private DoctorRepository doctorRepository; | ||
|
||
@Test | ||
@DatabaseSetup("/dataset/department/department-config.xml") | ||
@DatabaseSetup({ | ||
"/dataset/user/users-of-type-doctor.xml", | ||
"/dataset/user/users-of-type-patient.xml" | ||
}) | ||
@DatabaseSetup("/dataset/doctor/doctor-config.xml") | ||
@DatabaseSetup("/dataset/patient/patient-config.xml") | ||
public void testSaveShouldReturnSavedNotification() { | ||
User doctor = doctorRepository.getOne(MOCK_DOCTOR_ID).getUser(); | ||
User patient = patientRepository.getOne(MOCK_PATIENT_ID).getUser(); | ||
|
||
Notification notification = Notification.builder() | ||
.status(NotificationStatus.UNSEEN) | ||
.from(patient) | ||
.to(doctor) | ||
.message(String.format(AppConstant.NOTIFY_NEW_APPOINTMENT, patient.getName())) | ||
.build(); | ||
|
||
Notification saved = repository.save(notification); | ||
|
||
assertThat(saved.getId(), notNullValue()); | ||
} | ||
|
||
@Test | ||
@DatabaseSetup("/dataset/department/department-config.xml") | ||
@DatabaseSetup({ | ||
"/dataset/user/users-of-type-doctor.xml", | ||
"/dataset/user/users-of-type-patient.xml" | ||
}) | ||
@DatabaseSetup("/dataset/doctor/doctor-config.xml") | ||
@DatabaseSetup("/dataset/patient/patient-config.xml") | ||
public void testSaveAllShouldReturnSavedNotifications() { | ||
User doctor = doctorRepository.getOne(MOCK_DOCTOR_ID).getUser(); | ||
User patient1 = patientRepository.getOne(MOCK_PATIENT_ID).getUser(); | ||
User patient2 = patientRepository.getOne(MOCK_PATIENT_ID_2).getUser(); | ||
|
||
Notification notification1 = Notification.builder() | ||
.status(NotificationStatus.UNSEEN) | ||
.from(patient1) | ||
.to(doctor) | ||
.message(String.format(AppConstant.NOTIFY_NEW_APPOINTMENT, patient1.getName())) | ||
.build(); | ||
|
||
Notification notification2 = Notification.builder() | ||
.status(NotificationStatus.UNSEEN) | ||
.from(patient2) | ||
.to(doctor) | ||
.message(String.format(AppConstant.NOTIFY_NEW_APPOINTMENT, patient2.getName())) | ||
.build(); | ||
|
||
List<Notification> saved = repository.saveAll(Arrays.asList(notification1, notification2)); | ||
|
||
assertThat(saved, hasSize(2)); | ||
assertThat(saved.get(0).getId(), notNullValue()); | ||
assertThat(saved.get(1).getId(), notNullValue()); | ||
} | ||
|
||
@Test | ||
@DatabaseSetup("/dataset/department/department-config.xml") | ||
@DatabaseSetup({ | ||
"/dataset/user/users-of-type-doctor.xml", | ||
"/dataset/user/users-of-type-patient.xml" | ||
}) | ||
@DatabaseSetup("/dataset/doctor/doctor-config.xml") | ||
@DatabaseSetup("/dataset/patient/patient-config.xml") | ||
@DatabaseSetup("/dataset/notification/notification-config.xml") | ||
public void testSaveShouldUpdateNotification() { | ||
Notification notification = repository.getOne(MOCK_NOTIFICATION_ID); | ||
|
||
NotificationStatus oldStatus = NotificationStatus.UNSEEN; | ||
NotificationStatus newStatus = NotificationStatus.SEEN; | ||
|
||
assertThat(notification.getStatus(), is(oldStatus)); | ||
|
||
notification.setStatus(newStatus); | ||
repository.save(notification); | ||
|
||
Notification saved = repository.getOne(MOCK_NOTIFICATION_ID); | ||
|
||
assertThat(saved.getStatus(), not(oldStatus)); | ||
assertThat(saved.getStatus(), is(newStatus)); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
pemits-api/src/test/resources/dataset/notification/notification-config.xml
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,23 @@ | ||
<dataset> | ||
<!-- NULL: created_by, last_modified_by --> | ||
<notification | ||
id="1" | ||
created_at="2020-06-20 15:30:00" | ||
last_modified_at="2020-06-20 15:30:00" | ||
version="0" | ||
from_id="5" | ||
to_id="1" | ||
message="You have new notification from Marshal Doe" | ||
status="0" | ||
/> | ||
<notification | ||
id="2" | ||
created_at="2020-06-20 15:30:00" | ||
last_modified_at="2020-06-20 15:30:00" | ||
version="0" | ||
from_id="6" | ||
to_id="1" | ||
message="You have new notification from Jenny Doe" | ||
status="1" | ||
/> | ||
</dataset> |