/** * @see ConceptMapTypeValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfTheNameIsAnEmptyString() { ConceptMapType mapType = new ConceptMapType(); mapType.setName(""); Errors errors = new BindException(mapType, "mapType"); new ConceptMapTypeValidator().validate(mapType, errors); Assert.assertEquals(true, errors.hasFieldErrors("name")); }
/** * @see ConceptMapTypeValidator#validate(Object,Errors) */ @Test public void validate_shouldPassIfTheNameIsUniqueAmongstAllConceptMapTypeNames() { ConceptMapType mapType = new ConceptMapType(); mapType.setName("unique-name"); 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_shouldFailIfTheConceptMapTypeNameIsADuplicate() { ConceptMapType mapType = new ConceptMapType(); mapType.setName("is a"); Errors errors = new BindException(mapType, "mapType"); new ConceptMapTypeValidator().validate(mapType, errors); Assert.assertEquals(true, errors.hasFieldErrors("name")); }
/** * @see ConceptMapTypeValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfTheNameIsAWhiteSpaceCharacter() { ConceptMapType mapType = new ConceptMapType(); mapType.setName(" "); Errors errors = new BindException(mapType, "mapType"); new ConceptMapTypeValidator().validate(mapType, errors); Assert.assertEquals(true, errors.hasFieldErrors("name")); }
/** * @see ConceptService#saveConceptMapType(ConceptMapType) */ @Test public void saveConceptMapType_shouldAddTheSpecifiedConceptMapTypeToTheDatabaseAndAssignToItAnId() { ConceptMapType mapType = new ConceptMapType(); mapType.setName("test type"); mapType = Context.getConceptService().saveConceptMapType(mapType); Assert.assertNotNull(mapType.getId()); Assert.assertNotNull(Context.getConceptService().getConceptMapTypeByName("test type")); }
/** * @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()); }