/** * @see DrugValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldPassValidationIfFieldLengthsAreCorrect() { Drug drug = new Drug(); drug.addDrugReferenceMap(new DrugReferenceMap(conceptService.getConceptReferenceTerm(1), conceptService .getConceptMapType(1))); drug.setName("name"); drug.setStrength("strength"); drug.setRetireReason("retireReason"); Errors errors = new BindException(drug, "drug"); new DrugValidator().validate(drug, errors); Assert.assertFalse(errors.hasFieldErrors()); }
/** * @see DrugValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() { Drug drug = new Drug(); drug.addDrugReferenceMap(new DrugReferenceMap(conceptService.getConceptReferenceTerm(1), conceptService .getConceptMapType(1))); drug .setName("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); drug .setStrength("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); drug .setRetireReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); Errors errors = new BindException(drug, "drug"); new DrugValidator().validate(drug, errors); Assert.assertTrue(errors.hasFieldErrors("name")); Assert.assertTrue(errors.hasFieldErrors("strength")); Assert.assertTrue(errors.hasFieldErrors("retireReason")); } }
@Test public void shouldIncludeStrengthInDefaultRepresentation() throws Exception { executeDataSet(DRUG_SEARCH_TEST_DATA); String drugUuid = "8e2323fa-0fa0-461f-9b59-6765997d849d"; Drug drug = conceptService.getDrugByUuid(drugUuid); drug.setStrength("full"); conceptService.saveDrug(drug); SimpleObject result = deserialize(handle(newGetRequest(getURI() + "/" + drugUuid))); Assert.assertThat("full", Matchers.is(PropertyUtils.getProperty(result, "strength"))); }
@Test public void shouldIncludeStrengthInFullRepresentation() throws Exception { executeDataSet(DRUG_SEARCH_TEST_DATA); String drugUuid = "8e2323fa-0fa0-461f-9b59-6765997d849d"; Drug drug = conceptService.getDrugByUuid(drugUuid); drug.setStrength("full"); conceptService.saveDrug(drug); SimpleObject result = deserialize(handle(newGetRequest(getURI() + "/" + drugUuid, new Parameter("v", "full")))); Assert.assertThat("full", Matchers.is(PropertyUtils.getProperty(result, "strength"))); }