use of org.motechproject.commons.date.model.Time in project motech by motech.
the class CronJobSimpleExpressionBuilderTest method testBuild.
@Test
public void testBuild() {
CronJobSimpleExpressionBuilder builder = new CronJobSimpleExpressionBuilder(new Time(10, 25));
assertEquals("0 25 10 * * ?", builder.build());
}
use of org.motechproject.commons.date.model.Time in project motech by motech.
the class TestEventListener method shouldScheduleInterveningDayOfWeekJob.
@Test
public void shouldScheduleInterveningDayOfWeekJob() throws SchedulerException {
try {
fakeNow(newDateTime(2020, 7, 15, 10, 0, 0));
Map<String, Object> params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
schedulerService.scheduleDayOfWeekJob(new DayOfWeekSchedulableJob(new MotechEvent("test_event", params), // friday
newDateTime(2020, 7, 10), newDateTime(2020, 7, 22), asList(DayOfWeek.Monday, DayOfWeek.Thursday), new Time(10, 10), true));
List<DateTime> fireTimes = getFireTimes("test_event-job_id");
assertEquals(asList(newDateTime(2020, 7, 16, 10, 10, 0), newDateTime(2020, 7, 20, 10, 10, 0)), fireTimes);
} finally {
stopFakingTime();
}
}
use of org.motechproject.commons.date.model.Time in project motech by motech.
the class WeeklyCronJobExpressionBuilderTest method shouldBuildCronExpressionForAParticularDayAndTime.
@Test
public void shouldBuildCronExpressionForAParticularDayAndTime() {
WeeklyCronJobExpressionBuilder weeklyCronJobExpressionBuilder = new WeeklyCronJobExpressionBuilder(DayOfWeek.Monday);
Assert.assertEquals("0 30 10 ? * 2", weeklyCronJobExpressionBuilder.withTime(new Time(10, 30)).build());
}
use of org.motechproject.commons.date.model.Time in project motech by motech.
the class CronExpressionUtilTest method shouldParseValidCronExpression.
@Test
public void shouldParseValidCronExpression() {
String expression = "0 25 13 ? * 1,2,3,4,7";
Time expectedTime = new Time(13, 25);
List<DayOfWeek> expectedDaysOfWeek = prepareExpectedDaysOfWeek();
CronExpressionUtil util = new CronExpressionUtil(expression);
assertThat(util.getTime(), equalTo(expectedTime));
assertThat(util.getDaysOfWeek(), equalTo(expectedDaysOfWeek));
}
use of org.motechproject.commons.date.model.Time in project motech by motech.
the class TypeHelperTest method shouldParseStrings.
@Test
public void shouldParseStrings() {
final DateTime dt = DateUtil.now();
final DateTime dt2 = new DateTime(2009, 6, 7, 12, 11, 0, 0, DateTimeZone.forOffsetHours(1));
final LocalDate ld = DateUtil.now().toLocalDate();
final LocalDate ld2 = new LocalDate(2000, 8, 22);
final LocalDateTime ldt = LocalDateTime.now();
final LocalDateTime ldt2 = LocalDateTime.of(2015, 9, 1, 10, 15);
final java.time.LocalDate jld = java.time.LocalDate.now();
final java.time.LocalDate jld2 = java.time.LocalDate.of(1991, 5, 1);
assertEquals(3, TypeHelper.parse(3, Integer.class));
assertEquals("test", TypeHelper.parse("test", String.class));
assertEquals(new Time(16, 4), TypeHelper.parse("16:04", Time.class));
assertEquals(dt, TypeHelper.parse(dt.toString(), DateTime.class));
assertEquals(dt.toDate(), TypeHelper.parse(dt.toString(), Date.class));
assertEquals(DateUtil.setTimeZoneUTC(dt2), DateUtil.setTimeZoneUTC((DateTime) TypeHelper.parse("2009-06-07 12:11 +01:00", DateTime.class)));
assertEquals(dt2.toDate(), TypeHelper.parse("2009-06-07 12:11 +01:00", Date.class));
assertEquals(asList("one", "2", "three"), TypeHelper.parse("one\n2\nthree", List.class));
assertEquals(true, TypeHelper.parse("true", Boolean.class));
assertEquals(ld, TypeHelper.parse(ld, LocalDate.class));
assertEquals(ld, TypeHelper.parse(ld.toString(), LocalDate.class));
assertEquals(ld2, TypeHelper.parse("2000-08-22", LocalDate.class));
// TODO: do not send such values from the UI
assertEquals(ld2, TypeHelper.parse("2000-08-22T23:00:00.000Z", LocalDate.class));
// java.time types cases
assertEquals(jld, TypeHelper.parse(jld, java.time.LocalDate.class));
assertEquals(jld, TypeHelper.parse(jld.toString(), java.time.LocalDate.class));
assertEquals(jld2, TypeHelper.parse("1991-05-01", java.time.LocalDate.class));
assertEquals(ldt, TypeHelper.parse(ldt, java.time.LocalDateTime.class));
assertEquals(ldt, TypeHelper.parse(ldt.toString(), java.time.LocalDateTime.class));
assertTrue(ldt2.equals(TypeHelper.parse("2015-09-01 10:15 ".concat(findServerOffset()), java.time.LocalDateTime.class)));
}
Aggregations