/** * @see ConceptMapTypeValidator#validate(Object,Errors) */ @Test public void validate_shouldPassValidationIfFieldLengthsAreCorrect() { ConceptMapType mapType = new ConceptMapType(); mapType.setName("unique-name"); mapType.setDescription("Description"); mapType.setRetireReason("RetireReason"); Errors errors = new BindException(mapType, "mapType"); new ConceptMapTypeValidator().validate(mapType, errors); Assert.assertEquals(false, errors.hasErrors()); }
/** * @see ConceptMapTypeValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() { ConceptMapType mapType = new ConceptMapType(); mapType.setName("unique-name"); mapType .setDescription("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"); mapType .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(mapType, "mapType"); new ConceptMapTypeValidator().validate(mapType, errors); Assert.assertEquals(true, errors.hasFieldErrors("description")); Assert.assertEquals(true, errors.hasFieldErrors("retireReason")); } }
/** * @see ConceptService#saveConceptMapType(ConceptMapType) */ @Test public void saveConceptMapType_shouldUpdateAnExistingConceptMapType() { ConceptMapType mapType = Context.getConceptService().getConceptMapType(1); //sanity checks Assert.assertNull(mapType.getDateChanged()); Assert.assertNull(mapType.getChangedBy()); mapType.setName("random name"); mapType.setDescription("random description"); ConceptMapType editedMapType = Context.getConceptService().saveConceptMapType(mapType); Context.flushSession(); Assert.assertEquals("random name", editedMapType.getName()); Assert.assertEquals("random description", editedMapType.getDescription()); //date changed and changed by should have been updated Assert.assertNotNull(editedMapType.getDateChanged()); Assert.assertNotNull(editedMapType.getChangedBy()); }