Commits

timemachine  committed 0f18a74

Added ScriptingDateListProviderTest.

  • Participants
  • Parent commits ab9f6bb
  • Branches 1.1.x

Comments (0)

Files changed (2)

File timemachine-scheduler/src/test/java/unit/timemachine/scheduler/schedule/ScriptingDateListProviderTest.java

+/*
+ * Copyright 2012 Zemian Deng
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package unit.timemachine.scheduler.schedule;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+import java.util.Date;
+import java.util.List;
+
+import org.junit.Test;
+
+import timemachine.scheduler.Schedules;
+import timemachine.scheduler.schedule.DateListSchedule;
+import timemachine.scheduler.schedule.ScriptingDateListProvider;
+
+public class ScriptingDateListProviderTest {	
+	@Test
+	public void testClone() throws Exception {
+		DateListSchedule s = new DateListSchedule();
+		s.setDateListProviderClassName(ScriptingDateListProvider.class);
+		s.setDateListProviderData("scriptEngineName=Groovy,scriptFile=" +
+				"classpath:///unit/timemachine/scheduler/schedule/ScriptingDateListProviderTest.groovy");
+		s.initOnce();
+		
+		assertThat(s.getNextRun() != null, is(true));
+		
+		Date start = Schedules.time("00:00:00");
+		List<Date> dates = s.getNextRuns(null, 10);
+		assertThat(dates.size(), is(10));
+		assertThat(dates.get(0), is(Schedules.firstOfMonth(Schedules.addMonths(start, 1))));
+		assertThat(dates.get(1), is(Schedules.firstOfMonth(Schedules.addMonths(start, 2))));
+		assertThat(dates.get(2), is(Schedules.firstOfMonth(Schedules.addMonths(start, 3))));
+		assertThat(dates.get(3), is(Schedules.firstOfMonth(Schedules.addMonths(start, 4))));
+		assertThat(dates.get(4), is(Schedules.firstOfMonth(Schedules.addMonths(start, 5))));
+		assertThat(dates.get(5), is(Schedules.firstOfMonth(Schedules.addMonths(start, 6))));
+		assertThat(dates.get(6), is(Schedules.firstOfMonth(Schedules.addMonths(start, 7))));
+		assertThat(dates.get(7), is(Schedules.firstOfMonth(Schedules.addMonths(start, 8))));
+		assertThat(dates.get(8), is(Schedules.firstOfMonth(Schedules.addMonths(start, 9))));
+		assertThat(dates.get(9), is(Schedules.firstOfMonth(Schedules.addMonths(start, 10))));
+	}
+}

File timemachine-scheduler/src/test/resources/unit/timemachine/scheduler/schedule/ScriptingDateListProviderTest.groovy

+import timemachine.scheduler.*
+result = new ArrayList()
+prevDate = dateListSchedule.getPrevRun()
+if (prevDate == null)
+  result.add(Schedules.firstOfMonth(Schedules.addMonths(Schedules.time("00:00:00"), 1)))
+else
+  result.add(Schedules.firstOfMonth(Schedules.addMonths(prevDate, 1)))
+return result