Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
ndegwamartin committed Feb 17, 2023
1 parent 05c5421 commit 5c02267
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ protected Long retrievePrimaryKey(UniqueId uniqueId) {
UniqueIdExample example;
List<org.opensrp.domain.postgres.UniqueId> pgEntities;

if (fromOpenMrs == Boolean.TRUE) {
if (Boolean.TRUE.equals(fromOpenMrs)) {
identifier = uniqueOpenMrsIdentifier.toString();
example = new UniqueIdExample();
example.createCriteria().andOpenmrsIdEqualTo(identifier);
Expand Down
8 changes: 0 additions & 8 deletions src/test/java/org/opensrp/service/PlanServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,6 @@ public void testPopulateTaskCountForLarvalDipping() {
null, false)).thenReturn(1l);
Map<String, String> properties = new HashMap<>();
properties.put(PlanConstants.TYPE, PlanConstants.LARVAL_DIPPING_SITE);
List<String> structureIds = new ArrayList<>();
structureIds.add("structure-id-1");
structureIds.add("structure-id-2");
structureIds.add("structure-id-3");
when(locationService.countStructuresByProperties(Collections.singletonList("location-id1"),
properties)).thenReturn(3l);

Expand All @@ -540,10 +536,6 @@ public void testPopulateTaskCountForMosquitoCollection() {
null, false)).thenReturn(1l);
Map<String, String> properties = new HashMap<>();
properties.put(PlanConstants.TYPE, PlanConstants.MOSQUITO_COLLECTION_POINT);
List<String> structureIds = new ArrayList<>();
structureIds.add("structure-id-1");
structureIds.add("structure-id-2");
structureIds.add("structure-id-3");
when(locationService.countStructuresByProperties(Collections.singletonList("location-id1"),
properties)).thenReturn(3l);

Expand Down
59 changes: 25 additions & 34 deletions src/test/java/org/opensrp/service/PractitionerRoleServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand All @@ -50,7 +43,30 @@ public class PractitionerRoleServiceTest {
@Mock
private PractitionerService practitionerService;


private static PractitionerRole initTestPractitionerRole(){
PractitionerRole practitionerRole = new PractitionerRole();
practitionerRole.setIdentifier("pr1-identifier");
practitionerRole.setActive(true);
practitionerRole.setOrganizationIdentifier("org-identifier");
practitionerRole.setPractitionerIdentifier("p1-identifier");
PractitionerRoleCode code = new PractitionerRoleCode();
code.setText("pr1Code");
practitionerRole.setCode(code);
return practitionerRole;
}

private static PractitionerRole initTestPractitionerRole2(){
PractitionerRole practitionerRole = new PractitionerRole();
practitionerRole.setIdentifier("pr2-identifier");
practitionerRole.setActive(true);
practitionerRole.setOrganizationIdentifier("org1");
practitionerRole.setPractitionerIdentifier("p2-identifier");
PractitionerRoleCode code = new PractitionerRoleCode();
code.setText("pr2Code");
practitionerRole.setCode(code);
return practitionerRole;
}

@Test
public void testGetAllPractitionerRoles() {
List<PractitionerRole> expectedPractitionerRoles = new ArrayList<>();
Expand Down Expand Up @@ -145,15 +161,14 @@ public void testDeleteByOrganizationAndPractitionerShouldCallRepostorySafeRemove

org.opensrp.domain.postgres.Practitioner pgPractitioner = new org.opensrp.domain.postgres.Practitioner();
pgPractitioner.setId(1l);

when(practitionerService.getPgPractitioner(anyString())).thenReturn(pgPractitioner);

PractitionerRole practitionerRole = initTestPractitionerRole();
practitionerRoleService.deletePractitionerRole(practitionerRole.getIdentifier(), practitionerRole.getOrganizationIdentifier());
verify(practitionerRoleRepository).safeRemove(anyLong(), anyLong());
}


@Test
public void testGetRolesForPractitionerShouldCallGetRolesForPractitionerMethod() {
List<PractitionerRole> expectedPractitionerRoles = new ArrayList<>();
Expand Down Expand Up @@ -255,28 +270,4 @@ public void testAssignPractitionerRoleWithException() {
PractitionerRole practitionerRole = initTestPractitionerRole();
practitionerRoleService.assignPractitionerRole(organizationId, practitionerIdentifier, code, practitionerRole);
}

private static PractitionerRole initTestPractitionerRole(){
PractitionerRole practitionerRole = new PractitionerRole();
practitionerRole.setIdentifier("pr1-identifier");
practitionerRole.setActive(true);
practitionerRole.setOrganizationIdentifier("org-identifier");
practitionerRole.setPractitionerIdentifier("p1-identifier");
PractitionerRoleCode code = new PractitionerRoleCode();
code.setText("pr1Code");
practitionerRole.setCode(code);
return practitionerRole;
}

private static PractitionerRole initTestPractitionerRole2(){
PractitionerRole practitionerRole = new PractitionerRole();
practitionerRole.setIdentifier("pr2-identifier");
practitionerRole.setActive(true);
practitionerRole.setOrganizationIdentifier("org1");
practitionerRole.setPractitionerIdentifier("p2-identifier");
PractitionerRoleCode code = new PractitionerRoleCode();
code.setText("pr2Code");
practitionerRole.setCode(code);
return practitionerRole;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;

import java.util.HashMap;
import java.util.List;
Expand All @@ -23,7 +20,6 @@
import org.opensrp.common.AllConstants;
import org.opensrp.domain.AppStateToken;
import org.opensrp.service.ExportEventDataMapper;
import org.opensrp.repository.ClientsRepository;
import org.opensrp.repository.EventsRepository;
import org.opensrp.repository.PlanRepository;
import org.opensrp.service.ClientService;
Expand All @@ -36,6 +32,7 @@
import org.opensrp.service.formSubmission.handler.IHandlerMapper;
import org.smartregister.domain.Client;
import org.smartregister.domain.Event;
import org.smartregister.utils.Assert;

public class EventListenerTest {

Expand All @@ -48,9 +45,6 @@ public class EventListenerTest {
@Mock
private EventsRepository allEvents;

@Mock
private ClientsRepository allClients;

@Mock
private ErrorTraceService errorTraceService;

Expand Down Expand Up @@ -85,7 +79,7 @@ public void setUp() {
}

@Test
public void shouldHandleNewEvent() throws Exception {
public void shouldHandleNewEvent() {
EventsHandler eventHandler = mock(EventsHandler.class);
Map<String, EventsHandler> handlerMap = new HashMap<>();
handlerMap.put("VaccinesScheduleHandler", eventHandler);
Expand All @@ -96,19 +90,20 @@ public void shouldHandleNewEvent() throws Exception {
new Event());

when(configService.getAppStateTokenByName(AllConstants.Config.EVENTS_PARSER_LAST_PROCESSED_EVENT))
.thenReturn(new AppStateToken("token", 1l, 0l));
when(allEvents.findByServerVersion(1l)).thenReturn(events);
.thenReturn(new AppStateToken("token", 1L, 0l));
when(allEvents.findByServerVersion(1L)).thenReturn(events);
when(clientService.findAllByIdentifier(AllConstants.Client.ZEIR_ID.toUpperCase(), "2")).thenReturn(clients);
when(allEvents.findByBaseEntityAndType("222", "Birth Registration")).thenReturn(events);

when(handlerMapper.handlerMap()).thenReturn(handlerMap);

EventsListener spyEventListener = spy(eventsListener);
when(spyEventListener.getCurrentMilliseconds()).thenReturn(0l);


Assert.notNull(allEvents.findByServerVersion(1L));
spyEventListener.processEvent();

InOrder inOrder = inOrder(eventService, eventsRouter, eventHandler);
InOrder inOrder = inOrder(eventService, eventsRouter);
clients.get(0).setServerVersion(System.currentTimeMillis());
events.get(0).setServerVersion(System.currentTimeMillis());
inOrder.verify(eventService).processOutOfArea(events.get(0));
Expand Down

0 comments on commit 5c02267

Please sign in to comment.