Advertisement
Guest User

Untitled

a guest
Aug 15th, 2024
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.55 KB | None | 0 0
  1. package org.openelisglobal.panel;
  2.  
  3. import java.util.List;
  4. import javax.transaction.Transactional;
  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.localization.valueholder.Localization;
  11. import org.openelisglobal.panel.service.PanelService;
  12. import org.openelisglobal.panel.valueholder.Panel;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14.  
  15. public class PanelServiceTest extends BaseWebContextSensitiveTest {
  16.  
  17. @Autowired
  18. PanelService panelService;
  19.  
  20. @Before
  21. public void init() throws Exception {
  22.  
  23. }
  24.  
  25. @After
  26. public void tearDown() {
  27. }
  28.  
  29. @Test
  30. public void createPanel_shouldCreateNewPanel() throws Exception {
  31. String panelName = "Hematology";
  32. String description = "Panel for hematological tests";
  33.  
  34. Panel panel = createPanel(panelName, description);
  35.  
  36. // Save panel to the DB
  37. String panelId = panelService.insert(panel);
  38. Panel savedPanel = panelService.getPanelById(panelId);
  39.  
  40. Assert.assertEquals(1, panelService.getAllPanels().size());
  41. Assert.assertEquals(panelName, savedPanel.getPanelName());
  42. Assert.assertEquals(description, savedPanel.getDescription());
  43. }
  44.  
  45. @Test
  46. @Transactional
  47. public void getAllActivePanels_shouldReturnActivePanels() throws Exception {
  48. Panel activePanel = createPanel("Chemistry", "Active chemistry panel");
  49. Panel inactivePanel = createPanel("InactivePanel", "Inactive panel");
  50.  
  51. activePanel.setSortOrderInt(1);
  52. inactivePanel.setSortOrderInt(0);
  53.  
  54. panelService.insert(activePanel);
  55. panelService.insert(inactivePanel);
  56.  
  57. List<Panel> activePanels = panelService.getAllActivePanels();
  58.  
  59. Assert.assertEquals(1, activePanels.size());
  60. Assert.assertEquals("Chemistry", activePanels.get(0).getPanelName());
  61. }
  62.  
  63. @Test
  64. public void getIdForPanelName_shouldReturnCorrectId() throws Exception {
  65. String panelName = "Serology";
  66. Panel panel = createPanel(panelName, "Serology panel");
  67.  
  68. String panelId = panelService.insert(panel);
  69. String retrievedId = panelService.getIdForPanelName(panelName);
  70.  
  71. Assert.assertEquals(panelId, retrievedId);
  72. }
  73.  
  74. @Test
  75. public void getDescriptionForPanelId_shouldReturnCorrectDescription() throws Exception {
  76. String panelName = "Microbiology";
  77. String description = "Panel for microbiology tests";
  78.  
  79. Panel panel = createPanel(panelName, description);
  80. String panelId = panelService.insert(panel);
  81.  
  82. String retrievedDescription = panelService.getDescriptionForPanelId(panelId);
  83. Assert.assertEquals(description, retrievedDescription);
  84. }
  85.  
  86. @Test
  87. public void updatePanel_shouldUpdatePanelInformation() throws Exception {
  88. String panelName = "Molecular";
  89. String description = "Panel for molecular tests";
  90.  
  91. Panel panel = createPanel(panelName, description);
  92. String panelId = panelService.insert(panel);
  93.  
  94. Panel savedPanel = panelService.getPanelById(panelId);
  95. savedPanel.setPanelName("Molecular Updated");
  96. savedPanel.setDescription("Updated molecular panel");
  97. panelService.update(savedPanel);
  98.  
  99. Panel updatedPanel = panelService.getPanelById(panelId);
  100.  
  101. Assert.assertEquals("Molecular Updated", updatedPanel.getPanelName());
  102. Assert.assertEquals("Updated molecular panel", updatedPanel.getDescription());
  103. }
  104.  
  105. @Test
  106. public void getPanelById_shouldReturnCorrectPanel() throws Exception {
  107. String panelName = "Virology";
  108. Panel panel = createPanel(panelName, "Panel for virology tests");
  109.  
  110. String panelId = panelService.insert(panel);
  111. Panel retrievedPanel = panelService.getPanelById(panelId);
  112.  
  113. Assert.assertNotNull(retrievedPanel);
  114. Assert.assertEquals(panelName, retrievedPanel.getPanelName());
  115. }
  116.  
  117. private Panel createPanel(String panelName, String description) {
  118. Panel panel = new Panel();
  119. panel.setPanelName(panelName);
  120. panel.setDescription(description);
  121. return panel;
  122. }
  123.  
  124. @Test
  125. public void getData_shouldRetrieveDataForPanel() throws Exception {
  126. String panelName = "Immunology";
  127. Panel panel = createPanel(panelName, "Panel for immunological tests");
  128.  
  129. String panelId = panelService.insert(panel);
  130.  
  131. Panel savedPanel = new Panel();
  132. savedPanel.setId(panelId);
  133. panelService.getData(savedPanel);
  134.  
  135. Assert.assertEquals(panelName, savedPanel.getPanelName());
  136. }
  137.  
  138. @Test
  139. public void getTotalPanelCount_shouldReturnCorrectCount() throws Exception {
  140. Panel panel1 = createPanel("Panel 1", "Description 1");
  141. Panel panel2 = createPanel("Panel 2", "Description 2");
  142.  
  143. panelService.insert(panel1);
  144. panelService.insert(panel2);
  145.  
  146. Integer totalCount = panelService.getTotalPanelCount();
  147. Assert.assertEquals(Integer.valueOf(2), totalCount);
  148. }
  149.  
  150. @Test
  151. public void getLocalizationForPanel_shouldReturnCorrectLocalization() throws Exception {
  152. String panelName = "Localization Panel";
  153. Panel panel = createPanel(panelName, "Localization test panel");
  154.  
  155. String panelId = panelService.insert(panel);
  156. Localization localization = panelService.getLocalizationForPanel(panelId);
  157.  
  158. Assert.assertNotNull(localization);
  159. }
  160. }
  161.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement