forked from Raxa/raxacore
-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bindu | BAH-3117 | get note by voided false and make delete reason as…
… optional query parameter
- Loading branch information
Showing
6 changed files
with
109 additions
and
67 deletions.
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
99 changes: 88 additions & 11 deletions
99
bahmnicore-api/src/test/java/org/bahmni/module/bahmnicore/validator/NoteValidatorTest.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 |
---|---|---|
@@ -1,24 +1,101 @@ | ||
package org.bahmni.module.bahmnicore.validator; | ||
|
||
import org.bahmni.module.bahmnicore.contract.NoteRequest; | ||
import org.bahmni.module.bahmnicore.dao.NoteDao; | ||
import org.bahmni.module.bahmnicore.model.Note; | ||
import org.junit.Assert; | ||
import org.bahmni.module.bahmnicore.model.NoteType; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.openmrs.RelationshipType; | ||
import org.openmrs.test.BaseContextSensitiveTest; | ||
import org.openmrs.validator.RelationshipTypeValidator; | ||
import org.springframework.validation.BindException; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.MockitoAnnotations; | ||
import org.springframework.validation.BeanPropertyBindingResult; | ||
import org.springframework.validation.Errors; | ||
|
||
import java.text.DateFormat; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.MockitoAnnotations.initMocks; | ||
|
||
public class NoteValidatorTest { | ||
|
||
public class NoteValidatorTest extends BaseContextSensitiveTest { | ||
@InjectMocks | ||
private NoteValidator validator; | ||
@Mock | ||
private NoteDao noteDao; | ||
|
||
public void validate_shouldFailValidationIfaIsToBIsNullOrEmptyOrWhitespace() throws Exception { | ||
Note type = new Note(); | ||
@Before | ||
public void init() { | ||
MockitoAnnotations.initMocks(this); | ||
} | ||
|
||
@Test | ||
public void ensureNoteTypeIsNotNull() { | ||
initMocks(this); | ||
NoteRequest noteRequest = new NoteRequest(); | ||
Errors noteRequestErrors = new BeanPropertyBindingResult(noteRequest, "noteRequest"); | ||
noteRequest.setNoteTypeName(null); | ||
noteRequest.setNoteText("Note Text"); | ||
noteRequest.setNoteDate(new Date()); | ||
Note note = new Note(); | ||
note.setId(1); | ||
Mockito.when(noteDao.getNote(any(Date.class), any(String.class))).thenReturn(note); | ||
validator.validate(noteRequest, noteRequestErrors); | ||
assertEquals(true, "Note.noteType.required".matches(noteRequestErrors.getAllErrors().get(0).getCode().toString())); | ||
} | ||
|
||
Errors errors = new BindException(type, "type"); | ||
new NoteValidator().validate(type, errors); | ||
Assert.assertTrue(errors.hasFieldErrors("aIsToB")); | ||
@Test | ||
public void ensureNoteDateIsNotNull() { | ||
NoteRequest noteRequest = new NoteRequest(); | ||
Errors noteRequestErrors = new BeanPropertyBindingResult(noteRequest, "noteRequest"); | ||
noteRequest.setNoteTypeName("OT module"); | ||
noteRequest.setNoteText("Note Text"); | ||
noteRequest.setNoteDate(null); | ||
Note note = new Note(); | ||
note.setId(1); | ||
Mockito.when(noteDao.getNote(any(Date.class), any(String.class))).thenReturn(note); | ||
validator.validate(noteRequest, noteRequestErrors); | ||
assertEquals(true, "Note.noteDate.required".matches(noteRequestErrors.getAllErrors().get(0).getCode().toString())); | ||
} | ||
|
||
@Test | ||
public void ensureNoteTextIsNotNull() { | ||
NoteRequest noteRequest = new NoteRequest(); | ||
Errors noteRequestErrors = new BeanPropertyBindingResult(noteRequest, "noteRequest"); | ||
noteRequest.setNoteTypeName("OT module"); | ||
noteRequest.setNoteDate(new Date()); | ||
noteRequest.setNoteText(null); | ||
Note note = new Note(); | ||
note.setId(1); | ||
Mockito.when(noteDao.getNote(any(Date.class), any(String.class))).thenReturn(note); | ||
validator.validate(noteRequest, noteRequestErrors); | ||
assertEquals(true, "Note.noteText.required".matches(noteRequestErrors.getAllErrors().get(0).getCode().toString())); | ||
} | ||
|
||
@Test | ||
public void ensureNoteDoesntExistForSameNoteDateAndNoteType() throws ParseException { | ||
NoteRequest noteRequest = new NoteRequest(); | ||
Errors noteRequestErrors = new BeanPropertyBindingResult(noteRequest, "noteRequest"); | ||
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); | ||
Date noteDate1 = format.parse("2023-08-16 00:00:00.0"); | ||
noteRequest.setNoteTypeName("OT module"); | ||
noteRequest.setNoteDate(noteDate1); | ||
noteRequest.setNoteText("Some text"); | ||
|
||
Note note = new Note(); | ||
NoteType noteType = new NoteType(); | ||
Date existingNote = format.parse("2023-08-16 00:00:00.0"); | ||
noteType.setName("OT module"); | ||
note.setId(1); | ||
note.setNoteDate(existingNote); | ||
note.setNoteType(noteType); | ||
Mockito.when(noteDao.getNote(any(Date.class), any(String.class))).thenReturn(note); | ||
validator.validate(noteRequest, noteRequestErrors); | ||
assertEquals(true, "Note entry exist for noteType and noteDate".matches(noteRequestErrors.getAllErrors().get(0).getCode().toString())); | ||
} | ||
} |
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
41 changes: 0 additions & 41 deletions
41
...c/test/java/org/bahmni/module/bahmnicore/web/v1_0/controller/BahmniNotesControllerIT.java
This file was deleted.
Oops, something went wrong.