Permalink
Browse files

Deepan/Sanjana/Alex|#1425|Included functional test to assert schedule…

… creation for ANC reg and history
  • Loading branch information...
1 parent 120253e commit ce511778e89b06bb8f4f5bf6f5533d55ebc4fa1b @deepan deepan committed Apr 9, 2012
@@ -112,7 +112,7 @@ protected void assertAlerts(List<TestJobDetail> testJobDetails, List<Date> alert
SimpleTrigger alert = testJobDetail.trigger();
Date nextFireTime = alert.getNextFireTime();
actualAlertTimes.add(nextFireTime);
- for (int i = 1; i <= alert.getRepeatCount(); i++) {
+ for (int i = 1; i <= alert.getRepeatCount() - alert.getTimesTriggered(); i++) {
Calendar calendar = Calendar.getInstance();
calendar.setTime((Date) nextFireTime.clone());
calendar.add(Calendar.DAY_OF_MONTH, toDays(i * alert.getRepeatInterval()));
@@ -11,9 +11,9 @@
import java.util.List;
import java.util.Map;
-import static org.joda.time.format.DateTimeFormat.forPattern;
import static org.motechproject.ghana.national.functional.util.MobileFormUtils.updateFieldByNameAndValue;
import static org.motechproject.ghana.national.functional.util.MobileFormUtils.updateFieldName;
+import static org.motechproject.ghana.national.tools.Utility.nullSafeToString;
public class TestANCEnrollment implements CareEnrollment {
private String staffId;
@@ -40,50 +40,59 @@
private String country;
public static TestANCEnrollment create() {
- final TestANCEnrollment enrollment = new TestANCEnrollment();
+ return TestANCEnrollment.createWithoutHistory().addHistoryDetails();
+ }
+ public static TestANCEnrollment createWithoutHistory() {
+ final TestANCEnrollment enrollment = new TestANCEnrollment();
enrollment.registrationDate = DateUtil.today();
enrollment.registrationToday = RegistrationToday.TODAY;
enrollment.serialNumber = "serialNumber";
enrollment.estimatedDateOfDelivery = new LocalDate(2012, 2, 3);
- enrollment.addHistory = true;
- enrollment.addCareHistory = Arrays.asList(ANCCareHistory.values());
enrollment.height = "124.0";
enrollment.gravida = "3";
enrollment.parity = "4";
enrollment.deliveryDateConfirmed = true;
- enrollment.lastIPT = "1";
- enrollment.lastTT = "1";
- enrollment.lastIPTDate = new LocalDate(2011, 2, 3);
- enrollment.lastTTDate = new LocalDate(2011, 2, 4);
enrollment.country = "Ghana";
enrollment.region = "Central Region";
enrollment.district = "Awutu Senya";
enrollment.subDistrict = "Kasoa";
enrollment.facility = "Papaase CHPS";
enrollment.facilityId = "13212";
+ enrollment.addHistory = false;
return enrollment;
}
+ public TestANCEnrollment addHistoryDetails() {
+ this.addHistory = true;
+ this.addCareHistory = Arrays.asList(ANCCareHistory.values());
+ this.lastIPT = "1";
+ this.lastTT = "1";
+ this.lastIPTDate = new LocalDate(2011, 2, 3);
+ this.lastTTDate = new LocalDate(2011, 2, 4);
+ return this;
+ }
+
public Map<String, String> forMobile() {
return new HashMap<String, String>() {{
put("staffId", staffId);
put("facilityId", facilityId);
put("motechId", motechPatientId);
- put("registrationDate", registrationDate.toString(forPattern("yyyy-MM-dd")));
+ put("registrationDate", safe(registrationDate));
put("regDateToday", registrationToday.name());
put("ancRegNumber", serialNumber);
- put("estDeliveryDate", estimatedDateOfDelivery.toString(DateTimeFormat.forPattern("yyyy-MM-dd")));
+ put("estDeliveryDate", safe(estimatedDateOfDelivery));
put("height", height);
put("gravida", gravida);
put("parity", parity);
put("addHistory", booleanCodeForAddHistory(addHistory));
put("deliveryDateConfirmed", booleanCodeForDateConfirmed(deliveryDateConfirmed));
put("addCareHistory", "IPT,TT");
+// put("addCareHistory", join(collect(addCareHistory, on(ANCCareHistory.class).name()), ","));
put("lastIPT", lastIPT);
put("lastTT", lastTT);
- put("lastIPTDate", lastIPTDate.toString(DateTimeFormat.forPattern("yyyy-MM-dd")));
- put("lastTTDate", lastTTDate.toString(DateTimeFormat.forPattern("yyyy-MM-dd")));
+ put("lastIPTDate", safe(lastIPTDate));
+ put("lastTTDate", safe(lastTTDate));
put("serialNumber", serialNumber);
}};
}
@@ -122,6 +131,11 @@ public String booleanCodeForDateConfirmed(boolean value) {
return value ? "Y" : "N";
}
+ private String safe(LocalDate date) {
+ return nullSafeToString(date, "yyyy-MM-dd");
+
+ }
+
public Boolean addHistory() {
return addHistory;
}
@@ -1,12 +1,13 @@
package org.motechproject.ghana.national.functional.data;
import org.joda.time.LocalDate;
-import org.joda.time.format.DateTimeFormat;
import org.motechproject.util.DateUtil;
import java.util.HashMap;
import java.util.Map;
+import static org.motechproject.ghana.national.tools.Utility.nullSafeToString;
+
public class TestCareHistory {
private String staffId;
private String facilityId;
@@ -28,6 +29,30 @@
private LocalDate lastIPTIDate;
private LocalDate lastVitaminADate;
+ public static TestCareHistory withoutHistory(String motechId) {
+ final TestCareHistory careHistory = new TestCareHistory();
+ careHistory.facilityId = "13212";
+ careHistory.motechId = motechId;
+ careHistory.date = DateUtil.newDate(2000, 12, 12);
+ careHistory.addHistory = "";
+ return careHistory;
+ }
+
+ public TestCareHistory withIPT(String dosage, LocalDate lastIPTdate) {
+ lastIPT = dosage;
+ this.lastIPTDate = lastIPTdate;
+ addHistory = addHistory + "IPT";
+ return this;
+ }
+
+ public TestCareHistory withTT(String dosage, LocalDate lastIPTdate) {
+ lastTT = dosage;
+ this.lastTTDate = lastIPTdate;
+ addHistory = addHistory + "TT";
+ return this;
+ }
+
+
public static TestCareHistory create() {
TestCareHistory careHistory = new TestCareHistory();
careHistory.facilityId = "13212";
@@ -54,26 +79,30 @@ public static TestCareHistory create() {
return new HashMap<String, String>() {{
put("staffId", staffId);
put("facilityId", facilityId);
- put("date", date.toString(DateTimeFormat.forPattern("yyyy-MM-dd")));
+ put("date", safe(TestCareHistory.this.date));
put("motechId", motechId);
put("addHistory", addHistory);
put("lastIPT", lastIPT);
- put("lastIPTDate", lastIPTDate.toString(DateTimeFormat.forPattern("yyyy-MM-dd")));
+ put("lastIPTDate", safe(lastIPTDate));
put("lastTT", lastTT);
- put("lastTTDate", lastTTDate.toString(DateTimeFormat.forPattern("yyyy-MM-dd")));
- put("bcgDate", bcgDate.toString(DateTimeFormat.forPattern("yyyy-MM-dd")));
+ put("lastTTDate", safe(lastTTDate));
+ put("bcgDate", safe(bcgDate));
put("lastOPV", lastOPV);
- put("lastOPVDate", lastOPVDate.toString(DateTimeFormat.forPattern("yyyy-MM-dd")));
+ put("lastOPVDate", safe(lastOPVDate));
put("lastPenta", lastPenta);
- put("lastPentaDate", lastPentaDate.toString(DateTimeFormat.forPattern("yyyy-MM-dd")));
- put("measlesDate", measlesDate.toString(DateTimeFormat.forPattern("yyyy-MM-dd")));
- put("yellowFeverDate", yellowFeverDate.toString(DateTimeFormat.forPattern("yyyy-MM-dd")));
+ put("lastPentaDate", safe(lastPentaDate));
+ put("measlesDate", safe(measlesDate));
+ put("yellowFeverDate", safe(yellowFeverDate));
put("lastIPTI", lastIPTI);
- put("lastIPTIDate", lastIPTIDate.toString(DateTimeFormat.forPattern("yyyy-MM-dd")));
- put("lastVitaminADate", lastVitaminADate.toString(DateTimeFormat.forPattern("yyyy-MM-dd")));
+ put("lastIPTIDate", safe(lastIPTIDate));
+ put("lastVitaminADate", safe(lastVitaminADate));
}};
}
+ private String safe(LocalDate date) {
+ return nullSafeToString(date, "yyyy-MM-dd");
+ }
+
public TestCareHistory staffId(String staffId) {
this.staffId = staffId;
return this;
@@ -0,0 +1,58 @@
+package org.motechproject.ghana.national.functional.domain;
+
+import org.joda.time.LocalDate;
+import org.motechproject.scheduletracking.api.domain.WindowName;
+
+import java.util.Date;
+
+import static org.motechproject.util.DateUtil.newDate;
+
+public class Alert {
+ private WindowName window;
+ private Date alertDate;
+
+ public Alert(WindowName window, Date alertDate) {
+ this.window = window;
+ this.alertDate = alertDate;
+ }
+
+ public WindowName getWindow() {
+ return window;
+ }
+
+ public Date getAlertDate() {
+ return alertDate;
+ }
+
+ public LocalDate getAlertAsLocalDate() {
+ return newDate(alertDate);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Alert)) return false;
+
+ Alert alert = (Alert) o;
+
+ if (alertDate != null ? !alertDate.equals(alert.alertDate) : alert.alertDate != null) return false;
+ if (window != alert.window) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = window != null ? window.hashCode() : 0;
+ result = 31 * result + (alertDate != null ? alertDate.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "Alert{" +
+ "window=" + window +
+ ", alertDate=" + alertDate +
+ '}';
+ }
+}
@@ -0,0 +1,22 @@
+package org.motechproject.ghana.national.functional.domain;
+
+import org.quartz.SimpleTrigger;
+
+public class JobDetail {
+
+ SimpleTrigger trigger;
+ org.quartz.JobDetail jobDetail;
+
+ public JobDetail(SimpleTrigger trigger, org.quartz.JobDetail jobDetail) {
+ this.trigger = trigger;
+ this.jobDetail = jobDetail;
+ }
+
+ public org.quartz.JobDetail getJobDetail() {
+ return jobDetail;
+ }
+
+ public SimpleTrigger trigger() {
+ return trigger;
+ }
+}
Oops, something went wrong. Retry.

0 comments on commit ce51177

Please sign in to comment.