Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add-noteservice-Tests #1309

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/test/java/org/openelisglobal/AppTestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@
import org.openelisglobal.internationalization.MessageUtil;
import org.openelisglobal.localization.dao.LocalizationDAO;
import org.openelisglobal.localization.service.LocalizationServiceImpl;
import org.openelisglobal.note.dao.NoteDAO;
import org.openelisglobal.note.service.NoteService;
import org.openelisglobal.notification.service.AnalysisNotificationConfigService;
import org.openelisglobal.notification.service.TestNotificationConfigService;
import org.openelisglobal.observationhistory.service.ObservationHistoryService;
import org.openelisglobal.observationhistorytype.service.ObservationHistoryTypeService;
import org.openelisglobal.organization.dao.OrganizationTypeDAO;
import org.openelisglobal.organization.daoimpl.OrganizationTypeDAOImpl;
import org.openelisglobal.organization.service.OrganizationService;
import org.openelisglobal.organization.service.OrganizationTypeService;
import org.openelisglobal.panel.service.PanelService;
import org.openelisglobal.panelitem.service.PanelItemService;
import org.openelisglobal.program.service.ImmunohistochemistrySampleService;
Expand Down Expand Up @@ -213,6 +218,12 @@ public RequesterTypeService requesterTypeService() {
return mock(RequesterTypeService.class);
}

@Bean()
@Profile("test")
public OrganizationService organizationService() {
return mock(OrganizationService.class);
}

@Bean()
@Profile("test")
public BasicAuthenticationDataService basicAuthenticationDataService() {
Expand Down Expand Up @@ -404,6 +415,24 @@ public StatusOfSampleService statusOfSampleService() {
return mock(StatusOfSampleService.class);
}

@Bean
@Profile("test")
public OrganizationTypeService OrganizationTypeService() {
return mock(OrganizationTypeService.class);
}

@Bean
@Profile("test")
public NoteDAO NoteDAO() {
return mock(NoteDAO.class);
}

@Bean
@Profile("test")
public OrganizationTypeDAO organizationTypeDAO() {
return new OrganizationTypeDAOImpl();
}

@Override
public void configureMessageConverters(@NonNull List<HttpMessageConverter<?>> converters) {
WebMvcConfigurer.super.configureMessageConverters(converters);
Expand Down
108 changes: 108 additions & 0 deletions src/test/java/org/openelisglobal/note/NoteServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package org.openelisglobal.note;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;

import java.util.List;
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;

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.INTERNAL);
note1.setSubject("First Note");
note1.setText("This is the first test note.");
note1.setSysUserId("testUser123");
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");
noteService.insert(note2);

List<Note> notes = noteService.getAllNotesByRefIdRefTable(note1);
assertFalse("Notes list should not be empty", notes.isEmpty());

assertEquals("Second note should be internal", Note.INTERNAL, notes.get(0).getNoteType());
assertEquals("First note should be external", Note.INTERNAL, notes.get(1).getNoteType());
}

}
Loading