Skip to content

Commit

Permalink
#73 | Add test to ensure that duplicate runs do not create duplicate …
Browse files Browse the repository at this point in the history
…rows for organisations and groups
  • Loading branch information
vinayvenu committed Oct 3, 2023
1 parent bc578d7 commit 88f1331
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 4 deletions.
42 changes: 38 additions & 4 deletions src/test/java/org/avniproject/etl/DataSyncIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,20 +207,54 @@ public void addressLevelColumnsAreCreated() {
}

@Test
@Sql({"/test-data-teardown.sql", "/organisation-group.sql"})
@Sql(scripts = "/test-data-teardown.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
@Sql({"/test-data-teardown.sql", "/organisation-group-teardown.sql", "/organisation-group.sql"})
@Sql(scripts = {"/test-data-teardown.sql", "/organisation-group-teardown.sql"}, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void allTheDBUserOfOrgGroupAreAbleToQueryTables() {
etlService.runForOrganisationGroup("og");
etlService.runForOrganisationGroup("og");

etlService.runFor(OrganisationIdentity.createForOrganisation("ogi1", "ogi1"));

etlService.runForOrganisationGroup("og");
etlService.runFor(OrganisationIdentity.createForOrganisation("ogi1", "ogi1"));

jdbcTemplate.execute("set role og;");
List<Map<String, Object>> groupList = jdbcTemplate.queryForList("select * from og.person;");
jdbcTemplate.execute("set role ogi1;");
List<Map<String, Object>> child1List = jdbcTemplate.queryForList("select * from og.person;");
jdbcTemplate.execute("set role ogi2;");
List<Map<String, Object>> child2List = jdbcTemplate.queryForList("select * from og.person;");
jdbcTemplate.execute("reset role;");

assertThat("Group organisation schema contains data from both individual organisations", groupList.size(), is(2));
assertThat("Member organisations will also get the same data as the group organisations", child1List.size(), is(2));
assertThat("Member organisations will also get the same data as the group organisations", child2List.size(), is(2));
}

@Test
@Sql({"/test-data-teardown.sql", "/organisation-group-teardown.sql", "/organisation-group.sql"})
@Sql(scripts = {"/test-data-teardown.sql", "/organisation-group-teardown.sql"}, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void multipleRunsShouldNotCauseDuplicateDataInOrganisationsAndGroups() {

etlService.runFor(OrganisationIdentity.createForOrganisation("ogi2", "ogi2"));
etlService.runForOrganisationGroup("og");
etlService.runFor(OrganisationIdentity.createForOrganisation("ogi1", "ogi1"));

etlService.runFor(OrganisationIdentity.createForOrganisation("ogi2", "ogi2"));
etlService.runForOrganisationGroup("og");
etlService.runFor(OrganisationIdentity.createForOrganisation("ogi1", "ogi1"));

jdbcTemplate.execute("set role og;");
List<Map<String, Object>> groupList = jdbcTemplate.queryForList("select * from og.person;");
jdbcTemplate.execute("set role ogi1;");
List<Map<String, Object>> child1List = jdbcTemplate.queryForList("select * from ogi1.person;");
jdbcTemplate.execute("set role ogi2;");
List<Map<String, Object>> child2List = jdbcTemplate.queryForList("select * from ogi2.person;");
jdbcTemplate.execute("reset role;");

assertThat(groupList.size(), is(2));
assertThat(child1List.size(), is(2));
assertThat(child2List.size(), is(2));
assertThat(child1List.size(), is(1));
assertThat(child2List.size(), is(1));
}

@Test
Expand Down
31 changes: 31 additions & 0 deletions src/test/resources/organisation-group-teardown.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
drop schema if exists ogi1 cascade ;
drop schema if exists ogi2 cascade ;
drop schema if exists og cascade ;

delete from organisation where id = 13;
delete from organisation where id = 14;
delete from organisation_group where id = 11;
delete from organisation_group_organisation where id = 11;
delete from organisation_group_organisation where id = 12;
delete from address_level_type where organisation_id in (13, 14);
delete from address_level where organisation_id in (13, 14);
delete from users where organisation_id in (13, 14);
delete from subject_type where organisation_id in (13, 14);
delete from operational_subject_type where organisation_id in (13, 14);
delete from program where organisation_id in (13, 14);
delete from operational_program where organisation_id in (13, 14);
delete from encounter_type where organisation_id in (13, 14);
delete from operational_encounter_type where organisation_id in (13, 14);
delete from concept where organisation_id in (13, 14);
delete from concept_answer where organisation_id in (13, 14);
delete from form where organisation_id in (13, 14);
delete from form_element_group where organisation_id in (13, 14);
delete from form_element where organisation_id in (13, 14);
delete from form_mapping where organisation_id in (13, 14);
delete from decision_concept where form_id in (select id from form where organisation_id in (13, 14));
delete from gender where organisation_id in (13, 14);
delete from individual where organisation_id in (13, 14);
delete from program_enrolment where organisation_id in (13, 14);
delete from program_encounter where organisation_id in (13, 14);
delete from encounter where organisation_id in (13, 14);
delete from entity_approval_status where organisation_id in (13, 14);

0 comments on commit 88f1331

Please sign in to comment.