use of org.openmrs.ConceptClass in project openmrs-core by openmrs.
the class ConceptServiceImplTest method saveConcept_shouldForceSetFlagIfSetMembersExist.
/**
* @see ConceptServiceImpl#saveConcept(Concept)
*/
@Test
public void saveConcept_shouldForceSetFlagIfSetMembersExist() {
// Given
Concept concept = new Concept();
concept.addName(new ConceptName("Concept", new Locale("en", "US")));
concept.addDescription(new ConceptDescription("some description", null));
concept.setDatatype(new ConceptDatatype(1));
concept.setConceptClass(new ConceptClass(1));
Concept conceptSetMember = new Concept();
conceptSetMember.addName(new ConceptName("Set Member", new Locale("en", "US")));
conceptSetMember.addDescription(new ConceptDescription("some description", null));
conceptSetMember.setConceptClass(new ConceptClass(1));
conceptSetMember.setDatatype(new ConceptDatatype(1));
Context.getConceptService().saveConcept(conceptSetMember);
concept.addSetMember(conceptSetMember);
concept.setSet(false);
// When
Context.getConceptService().saveConcept(concept);
// Then
assertTrue(concept.getSet());
}
use of org.openmrs.ConceptClass in project openmrs-core by openmrs.
the class ConceptClassValidatorTest method validate_shouldFailValidationIfUserIsNullOrEmptyOrWhitespace.
/**
* @see ConceptClassValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfUserIsNullOrEmptyOrWhitespace() {
ConceptClass cc = new ConceptClass();
cc.setName(null);
cc.setDescription("some text");
Errors errors = new BindException(cc, "cc");
new ConceptClassValidator().validate(cc, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
cc.setName("");
errors = new BindException(cc, "cc");
new ConceptClassValidator().validate(cc, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
cc.setName(" ");
errors = new BindException(cc, "cc");
new ConceptClassValidator().validate(cc, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
}
use of org.openmrs.ConceptClass in project openmrs-core by openmrs.
the class ConceptClassValidatorTest method validate_shouldFailValidationIfConceptClassNameAlreadyExist.
/**
* @see ConceptClassValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfConceptClassNameAlreadyExist() {
ConceptClass cc = new ConceptClass();
cc.setName("Test");
cc.setDescription("some text");
Errors errors = new BindException(cc, "cc");
new ConceptClassValidator().validate(cc, errors);
Assert.assertTrue(errors.hasErrors());
}
use of org.openmrs.ConceptClass in project openmrs-core by openmrs.
the class JavaSerializationTest method shouldSerializeOpenMrsMetadata.
@Test
public void shouldSerializeOpenMrsMetadata() {
Date date = new Date();
User user = new User(1);
Concept originalConcept = new Concept();
originalConcept.setConceptClass(new ConceptClass(1));
originalConcept.setDatatype(new ConceptDatatype(1));
originalConcept.setUuid("abc123");
originalConcept.setDateCreated(date);
originalConcept.setCreator(user);
originalConcept.setDateChanged(date);
originalConcept.setChangedBy(user);
originalConcept.setRetired(true);
originalConcept.setRetiredBy(user);
originalConcept.setDateRetired(date);
originalConcept.setRetireReason("test");
byte[] serialized = SerializationUtils.serialize(originalConcept);
Concept copyConcept = (Concept) SerializationUtils.deserialize(serialized);
assertThat(copyConcept.getConceptClass(), is(originalConcept.getConceptClass()));
assertThat(copyConcept.getDatatype(), is(originalConcept.getDatatype()));
assertThat(copyConcept.getDateCreated(), is(originalConcept.getDateCreated()));
assertThat(copyConcept.getCreator(), is(originalConcept.getCreator()));
assertThat(copyConcept.getDateChanged(), is(originalConcept.getDateChanged()));
assertThat(copyConcept.getChangedBy(), is(originalConcept.getChangedBy()));
assertThat(copyConcept.getRetired(), is(originalConcept.getRetired()));
assertThat(copyConcept.getRetiredBy(), is(originalConcept.getRetiredBy()));
assertThat(copyConcept.getDateRetired(), is(originalConcept.getDateRetired()));
assertThat(copyConcept.getRetireReason(), is(originalConcept.getRetireReason()));
assertThat(copyConcept.getUuid(), is(originalConcept.getUuid()));
}
use of org.openmrs.ConceptClass in project openmrs-core by openmrs.
the class OrderTypeValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see OrderTypeValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
OrderType orderType = new OrderType();
orderType.setName("unique name");
orderType.setJavaClassName("org.openmrs.TestDrugOrder");
Collection<ConceptClass> col = new HashSet<>();
col.add(Context.getConceptService().getConceptClass(2));
orderType.setConceptClasses(col);
orderType.setDescription("description");
orderType.setRetireReason("retireReason");
Errors errors = new BindException(orderType, "orderType");
new OrderTypeValidator().validate(orderType, errors);
Assert.assertFalse(errors.hasErrors());
}
Aggregations