Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.openelisglobal.panel;
- import java.util.List;
- import javax.transaction.Transactional;
- import org.junit.After;
- import org.junit.Assert;
- import org.junit.Before;
- import org.junit.Test;
- import org.openelisglobal.BaseWebContextSensitiveTest;
- import org.openelisglobal.localization.valueholder.Localization;
- import org.openelisglobal.panel.service.PanelService;
- import org.openelisglobal.panel.valueholder.Panel;
- import org.springframework.beans.factory.annotation.Autowired;
- public class PanelServiceTest extends BaseWebContextSensitiveTest {
- @Autowired
- PanelService panelService;
- @Before
- public void init() throws Exception {
- }
- @After
- public void tearDown() {
- }
- @Test
- public void createPanel_shouldCreateNewPanel() throws Exception {
- String panelName = "Hematology";
- String description = "Panel for hematological tests";
- Panel panel = createPanel(panelName, description);
- // Save panel to the DB
- String panelId = panelService.insert(panel);
- Panel savedPanel = panelService.getPanelById(panelId);
- Assert.assertEquals(1, panelService.getAllPanels().size());
- Assert.assertEquals(panelName, savedPanel.getPanelName());
- Assert.assertEquals(description, savedPanel.getDescription());
- }
- @Test
- @Transactional
- public void getAllActivePanels_shouldReturnActivePanels() throws Exception {
- Panel activePanel = createPanel("Chemistry", "Active chemistry panel");
- Panel inactivePanel = createPanel("InactivePanel", "Inactive panel");
- activePanel.setSortOrderInt(1);
- inactivePanel.setSortOrderInt(0);
- panelService.insert(activePanel);
- panelService.insert(inactivePanel);
- List<Panel> activePanels = panelService.getAllActivePanels();
- Assert.assertEquals(1, activePanels.size());
- Assert.assertEquals("Chemistry", activePanels.get(0).getPanelName());
- }
- @Test
- public void getIdForPanelName_shouldReturnCorrectId() throws Exception {
- String panelName = "Serology";
- Panel panel = createPanel(panelName, "Serology panel");
- String panelId = panelService.insert(panel);
- String retrievedId = panelService.getIdForPanelName(panelName);
- Assert.assertEquals(panelId, retrievedId);
- }
- @Test
- public void getDescriptionForPanelId_shouldReturnCorrectDescription() throws Exception {
- String panelName = "Microbiology";
- String description = "Panel for microbiology tests";
- Panel panel = createPanel(panelName, description);
- String panelId = panelService.insert(panel);
- String retrievedDescription = panelService.getDescriptionForPanelId(panelId);
- Assert.assertEquals(description, retrievedDescription);
- }
- @Test
- public void updatePanel_shouldUpdatePanelInformation() throws Exception {
- String panelName = "Molecular";
- String description = "Panel for molecular tests";
- Panel panel = createPanel(panelName, description);
- String panelId = panelService.insert(panel);
- Panel savedPanel = panelService.getPanelById(panelId);
- savedPanel.setPanelName("Molecular Updated");
- savedPanel.setDescription("Updated molecular panel");
- panelService.update(savedPanel);
- Panel updatedPanel = panelService.getPanelById(panelId);
- Assert.assertEquals("Molecular Updated", updatedPanel.getPanelName());
- Assert.assertEquals("Updated molecular panel", updatedPanel.getDescription());
- }
- @Test
- public void getPanelById_shouldReturnCorrectPanel() throws Exception {
- String panelName = "Virology";
- Panel panel = createPanel(panelName, "Panel for virology tests");
- String panelId = panelService.insert(panel);
- Panel retrievedPanel = panelService.getPanelById(panelId);
- Assert.assertNotNull(retrievedPanel);
- Assert.assertEquals(panelName, retrievedPanel.getPanelName());
- }
- private Panel createPanel(String panelName, String description) {
- Panel panel = new Panel();
- panel.setPanelName(panelName);
- panel.setDescription(description);
- return panel;
- }
- @Test
- public void getData_shouldRetrieveDataForPanel() throws Exception {
- String panelName = "Immunology";
- Panel panel = createPanel(panelName, "Panel for immunological tests");
- String panelId = panelService.insert(panel);
- Panel savedPanel = new Panel();
- savedPanel.setId(panelId);
- panelService.getData(savedPanel);
- Assert.assertEquals(panelName, savedPanel.getPanelName());
- }
- @Test
- public void getTotalPanelCount_shouldReturnCorrectCount() throws Exception {
- Panel panel1 = createPanel("Panel 1", "Description 1");
- Panel panel2 = createPanel("Panel 2", "Description 2");
- panelService.insert(panel1);
- panelService.insert(panel2);
- Integer totalCount = panelService.getTotalPanelCount();
- Assert.assertEquals(Integer.valueOf(2), totalCount);
- }
- @Test
- public void getLocalizationForPanel_shouldReturnCorrectLocalization() throws Exception {
- String panelName = "Localization Panel";
- Panel panel = createPanel(panelName, "Localization test panel");
- String panelId = panelService.insert(panel);
- Localization localization = panelService.getLocalizationForPanel(panelId);
- Assert.assertNotNull(localization);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement