derrickjunior

Untitled

Aug 21st, 2024
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. package org.openelisglobal.notes;
  2.  
  3. import java.sql.Date;
  4. import java.util.List;
  5. import org.junit.After;
  6. import org.junit.Assert;
  7. import org.junit.Before;
  8. import org.junit.Test;
  9. import org.openelisglobal.BaseWebContextSensitiveTest;
  10. import org.openelisglobal.note.service.NoteService;
  11. import org.openelisglobal.note.valueholder.Note;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13.  
  14. public class NoteServiceTest extends BaseWebContextSensitiveTest {
  15.  
  16. @Autowired
  17. private NoteService noteService;
  18.  
  19. @Before
  20. public void init() throws Exception {
  21.  
  22. }
  23.  
  24. @After
  25. public void tearDown() {
  26. noteService.deleteAll(noteService.getAll());
  27. }
  28. @Test
  29. public void createNote_shouldCreateNewNote() throws Exception {
  30. String noteText = "This is a test note.";
  31. String noteSubject = "Test Subject";
  32.  
  33. Note note = createNote(noteText, noteSubject);
  34.  
  35. // Save note to the DB
  36. String noteId = noteService.insert(note);
  37. Note savedNote = noteService.get(noteId);
  38.  
  39. Assert.assertNotNull(savedNote);
  40. Assert.assertEquals(noteText, savedNote.getText());
  41. Assert.assertEquals(noteSubject, savedNote.getSubject());
  42. }
  43.  
  44. private Note createNote(String text, String subject) {
  45. Note note = new Note();
  46. note.setText(text);
  47. note.setSubject(subject);
  48. // Set other necessary fields, such as referenceId and referenceTableId
  49. note.setReferenceId("1");
  50. note.setReferenceTableId("1");
  51. return note;
  52. }
  53.  
  54. @Test
  55. public void getNoteByRefIdAndRefTableAndSubject_shouldReturnNotes() throws Exception {
  56. String noteText = "Reference note.";
  57. String noteSubject = "Ref Subject";
  58. Note note = createNote(noteText, noteSubject);
  59.  
  60. // Save note to the DB
  61. noteService.insert(note);
  62.  
  63. List<Note> notes = noteService.getNoteByRefIAndRefTableAndSubject(
  64. note.getReferenceId(), note.getReferenceTableId(), note.getSubject());
  65.  
  66. Assert.assertNotNull(notes);
  67. Assert.assertTrue(notes.size() > 0);
  68. }
  69.  
  70. }
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
Advertisement
Add Comment
Please, Sign In to add comment