|
| 1 | +/* |
| 2 | + * This Source Code Form is subject to the terms of the Mozilla Public License, |
| 3 | + * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 4 | + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under |
| 5 | + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. |
| 6 | + * |
| 7 | + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS |
| 8 | + * graphic logo is a trademark of OpenMRS Inc. |
| 9 | + */ |
| 10 | +package org.openmrs.module.queue.api; |
| 11 | + |
| 12 | +import static org.junit.Assert.assertNotNull; |
| 13 | +import static org.junit.Assert.assertNull; |
| 14 | + |
| 15 | +import java.util.Arrays; |
| 16 | +import java.util.List; |
| 17 | + |
| 18 | +import org.junit.Before; |
| 19 | +import org.junit.Test; |
| 20 | +import org.openmrs.module.queue.SpringTestConfiguration; |
| 21 | +import org.openmrs.module.queue.exception.DuplicateQueueEntryException; |
| 22 | +import org.openmrs.module.queue.model.QueueEntry; |
| 23 | +import org.openmrs.module.queue.model.QueueEntryTransition; |
| 24 | +import org.openmrs.test.BaseModuleContextSensitiveTest; |
| 25 | +import org.springframework.beans.factory.annotation.Autowired; |
| 26 | +import org.springframework.beans.factory.annotation.Qualifier; |
| 27 | +import org.springframework.test.context.ContextConfiguration; |
| 28 | + |
| 29 | +@ContextConfiguration(classes = SpringTestConfiguration.class, inheritLocations = false) |
| 30 | +public class QueueEntryServiceTest extends BaseModuleContextSensitiveTest { |
| 31 | + |
| 32 | + private static final List<String> INITIAL_DATASET_XML = Arrays.asList( |
| 33 | + "org/openmrs/module/queue/api/dao/QueueDaoTest_locationInitialDataset.xml", |
| 34 | + "org/openmrs/module/queue/api/dao/QueueEntryDaoTest_conceptsInitialDataset.xml", |
| 35 | + "org/openmrs/module/queue/api/dao/QueueEntryDaoTest_patientInitialDataset.xml", |
| 36 | + "org/openmrs/module/queue/api/dao/VisitQueueEntryDaoTest_visitInitialDataset.xml", |
| 37 | + "org/openmrs/module/queue/api/dao/QueueDaoTest_initialDataset.xml", |
| 38 | + "org/openmrs/module/queue/api/dao/QueueEntryDaoTest_initialDataset.xml", |
| 39 | + "org/openmrs/module/queue/validators/QueueEntryValidatorTest_globalPropertyInitialDataset.xml"); |
| 40 | + |
| 41 | + @Autowired |
| 42 | + @Qualifier("queue.QueueEntryService") |
| 43 | + private QueueEntryService queueEntryService; |
| 44 | + |
| 45 | + @Before |
| 46 | + public void setup() { |
| 47 | + INITIAL_DATASET_XML.forEach(this::executeDataSet); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void transitionQueueEntryShouldNotEndInitialIfNewIsDuplicate() { |
| 52 | + QueueEntry queueEntry = queueEntryService.getQueueEntryById(3).get(); |
| 53 | + QueueEntryTransition transition = new QueueEntryTransition(); |
| 54 | + transition.setQueueEntryToTransition(queueEntry); |
| 55 | + transition.setTransitionDate(queueEntry.getStartedAt()); |
| 56 | + try { |
| 57 | + queueEntryService.transitionQueueEntry(transition); |
| 58 | + } |
| 59 | + catch (DuplicateQueueEntryException ex) { |
| 60 | + assertNull(queueEntryService.getQueueEntryById(3).get().getEndedAt()); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + public void transitionQueueEntryShouldEndInitialIfNewIsNotDuplicate() { |
| 66 | + QueueEntry queueEntry = queueEntryService.getQueueEntryById(1).get(); |
| 67 | + QueueEntryTransition transition = new QueueEntryTransition(); |
| 68 | + transition.setQueueEntryToTransition(queueEntry); |
| 69 | + transition.setTransitionDate(queueEntry.getStartedAt()); |
| 70 | + assertNotNull(queueEntryService.getQueueEntryById(1).get().getEndedAt()); |
| 71 | + } |
| 72 | +} |
0 commit comments