Skip to content

Commit

Permalink
COH-49 :added foreignKey constraint to cohort (#31)
Browse files Browse the repository at this point in the history
update unit test for changes made for purge cohortType

update unit tests

update unit tests

COH-49 : changed liquibase changeset id

COH-49 : changed liquibase changeset id
  • Loading branch information
ManojLL authored Aug 30, 2023
1 parent a8fd4f0 commit 819b139
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions api/src/main/resources/liquibase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -347,5 +347,14 @@
</createIndex>
</changeSet>

<changeSet id="add_foreignKey_constraint_to_cohort_type_id" author="manojll">
<preConditions>
<columnExists tableName="cohort" columnName="cohort_type_id"/>
</preConditions>
<addForeignKeyConstraint baseTableName="cohort" baseColumnNames="cohort_type_id"
constraintName="cohort_cohort_type_fk" referencedTableName="cohort_type" referencedColumnNames="cohort_type_id"
onDelete="RESTRICT" />
</changeSet>

<include file="liquibase/3.x-liquibase-changeSet.xml"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import org.hibernate.exception.ConstraintViolationException;
import org.junit.Before;
import org.junit.Test;
import org.openmrs.api.context.Context;
Expand All @@ -24,6 +27,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;


public class CohortTypeGenericDaoTest extends BaseModuleContextSensitiveTest {

private static final String COHORT_TYPE_INITIAL_TEST_DATA_XML = "org/openmrs/module/cohort/api/hibernate/db/CohortTypeDaoTest_initialTestData.xml";
Expand Down Expand Up @@ -79,4 +83,21 @@ public void shouldVoidCohortType() {
assertThat(voidedCohortType, nullValue());
}

@Test
public void shouldPurgeCohortType() {
CohortType cohortType = dao.get(COHORT_TYPE_UUID);
assertNotNull(cohortType);
dao.delete(cohortType);
CohortType afterAttemptPurge = dao.get(COHORT_TYPE_UUID);
assertNull(afterAttemptPurge);
}

@Test(expected = ConstraintViolationException.class)
public void shouldThrowExceptionForPurgeCohortType() {
CohortType cohortType = dao.get("94517bf9-d9d6-4726-b4f1-a2dff6b36e2d");
assertNotNull(cohortType);
dao.delete(cohortType);
Context.flushSession();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
graphic logo is a trademark of OpenMRS Inc.
-->
<dataset>
<location location_id="101" name="Cohort-21 Location" creator="1" date_created="2021-10-14 00:00:00.0" retired="false"
uuid="65ab9667-7435-49af-8be8-65a4b58fc78k"/>

<cohort_type cohort_type_id="101" name="cohort type name" description="cohort type description" creator="1"
date_created="2005-01-01 00:00:00.0" voided="false" uuid="94517bf9-d8d7-4726-b4f1-a2dff6b36e2d"/>

<cohort_type cohort_type_id="102" name="cohort type 2" description="cohort type description" creator="1"
date_created="2005-01-01 00:00:00.0" voided="false" uuid="94517bf9-d9d6-4726-b4f1-a2dff6b36e2d"/>

<cohort cohort_id="12" name="COVID-20 patients" description="COVID-19 patients" is_group_cohort="0" creator="1"
definition_handler="org.openmrs.module.cohort.definition.handler.DefaultCohortDefinitionHandler"
location_id="101" cohort_type_id="102" date_created="2005-01-01 00:00:00.0" voided="false" uuid="8f9a2479-c14a-4bfc-bcaa-632860258519"/>
</dataset>

0 comments on commit 819b139

Please sign in to comment.