Skip to content

Commit

Permalink
#813 - removed unnecessary transactionals. removed powermock.
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Nov 8, 2024
1 parent b882689 commit 93456ed
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ public Set<Checklist> findChecklistsByIndividual(Individual individual) {
return checklistRepository.findByProgramEnrolmentIndividual(individual);
}

@Transactional(Transactional.TxType.REQUIRED)
public ChecklistItem findChecklistItem(String checklistUUID, String checklistItemDetailUUID) {
return checklistItemRepository.findByChecklistUuidAndChecklistItemDetailUuid(checklistUUID, checklistItemDetailUUID);
}

@Transactional(Transactional.TxType.REQUIRED)
public void saveItem(ChecklistItem checklistItem) {
checklistItemRepository.saveEntity(checklistItem);
}

@Override
public boolean isScopeEntityChanged(DateTime lastModifiedDateTime, String checklistDetailUuid) {
ChecklistDetail checklistDetail = checklistDetailRepository.findByUuid(checklistDetailUuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ private void setSubjectTypeIfRequired(FormMapping formMapping, String requestSub
formMapping.setSubjectType(subjectType);
}

@Transactional(readOnly = true)
public LinkedHashMap<String, FormElement> getAllFormElementsAndDecisionMap(String subjectTypeUUID, String programUUID, String encounterTypeUUID, FormType formType) {
return getEntityConceptMap(formMappingRepository.getRequiredFormMapping(subjectTypeUUID, programUUID, encounterTypeUUID, formType), false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.stream.Collectors;

@Service
@Transactional
public class SubjectSyncResponseBuilderService {
private IndividualRepository individualRepository;
private ChecklistService checklistService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
import org.avni.server.domain.UserContext;
import org.avni.server.framework.security.UserContextHolder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import java.util.Optional;

Expand All @@ -22,11 +20,9 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@RunWith(PowerMockRunner.class)
@PrepareForTest({UserContextHolder.class})
@Transactional
public class OrganisationConfigServiceTest {

@Test
public void shouldRetrieveOptionalObjectFromOrganisationSettings() {
OrganisationConfigRepository organisationRepository = mock(OrganisationConfigRepository.class);
Expand All @@ -49,11 +45,12 @@ public void shouldRetrieveOptionalObjectFromOrganisationSettings() {
@Test
public void shouldCheckIfMessagingFeatureEnabled() {
OrganisationConfigRepository organisationConfigRepository = mock(OrganisationConfigRepository.class);
PowerMockito.mockStatic(UserContextHolder.class);
UserContext userContext = mock(UserContext.class);
long organisationId = 25l;
when(userContext.getOrganisationId()).thenReturn(organisationId);
Mockito.when(UserContextHolder.getUserContext()).thenReturn(userContext);
UserContext context = new UserContext();
Organisation organisation = new Organisation();
organisation.setId(organisationId);
context.setOrganisation(organisation);
UserContextHolder.create(context);

OrganisationConfig organisationConfigWithoutMessagingEnabled = new OrganisationConfig();
organisationConfigWithoutMessagingEnabled.setSettings(new JsonObject());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import jakarta.transaction.Transactional;
import org.avni.server.common.AbstractControllerIntegrationTest;
import org.avni.server.dao.GroupRoleRepository;
import org.avni.server.dao.UserRepository;
import org.avni.server.dao.UserSubjectAssignmentRepository;
import org.avni.server.dao.*;
import org.avni.server.dao.sync.SyncEntityName;
import org.avni.server.domain.*;
import org.avni.server.domain.factory.TestUserSyncSettingsBuilder;
Expand Down Expand Up @@ -284,7 +282,8 @@ public void sync() throws Exception {
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());
userSubjectAssignmentService.assignSubjects(organisationData.getUser(), Collections.singletonList(assignedGroupSubject), false);
groupSubjects = getGroupSubjects(groupSubjectTypeForCatchmentBasedSync);

groupSubjects = getGroupSubjects(groupSubjectTypeForDirectAssignment);
assertTrue(hasEntity(groupSubjectInDirectAssignment, groupSubjects));
}

Expand Down
2 changes: 1 addition & 1 deletion avni-server-api/src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spring.flyway.baseline-on-migrate=false
server.tomcat.accesslog.max-days=90

# JPA, Hibernate and Spring Data
spring.jpa.show-sql=false
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=none
#spring.jpa.properties.jadira.usertype.databaseZone=jvm
#spring.jpa.properties.jadira.usertype.javaZone=jvm
Expand Down

0 comments on commit 93456ed

Please sign in to comment.