From 57be4edcbd425e765254717bc8a085dd32e41eb4 Mon Sep 17 00:00:00 2001 From: Agaba Derrick Date: Thu, 9 Jan 2025 21:47:23 +0300 Subject: [PATCH] OrderedByType --- .../org/openelisglobal/AppTestConfig.java | 24 +++++++++++++ .../openelisglobal/note/NoteServiceTest.java | 36 +++++++++++++++++-- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/openelisglobal/AppTestConfig.java b/src/test/java/org/openelisglobal/AppTestConfig.java index 58b807c5eb..909c012f82 100644 --- a/src/test/java/org/openelisglobal/AppTestConfig.java +++ b/src/test/java/org/openelisglobal/AppTestConfig.java @@ -16,12 +16,18 @@ 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.daoimpl.NoteDAOImpl; 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.organization.service.OrganizationTypeServiceImpl; import org.openelisglobal.program.service.ImmunohistochemistrySampleService; import org.openelisglobal.program.service.PathologySampleService; import org.openelisglobal.program.service.ProgramSampleService; @@ -340,6 +346,24 @@ public StatusOfSampleService statusOfSampleService() { return mock(StatusOfSampleService.class); } + @Bean + @Profile("test") + public OrganizationTypeService organizationTypeService() { + return new OrganizationTypeServiceImpl(); + } + + @Bean + @Profile("test") + public NoteDAO NoteDAO() { + return new NoteDAOImpl(); + } + + @Bean + @Profile("test") + public OrganizationTypeDAO organizationTypeDAO() { + return new OrganizationTypeDAOImpl(); + } + @Override public void configureMessageConverters(@NonNull List> converters) { WebMvcConfigurer.super.configureMessageConverters(converters); diff --git a/src/test/java/org/openelisglobal/note/NoteServiceTest.java b/src/test/java/org/openelisglobal/note/NoteServiceTest.java index 86e1e0816a..bd2dd8a08b 100644 --- a/src/test/java/org/openelisglobal/note/NoteServiceTest.java +++ b/src/test/java/org/openelisglobal/note/NoteServiceTest.java @@ -1,13 +1,15 @@ package org.openelisglobal.note; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +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; @@ -17,9 +19,11 @@ public class NoteServiceTest extends BaseWebContextSensitiveTest { @Autowired NoteService noteService; + @Autowired + NoteDAO noteDAO; + @Before public void init() throws Exception { - assertNotNull(noteService); noteService.deleteAll(noteService.getAll()); } @@ -73,4 +77,32 @@ public void deleteAllNotes_shouldClearAllNotes() throws Exception { 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 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()); + } + }