/** * @see ConceptMapTypeValidator#validate(Object,Errors) */ @Test(expected = IllegalArgumentException.class) public void validate_shouldFailIfTheConceptMapTypeObjectIsNull() { Errors errors = new BindException(new ConceptMapType(), "mapType"); new ConceptMapTypeValidator().validate(null, errors); }
/** * @see ConceptReferenceTerm#addConceptReferenceTermMap(ConceptReferenceTermMap) */ @Test public void addConceptReferenceTermMap_shouldNotAddAMapWhereTermBIsItself() { ConceptReferenceTerm term = new ConceptReferenceTerm(2); term.setUuid("test uuid"); term.addConceptReferenceTermMap(new ConceptReferenceTermMap(new ConceptReferenceTerm(1), new ConceptMapType(1))); //add a mapping where termB is itself term.addConceptReferenceTermMap(new ConceptReferenceTermMap(term, new ConceptMapType(1))); Assert.assertEquals(1, term.getConceptReferenceTermMaps().size()); }
/** * @see ConceptReferenceTerm#addConceptReferenceTermMap(ConceptReferenceTermMap) */ @Test public void addConceptReferenceTermMap_shouldSetTermAAsTheTermToWhichAMappingIsBeingAdded() { ConceptReferenceTerm term = new ConceptReferenceTerm(2); term.addConceptReferenceTermMap(new ConceptReferenceTermMap(new ConceptReferenceTerm(1), new ConceptMapType(1))); Assert.assertEquals(true, term.equals(term.getConceptReferenceTermMaps().iterator().next().getTermA())); }
/** * @see DelegatingCrudResource#newDelegate() */ @Override public ConceptMapType newDelegate() { return new ConceptMapType(); }
/** * @see DrugValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldInvokeConceptMapTypeValidatorIfConceptMapTypeOnDrugReferenceMapIsNew() { Drug drug = new Drug(); drug.addDrugReferenceMap(new DrugReferenceMap(conceptService.getConceptReferenceTerm(1), new ConceptMapType())); Errors errors = new BindException(drug, "drug"); new DrugValidator().validate(drug, errors); //concept map type validator should have been called which should reject a null name Assert.assertTrue(errors.hasFieldErrors("drugReferenceMaps[0].conceptMapType.name")); }
/** * @see Concept#removeConceptMapping(ContentMap) */ @Test public void removeConceptMapping_shouldRemoveConceptMapPassedFromListOfMappings() { Concept c = new Concept(); ConceptMap c1 = new ConceptMap(1); c1.setConceptMapType(new ConceptMapType(1)); ConceptMap c2 = new ConceptMap(2); c2.setConceptMapType(new ConceptMapType(2)); c.addConceptMapping(c1); c.addConceptMapping(c2); Collection<ConceptMap> mappings = c.getConceptMappings(); Assert.assertEquals(2, mappings.size()); c.removeConceptMapping(c1); mappings = c.getConceptMappings(); Assert.assertTrue(mappings.contains(c2)); Assert.assertEquals(1, mappings.size()); }
/** * @see ConceptMapTypeValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfTheNameIsNull() { ConceptMapType mapType = new ConceptMapType(); Errors errors = new BindException(mapType, "mapType"); new ConceptMapTypeValidator().validate(mapType, errors); Assert.assertEquals(true, errors.hasFieldErrors("name")); }
/** * @see ConceptReferenceTermValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfTermBOfAConceptReferenceTermMapIsNotSet() { ConceptReferenceTerm term = new ConceptReferenceTerm(); term.setName("name"); term.setCode("code"); term.setConceptSource(Context.getConceptService().getConceptSource(1)); Set<ConceptReferenceTermMap> maps = new LinkedHashSet<>(); maps.add(new ConceptReferenceTermMap(null, new ConceptMapType(1))); term.setConceptReferenceTermMaps(maps); Errors errors = new BindException(term, "term"); new ConceptReferenceTermValidator().validate(term, errors); Assert.assertEquals(true, errors.hasFieldErrors("conceptReferenceTermMaps[0].termB")); }
/** * @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 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 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")); }
private static ConceptMap getConceptMap(String sourceHl7Code, String code, String mapTypeUuid) { ConceptMap conceptMap = new ConceptMap(); ConceptReferenceTerm conceptReferenceTerm = new ConceptReferenceTerm(); ConceptSource conceptSource = new ConceptSource(); conceptSource.setHl7Code(sourceHl7Code); conceptReferenceTerm.setConceptSource(conceptSource); conceptReferenceTerm.setCode(code); conceptMap.setConceptReferenceTerm(conceptReferenceTerm); ConceptMapType conceptMapType = new ConceptMapType(); if (mapTypeUuid != null) { conceptMapType.setUuid(mapTypeUuid); } else { conceptMapType.setUuid(ConceptMapType.SAME_AS_MAP_TYPE_UUID); } conceptMap.setConceptMapType(conceptMapType); return conceptMap; }
/** * @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")); } }