Guest User

Untitled

a guest
Dec 26th, 2024
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. package org.openelisglobal.note;
  2.  
  3. import static org.junit.Assert.assertEquals;
  4. import static org.junit.Assert.assertNotNull;
  5. import static org.junit.Assert.assertNull;
  6.  
  7. import org.junit.After;
  8. import org.junit.Before;
  9. import org.junit.Test;
  10. import org.openelisglobal.BaseWebContextSensitiveTest;
  11. import org.openelisglobal.note.dao.NoteDAO;
  12. import org.openelisglobal.note.service.NoteService;
  13. import org.openelisglobal.note.valueholder.Note;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15.  
  16. import java.util.List;
  17.  
  18. import static org.junit.Assert.assertFalse;
  19.  
  20. public class NoteServiceTest extends BaseWebContextSensitiveTest {
  21.  
  22. @Autowired
  23. NoteService noteService;
  24.  
  25. @Autowired
  26. NoteDAO noteDAO;
  27.  
  28. @Before
  29. public void init() throws Exception {
  30. noteService.deleteAll(noteService.getAll());
  31. }
  32.  
  33. @After
  34. public void tearDown() {
  35. noteService.deleteAll(noteService.getAll());
  36.  
  37. }
  38.  
  39. @Test
  40. public void deleteNote_shouldDeleteNote() throws Exception {
  41. String subject = "Test Note Subject";
  42. String text = "This is a test note text.";
  43.  
  44. Note note = new Note();
  45. note.setSubject(subject);
  46. note.setText(text);
  47.  
  48. String noteId = noteService.insert(note);
  49.  
  50. Note savedNote = noteService.get(noteId);
  51. noteService.delete(savedNote);
  52. assertEquals(0, noteService.getAll().size());
  53. }
  54.  
  55. @Test
  56. public void getNote_shouldReturnNullForNonExistentNote() throws Exception {
  57. String nonExistentNoteId = "nonExistentNoteId";
  58.  
  59. Note note = noteService.get(nonExistentNoteId);
  60. assertNull(note);
  61. }
  62.  
  63. @Test
  64. public void deleteAllNotes_shouldClearAllNotes() throws Exception {
  65. String subject1 = "Note 1";
  66. String text1 = "First test note.";
  67.  
  68. Note note1 = new Note();
  69. note1.setSubject(subject1);
  70. note1.setText(text1);
  71. noteService.insert(note1);
  72.  
  73. String subject2 = "Note 2";
  74. String text2 = "Second test note.";
  75.  
  76. Note note2 = new Note();
  77. note2.setSubject(subject2);
  78. note2.setText(text2);
  79. noteService.insert(note2);
  80. noteService.deleteAll(noteService.getAll());
  81. assertEquals(0, noteService.getAll().size());
  82. }
  83.  
  84. @Test
  85. public void getNotesOrderedByTypeAndLastUpdated_shouldReturnNotesInCorrectOrder() {
  86. Note note1 = new Note();
  87. note1.setReferenceId("1");
  88. note1.setReferenceTableId("1");
  89. note1.setNoteType(Note.EXTERNAL);
  90. note1.setSubject("First Note");
  91. note1.setText("This is the first test note.");
  92. note1.setSysUserId("testUser123");
  93. System.out.println("Inserting note1: " + note1);
  94. noteService.insert(note1);
  95.  
  96. Note note2 = new Note();
  97. note2.setReferenceId("1");
  98. note2.setReferenceTableId("1");
  99. note2.setNoteType(Note.INTERNAL);
  100. note2.setSubject("Second Note");
  101. note2.setText("This is the second test note.");
  102. note2.setSysUserId("testUser456");
  103. System.out.println("Inserting note2: " + note2);
  104. noteService.insert(note2);
  105.  
  106. List<Note> notes = noteService.getAllNotesByRefIdRefTable(note1);
  107. System.out.println("Retrieved notes: " + notes);
  108.  
  109. assertFalse("Notes list should not be empty", notes.isEmpty());
  110. System.out.println("Notes list is not empty.");
  111.  
  112. assertEquals("Second note should be internal", Note.INTERNAL, notes.get(0).getNoteType());
  113. System.out.println("First note's type is correct: " + notes.get(0).getNoteType());
  114.  
  115. assertEquals("First note should be external", Note.EXTERNAL, notes.get(1).getNoteType());
  116. System.out.println("Second note's type is correct: " + notes.get(1).getNoteType());
  117. }
  118. }
  119.  
Advertisement
Add Comment
Please, Sign In to add comment