Search in sources :

Example 36 with ConceptClass

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());
}
Also used : Concept(org.openmrs.Concept) Locale(java.util.Locale) ConceptClass(org.openmrs.ConceptClass) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptDatatype(org.openmrs.ConceptDatatype) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 37 with ConceptClass

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"));
}
Also used : Errors(org.springframework.validation.Errors) ConceptClass(org.openmrs.ConceptClass) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 38 with ConceptClass

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());
}
Also used : Errors(org.springframework.validation.Errors) ConceptClass(org.openmrs.ConceptClass) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 39 with ConceptClass

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()));
}
Also used : Concept(org.openmrs.Concept) ConceptClass(org.openmrs.ConceptClass) User(org.openmrs.User) ConceptDatatype(org.openmrs.ConceptDatatype) Date(java.util.Date) Test(org.junit.Test)

Example 40 with ConceptClass

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());
}
Also used : Errors(org.springframework.validation.Errors) ConceptClass(org.openmrs.ConceptClass) OrderType(org.openmrs.OrderType) BindException(org.springframework.validation.BindException) HashSet(java.util.HashSet) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

ConceptClass (org.openmrs.ConceptClass)55 Test (org.junit.Test)50 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)46 ConceptDatatype (org.openmrs.ConceptDatatype)38 ConceptName (org.openmrs.ConceptName)33 ConceptDescription (org.openmrs.ConceptDescription)31 Concept (org.openmrs.Concept)27 Locale (java.util.Locale)12 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)12 BindException (org.springframework.validation.BindException)9 Errors (org.springframework.validation.Errors)9 OrderType (org.openmrs.OrderType)5 HashSet (java.util.HashSet)4 ConceptMap (org.openmrs.ConceptMap)3 ConceptNumeric (org.openmrs.ConceptNumeric)3 ConceptBuilder (org.openmrs.module.emrapi.test.builder.ConceptBuilder)3 ConceptComplex (org.openmrs.ConceptComplex)2 ConceptMapType (org.openmrs.ConceptMapType)2 ConceptSearchResult (org.openmrs.ConceptSearchResult)2 ConceptSource (org.openmrs.ConceptSource)2