Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
githengi committed Jun 23, 2020
1 parent c212d8d commit 7231e28
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ private PathEvaluatorLibrary(LocationDao locationDao, ClientDao clientDao, TaskD
eventProvider = new EventProvider(eventDao);
}

public static void init(LocationDao locationDao, ClientDao clientDao, TaskDao taskDao, EventDao eventDao,
String userName) {
public static void init(LocationDao locationDao, ClientDao clientDao, TaskDao taskDao, EventDao eventDao) {
instance = new PathEvaluatorLibrary(locationDao, clientDao, taskDao, eventDao);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void testConvertToPatientResource() {
assertEquals(client.getBirthdate().toString("YYYY-MM-DD"), patient.getBirthDate().getValue().toString());
assertEquals(client.getDeathdate().toString("yyyy-MM-dd'T'HH:mm'Z'"),
patient.getDeceased().as(com.ibm.fhir.model.type.DateTime.class).getValue().toString());
PathEvaluatorLibrary.init(null, null, null,null,"testUser");
PathEvaluatorLibrary.init(null, null, null,null);
FHIRPathElementNode node = PathEvaluatorLibrary.getInstance().evaluateElementExpression(patient, "Patient.identifier.where(system='opensrp_id')");
Identifier identifierNode = node.element().as(Identifier.class);
assertEquals("20366639", identifierNode.getValue().getValue());
Expand Down
20 changes: 7 additions & 13 deletions src/test/java/org/smartregister/converters/EventConverterTest.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
package org.smartregister.converters;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.ibm.fhir.model.resource.QuestionnaireResponse;
import com.ibm.fhir.model.type.Integer;
import com.ibm.fhir.path.FHIRPathElementNode;
import com.ibm.fhir.path.FHIRPathNode;
import com.ibm.fhir.path.FHIRPathResourceNode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.lang.String;
import java.util.Collection;
import java.util.Map;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.joda.time.DateTime;
import org.junit.Test;
import org.smartregister.domain.Event;
import org.smartregister.pathevaluator.PathEvaluatorLibrary;
import org.smartregister.utils.TaskDateTimeTypeConverter;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.ibm.fhir.model.resource.QuestionnaireResponse;
import com.ibm.fhir.path.FHIRPathElementNode;

public class EventConverterTest {

Expand Down Expand Up @@ -107,7 +101,7 @@ public void testConvertEventToQuestionnaireResponseWithMultipleValuesOfObs() {
questionnaireResponse.getItem().get(3).getAnswer().get(0).getValue().as(com.ibm.fhir.model.type.String.class)
.getValue());

PathEvaluatorLibrary.init(null, null, null, null, "testUser");
PathEvaluatorLibrary.init(null, null, null, null);
FHIRPathElementNode node = PathEvaluatorLibrary.getInstance().evaluateElementExpression(questionnaireResponse, "QuestionnaireResponse.item.where(linkId='totPopulation')");
QuestionnaireResponse.Item totPopulation = node.element().as(QuestionnaireResponse.Item.class);
assertEquals(1,totPopulation.getAnswer().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class PathEvaluatorLibraryTest {

@Before
public void startUp() {
PathEvaluatorLibrary.init(null, null, null, null, null);
PathEvaluatorLibrary.init(null, null, null, null);
pathEvaluatorLibrary = PathEvaluatorLibrary.getInstance();
patient = Patient.builder().id("12345").birthDate(Date.of("1990-12-19"))
.identifier(Identifier.builder().id("1234").value(of("1212313")).build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class ActionHelperTest {

@Before
public void setUp() {
PathEvaluatorLibrary.init(locationDao, clientDao, taskDao, eventDao,"testUser");
PathEvaluatorLibrary.init(locationDao, clientDao, taskDao, eventDao);
PathEvaluatorLibrary instance = PathEvaluatorLibrary.getInstance();
Whitebox.setInternalState(instance, "locationProvider", locationProvider);
Whitebox.setInternalState(instance, "clientProvider", clientProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class ConditionHelperTest {

@BeforeClass
public static void bootstrap() {
PathEvaluatorLibrary.init(null,null,null, null,null);
PathEvaluatorLibrary.init(null,null,null, null);
}

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ public class PlanEvaluatorTest {

private String plan = UUID.randomUUID().toString();

private String username = UUID.randomUUID().toString();

@Before
public void setUp() {
planEvaluator = new PlanEvaluator();
planEvaluator = new PlanEvaluator(username);
Whitebox.setInternalState(planEvaluator, "actionHelper", actionHelper);
Whitebox.setInternalState(planEvaluator, "conditionHelper", conditionHelper);
Whitebox.setInternalState(planEvaluator, "taskHelper", taskHelper);
Expand Down Expand Up @@ -100,7 +102,7 @@ public List<Patient> answer(InvocationOnMock invocation) throws Throwable {

verify(conditionHelper).evaluateActionConditions(patients.get(0), action, plan);

verify(taskHelper).generateTask(patients.get(0), action, planDefinition.getIdentifier(), jurisdiction.getCode());
verify(taskHelper).generateTask(patients.get(0), action, planDefinition.getIdentifier(), jurisdiction.getCode(),username);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,39 @@

@RunWith(MockitoJUnitRunner.class)
public class TaskHelperTest {

private TaskHelper taskHelper;

@Mock
private LocationDao locationDao;

@Mock
private ClientDao clientDao;

@Mock
private TaskDao taskDao;

@Mock
private EventDao eventDao;

@Mock
private Action action;

private Patient patient;

@Before
public void setUp() {
PathEvaluatorLibrary.init(locationDao, clientDao, taskDao, eventDao, "testUser");
PathEvaluatorLibrary.init(locationDao, clientDao, taskDao, eventDao);
PathEvaluatorLibrary instance = PathEvaluatorLibrary.getInstance();
taskHelper = new TaskHelper();
patient = TestData.createPatient();
}

@Test(expected = Test.None.class)
@Test
public void testGenerateTask() {
String planIdentifier = UUID.randomUUID().toString();
String jurisdiction = "12123";
Mockito.doNothing().when(taskDao).saveTask(any(Task.class));
taskHelper.generateTask(patient,action, planIdentifier,jurisdiction);
taskHelper.generateTask(patient, action, planIdentifier, jurisdiction, "testUser");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class TriggerHelperTest {

@Before
public void setUp() {
PathEvaluatorLibrary.init(null, null, null, null,null);
PathEvaluatorLibrary.init(null, null, null, null);
triggerHelper = new TriggerHelper(actionHelper);
trigger = Trigger.builder().name(TriggerType.PLAN_ACTIVATION.value()).build();
}
Expand Down

0 comments on commit 7231e28

Please sign in to comment.