diff --git a/avni-server-api/src/test/java/org/avni/server/dao/GeneralRepository.java b/avni-server-api/src/test/java/org/avni/server/dao/GeneralRepository.java new file mode 100644 index 000000000..7d1ad53f6 --- /dev/null +++ b/avni-server-api/src/test/java/org/avni/server/dao/GeneralRepository.java @@ -0,0 +1,23 @@ +package org.avni.server.dao; + +import jakarta.persistence.EntityManager; +import jakarta.persistence.Query; +import org.hibernate.query.sql.internal.NativeQueryImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +@Repository +public class GeneralRepository { + private final EntityManager entityManager; + + @Autowired + public GeneralRepository(EntityManager entityManager) { + this.entityManager = entityManager; + } + + public long execute(String sql) { + Query query = entityManager.createNativeQuery(sql); + NativeQueryImpl nativeQuery = (NativeQueryImpl) query; + return nativeQuery.getResultCount(); + } +} diff --git a/avni-server-api/src/test/java/org/avni/server/web/TransactionDataSyncTest.java b/avni-server-api/src/test/java/org/avni/server/web/TransactionDataSyncTest.java index 003d71a7e..3f017c4a2 100644 --- a/avni-server-api/src/test/java/org/avni/server/web/TransactionDataSyncTest.java +++ b/avni-server-api/src/test/java/org/avni/server/web/TransactionDataSyncTest.java @@ -65,6 +65,8 @@ public class TransactionDataSyncTest extends AbstractControllerIntegrationTest { private TestDataSetupService testDataSetupService; @Autowired private UserSubjectAssignmentService userSubjectAssignmentService; + @Autowired + private GeneralRepository generalRepository; private TestDataSetupService.TestOrganisationData organisationData; private TestDataSetupService.TestCatchmentData catchmentData; @@ -74,6 +76,7 @@ public class TransactionDataSyncTest extends AbstractControllerIntegrationTest { private SubjectType subjectTypeWithNoAccess; private Program programWithNoAccess; private GroupRole groupRoleForGroupSubjectTypeWithCatchmentBasedSync; + private GroupRole groupRoleForGroupSubjectTypeWithDirectAssignment; private Concept conceptForAttributeBasedSync; private SubjectType subjectTypeWithSyncAttributeBasedSync; private SubjectType groupSubjectTypeWithSyncAttributeBasedSync; @@ -167,6 +170,13 @@ public void setup() { groupRoleRepository.save(new TestGroupRoleBuilder().withMandatoryFieldsForNewEntity().withGroupSubjectType(groupSubjectTypeForDirectAssignment).withMemberSubjectType(subjectTypeForDirectAssignment).build()); + groupRoleForGroupSubjectTypeWithDirectAssignment = groupRoleRepository.save( + new TestGroupRoleBuilder() + .withMandatoryFieldsForNewEntity() + .withGroupSubjectType(groupSubjectTypeForDirectAssignment) + .withMemberSubjectType(subjectTypeForDirectAssignment) + .build()); + testGroupService.giveViewSubjectPrivilegeTo(organisationData.getGroup(), subjectTypeWithCatchmentBasedSync, subjectTypeForDirectAssignment, subjectTypeWithSyncAttributeBasedSync, groupSubjectTypeWithSyncAttributeBasedSync, groupSubjectTypeForCatchmentBasedSync, groupSubjectTypeForDirectAssignment); testGroupService.giveViewProgramPrivilegeTo(organisationData.getGroup(), subjectTypeWithCatchmentBasedSync, programWithCatchmentBasedSync); testGroupService.giveViewProgramPrivilegeTo(organisationData.getGroup(), subjectTypeForDirectAssignment, programForDirectAssignment); @@ -175,7 +185,6 @@ public void setup() { @Test @Transactional - @Ignore public void sync() throws Exception { // Catchment tx entities Individual inTheCatchment = testSubjectService.save(new SubjectBuilder().withMandatoryFieldsForNewEntity().withSubjectType(subjectTypeWithCatchmentBasedSync).withLocation(catchmentData.getAddressLevel1()).build()); @@ -282,7 +291,7 @@ public void sync() throws Exception { assertTrue(hasEntity(enrolmentAssignedNow, enrolments)); // Group Subject Individual assignedGroupSubject = testSubjectService.save(new SubjectBuilder().withMandatoryFieldsForNewEntity().withSubjectType(groupSubjectTypeForDirectAssignment).withLocation(catchmentData.getAddressLevel1()).build()); - GroupSubject groupSubjectInDirectAssignment = testGroupSubjectService.save(new TestGroupSubjectBuilder().withGroupRole(groupRoleForGroupSubjectTypeWithCatchmentBasedSync).withMember(assigned).withGroup(assignedGroupSubject).build()); + GroupSubject groupSubjectInDirectAssignment = testGroupSubjectService.save(new TestGroupSubjectBuilder().withGroupRole(groupRoleForGroupSubjectTypeWithDirectAssignment).withMember(assigned).withGroup(assignedGroupSubject).build()); userSubjectAssignmentService.assignSubjects(organisationData.getUser(), Collections.singletonList(assignedGroupSubject), false); groupSubjects = getGroupSubjects(groupSubjectTypeForDirectAssignment);