/** * @verifies fail validation if route is null for SIMPLE dosingType * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailValidationIfRouteIsNullForSIMPLEDosingType() throws Exception { DrugOrder order = new DrugOrder(); order.setDosingType(DrugOrder.DosingType.SIMPLE); order.setRoute(null); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("route")); }
private DrugOrder createValidDrugOrder() { DrugOrder drugOrder = new DrugOrder(); drugOrder.setDose(10.0); drugOrder.setDoseUnits(createConceptWithName("ml")); drugOrder.setRoute(createConceptWithName("IV")); OrderFrequency frequency = new OrderFrequency(); frequency.setConcept(createConceptWithName("Twice a day")); drugOrder.setFrequency(frequency); return drugOrder; }
/** * @verifies fail if route is not a valid concept * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailIfRouteIsNotAValidConcept() throws Exception { Concept concept = Context.getConceptService().getConcept(3); assertThat(concept, not(isIn(Context.getOrderService().getDrugRoutes()))); DrugOrder order = new DrugOrder(); order.setDosingType(DrugOrder.DosingType.FREE_TEXT); order.setDuration(5.0); order.setDurationUnits(concept); order.setDose(1.0); order.setDoseUnits(concept); order.setQuantity(30.0); order.setQuantityUnits(concept); order.setRoute(concept); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("route")); Assert.assertEquals( "DrugOrder.error.routeNotAmongAllowedConcepts", errors.getFieldError("route").getCode()); }