Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.openelisglobal.note;
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.assertNotNull;
- import static org.junit.Assert.assertNull;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
- import org.openelisglobal.BaseWebContextSensitiveTest;
- import org.openelisglobal.note.dao.NoteDAO;
- import org.openelisglobal.note.service.NoteService;
- import org.openelisglobal.note.valueholder.Note;
- import org.springframework.beans.factory.annotation.Autowired;
- import java.util.List;
- import static org.junit.Assert.assertFalse;
- public class NoteServiceTest extends BaseWebContextSensitiveTest {
- @Autowired
- NoteService noteService;
- @Autowired
- NoteDAO noteDAO;
- @Before
- public void init() throws Exception {
- noteService.deleteAll(noteService.getAll());
- }
- @After
- public void tearDown() {
- noteService.deleteAll(noteService.getAll());
- }
- @Test
- public void deleteNote_shouldDeleteNote() throws Exception {
- String subject = "Test Note Subject";
- String text = "This is a test note text.";
- Note note = new Note();
- note.setSubject(subject);
- note.setText(text);
- String noteId = noteService.insert(note);
- Note savedNote = noteService.get(noteId);
- noteService.delete(savedNote);
- assertEquals(0, noteService.getAll().size());
- }
- @Test
- public void getNote_shouldReturnNullForNonExistentNote() throws Exception {
- String nonExistentNoteId = "nonExistentNoteId";
- Note note = noteService.get(nonExistentNoteId);
- assertNull(note);
- }
- @Test
- public void deleteAllNotes_shouldClearAllNotes() throws Exception {
- String subject1 = "Note 1";
- String text1 = "First test note.";
- Note note1 = new Note();
- note1.setSubject(subject1);
- note1.setText(text1);
- noteService.insert(note1);
- String subject2 = "Note 2";
- String text2 = "Second test note.";
- Note note2 = new Note();
- note2.setSubject(subject2);
- note2.setText(text2);
- noteService.insert(note2);
- noteService.deleteAll(noteService.getAll());
- assertEquals(0, noteService.getAll().size());
- }
- @Test
- public void getNotesOrderedByTypeAndLastUpdated_shouldReturnNotesInCorrectOrder() {
- Note note1 = new Note();
- note1.setReferenceId("1");
- note1.setReferenceTableId("1");
- note1.setNoteType(Note.EXTERNAL);
- note1.setSubject("First Note");
- note1.setText("This is the first test note.");
- note1.setSysUserId("testUser123");
- System.out.println("Inserting note1: " + note1);
- noteService.insert(note1);
- Note note2 = new Note();
- note2.setReferenceId("1");
- note2.setReferenceTableId("1");
- note2.setNoteType(Note.INTERNAL);
- note2.setSubject("Second Note");
- note2.setText("This is the second test note.");
- note2.setSysUserId("testUser456");
- System.out.println("Inserting note2: " + note2);
- noteService.insert(note2);
- List<Note> notes = noteService.getAllNotesByRefIdRefTable(note1);
- System.out.println("Retrieved notes: " + notes);
- assertFalse("Notes list should not be empty", notes.isEmpty());
- System.out.println("Notes list is not empty.");
- assertEquals("Second note should be internal", Note.INTERNAL, notes.get(0).getNoteType());
- System.out.println("First note's type is correct: " + notes.get(0).getNoteType());
- assertEquals("First note should be external", Note.EXTERNAL, notes.get(1).getNoteType());
- System.out.println("Second note's type is correct: " + notes.get(1).getNoteType());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment