|
37 | 37 | import static org.openlmis.requisition.i18n.MessageKeys.ERROR_OPTION_NOT_AVAILABLE; |
38 | 38 | import static org.openlmis.requisition.i18n.MessageKeys.ERROR_SOURCE_NOT_AVAILABLE; |
39 | 39 | import static org.openlmis.requisition.i18n.MessageKeys.ERROR_SOURCE_OF_REQUISITION_TEMPLATE_COLUMN_CANNOT_BE_NULL; |
| 40 | +import static org.openlmis.requisition.i18n.MessageKeys.ERROR_VALIDATION_CANNOT_ASSIGN_WARD_SERVICE_TYPE; |
40 | 41 | import static org.openlmis.requisition.i18n.MessageKeys.ERROR_VALIDATION_COLUMN_DEFINITION_MODIFIED; |
41 | 42 | import static org.openlmis.requisition.i18n.MessageKeys.ERROR_VALIDATION_COLUMN_DEFINITION_NOT_FOUND; |
42 | 43 | import static org.openlmis.requisition.i18n.MessageKeys.ERROR_VALIDATION_FIELD_CANNOT_BE_NULL; |
|
51 | 52 | import static org.openlmis.requisition.validate.RequisitionTemplateDtoValidator.CALCULATED_ORDER_QUANTITY; |
52 | 53 | import static org.openlmis.requisition.validate.RequisitionTemplateDtoValidator.COLUMNS_MAP; |
53 | 54 | import static org.openlmis.requisition.validate.RequisitionTemplateDtoValidator.FACILITY_TYPE; |
54 | | -import static org.openlmis.requisition.validate.RequisitionTemplateDtoValidator.FACILITY_TYPE_ID; |
| 55 | +import static org.openlmis.requisition.validate.RequisitionTemplateDtoValidator.FACILITY_TYPES; |
55 | 56 | import static org.openlmis.requisition.validate.RequisitionTemplateDtoValidator.MAX_COLUMN_DEFINITION_LENGTH; |
56 | 57 | import static org.openlmis.requisition.validate.RequisitionTemplateDtoValidator.NUMBER_OF_PERIODS_TO_AVERAGE; |
57 | 58 | import static org.openlmis.requisition.validate.RequisitionTemplateDtoValidator.PROGRAM; |
|
64 | 65 | import static org.openlmis.requisition.validate.RequisitionTemplateDtoValidator.TOTAL_LOSSES_AND_ADJUSTMENTS; |
65 | 66 | import static org.openlmis.requisition.validate.RequisitionTemplateDtoValidator.TOTAL_RECEIVED_QUANTITY; |
66 | 67 | import static org.openlmis.requisition.validate.RequisitionTemplateDtoValidator.TOTAL_STOCKOUT_DAYS; |
| 68 | +import static org.openlmis.requisition.validate.RequisitionTemplateDtoValidator.WARD_SERVICE_TYPE; |
67 | 69 |
|
68 | 70 | import java.util.Optional; |
69 | 71 | import java.util.Random; |
|
75 | 77 | import org.junit.runner.RunWith; |
76 | 78 | import org.mockito.InjectMocks; |
77 | 79 | import org.mockito.Mock; |
78 | | -import org.mockito.runners.MockitoJUnitRunner; |
| 80 | +import org.mockito.junit.MockitoJUnitRunner; |
79 | 81 | import org.openlmis.requisition.domain.AvailableRequisitionColumn; |
80 | 82 | import org.openlmis.requisition.domain.AvailableRequisitionColumnOption; |
81 | 83 | import org.openlmis.requisition.domain.RequisitionTemplate; |
82 | 84 | import org.openlmis.requisition.domain.RequisitionTemplateColumn; |
83 | 85 | import org.openlmis.requisition.domain.RequisitionTemplateColumnDataBuilder; |
84 | 86 | import org.openlmis.requisition.domain.RequisitionTemplateDataBuilder; |
85 | 87 | import org.openlmis.requisition.dto.AvailableRequisitionColumnOptionDto; |
86 | | -import org.openlmis.requisition.dto.FacilityTypeDto; |
87 | 88 | import org.openlmis.requisition.dto.RequisitionTemplateColumnDto; |
88 | 89 | import org.openlmis.requisition.dto.RequisitionTemplateDto; |
89 | 90 | import org.openlmis.requisition.repository.AvailableRequisitionColumnRepository; |
90 | 91 | import org.openlmis.requisition.service.referencedata.FacilityTypeReferenceDataService; |
91 | 92 | import org.openlmis.requisition.service.referencedata.ProgramReferenceDataService; |
92 | 93 | import org.openlmis.requisition.testutils.AvailableRequisitionColumnDataBuilder; |
93 | 94 | import org.openlmis.requisition.testutils.AvailableRequisitionColumnOptionDataBuilder; |
| 95 | +import org.openlmis.requisition.testutils.FacilityTypeDtoDataBuilder; |
94 | 96 | import org.openlmis.requisition.testutils.ProgramDtoDataBuilder; |
95 | 97 | import org.openlmis.requisition.utils.Message; |
96 | 98 | import org.springframework.validation.Errors; |
@@ -517,11 +519,26 @@ public void shouldRejectIfFacilityTypeWithSpecifiedIdDoesNotExist() throws Excep |
517 | 519 | when(facilityTypeReferenceDataService.findOne(facilityTypeId)).thenReturn(null); |
518 | 520 |
|
519 | 521 | validator.validate(requisitionTemplate, errors); |
520 | | - verify(errors).rejectValue(eq(FACILITY_TYPE_ID), |
| 522 | + verify(errors).rejectValue(eq(FACILITY_TYPES), |
521 | 523 | eq(new Message(ERROR_VALIDATION_REFERENCED_OBJECT_DOES_NOT_EXIST, |
522 | 524 | FACILITY_TYPE, facilityTypeId).toString())); |
523 | 525 | } |
524 | 526 |
|
| 527 | + @Test |
| 528 | + public void shouldRejectIfFacilityTypeIsWardService() throws Exception { |
| 529 | + RequisitionTemplateDto requisitionTemplate = generateTemplate(); |
| 530 | + UUID facilityTypeId = requisitionTemplate.getFacilityTypeIds().iterator().next(); |
| 531 | + when(facilityTypeReferenceDataService.findOne(facilityTypeId)) |
| 532 | + .thenReturn(new FacilityTypeDtoDataBuilder() |
| 533 | + .withId(facilityTypeId) |
| 534 | + .withCode(WARD_SERVICE_TYPE) |
| 535 | + .buildAsDto()); |
| 536 | + |
| 537 | + validator.validate(requisitionTemplate, errors); |
| 538 | + verify(errors).rejectValue(eq(FACILITY_TYPES), |
| 539 | + eq(new Message(ERROR_VALIDATION_CANNOT_ASSIGN_WARD_SERVICE_TYPE).toString())); |
| 540 | + } |
| 541 | + |
525 | 542 | @Test |
526 | 543 | public void shouldRejectWhenSourceInRequisitionTemplateColumnIsNull() throws Exception { |
527 | 544 | RequisitionTemplateDto requisitionTemplate = generateTemplate(); |
@@ -709,7 +726,7 @@ private void mockResponses(RequisitionTemplateDto template) { |
709 | 726 |
|
710 | 727 | for (UUID facilityTypeId : template.getFacilityTypeIds()) { |
711 | 728 | when(facilityTypeReferenceDataService.findOne(facilityTypeId)).thenReturn( |
712 | | - new FacilityTypeDto()); |
| 729 | + new FacilityTypeDtoDataBuilder().buildAsDto()); |
713 | 730 | } |
714 | 731 | } |
715 | 732 |
|
|
0 commit comments