Commits

Zemian Deng committed 4f4bce7

Added test cases for event history CRUD operations.

Comments (0)

Files changed (1)

timemachine-scheduler/src/test/java/integration/timemachine/scheduler/service/DataStoreTestBase.java

 import org.junit.Before;
 import org.junit.Test;
 
+import timemachine.scheduler.EventHistory;
 import timemachine.scheduler.JobDef;
 import timemachine.scheduler.Schedule;
 import timemachine.scheduler.SchedulerData;
 import timemachine.scheduler.schedule.DateListSchedule;
 import timemachine.scheduler.schedule.RepeatSchedule;
 import timemachine.scheduler.service.DataStore;
+import timemachine.scheduler.service.EventHistoryService;
 
 /**
  * A abstract base class that test out all common {@link DataStore} interface. Each implementation should
 		jobDef1b = store.getJobDef(getSchedulerId(), jobDef.getId());
 		assertThat(jobDef1b.getSchedules().size(), is(1));
 	}
+	
+	@Test
+	public void testEventHistory() throws Exception {
+		EventHistoryService helper = new EventHistoryService();
+		EventHistory eh1 = helper.createEventHistory("TEST-TYPE", "MY-EVENT");
+		EventHistory eh2 = helper.createEventHistory("TEST-TYPE", "MY-EVENT2", "1");
+		EventHistory eh3 = helper.createEventHistory("TEST-TYPE", "MY-EVENT2", "a", "b", "c", "d", "e");
+		eh1.setSchedulerNodeId(1L);
+		eh2.setSchedulerNodeId(1L);
+		eh3.setSchedulerNodeId(1L);
+		
+		eh1.setCreateTime(Schedules.date("1/1/2012"));
+		eh2.setCreateTime(Schedules.date("1/2/2012"));
+		eh3.setCreateTime(Schedules.date("1/3/2012"));
+		
+		store.createEventHistory(eh1);
+		store.createEventHistory(eh2);
+		store.createEventHistory(eh3);
+		
+		assertThat(eh1.getId(), notNullValue());
+		assertThat(eh2.getId(), notNullValue());
+		assertThat(eh3.getId(), notNullValue());
+
+		EventHistory eh1a = store.getEventHistory(1L, eh1.getId());
+		EventHistory eh2a = store.getEventHistory(1L, eh2.getId());
+		EventHistory eh3a = store.getEventHistory(1L, eh3.getId());
+		
+		assertThat(eh1a.getType(), is("TEST-TYPE"));
+		assertThat(eh2a.getType(), is("TEST-TYPE"));
+		assertThat(eh3a.getType(), is("TEST-TYPE"));
+		assertThat(eh1a.getName(), is("MY-EVENT"));
+		assertThat(eh2a.getName(), is("MY-EVENT2"));
+		assertThat(eh3a.getName(), is("MY-EVENT2"));
+		assertThat(eh1a.getInfo1(), nullValue());
+		assertThat(eh2a.getInfo1(), is("1"));
+		assertThat(eh3a.getInfo1(), is("a"));
+		assertThat(eh1a.getInfo2(), nullValue());
+		assertThat(eh2a.getInfo2(), nullValue());
+		assertThat(eh3a.getInfo2(), is("b"));
+		assertThat(eh1a.getInfo3(), nullValue());
+		assertThat(eh2a.getInfo3(), nullValue());
+		assertThat(eh3a.getInfo3(), is("c"));
+		assertThat(eh1a.getInfo4(), nullValue());
+		assertThat(eh2a.getInfo4(), nullValue());
+		assertThat(eh3a.getInfo4(), is("d"));
+		assertThat(eh1a.getInfo5(), nullValue());
+		assertThat(eh2a.getInfo5(), nullValue());
+		assertThat(eh3a.getInfo5(), is("e"));
+		
+		List<EventHistory> ls = store.findEventHistories(1L);
+		assertThat(ls.size(), is(3));
+		assertThat(ls.get(0).getId(), is(eh3.getId()));
+		assertThat(ls.get(1).getId(), is(eh2.getId()));
+		assertThat(ls.get(2).getId(), is(eh1.getId()));
+		
+		ls = store.findEventHistories(1L, Schedules.date("12/1/2011"), new Date());
+		assertThat(ls.size(), is(3));
+		assertThat(ls.get(0).getId(), is(eh3.getId()));
+		assertThat(ls.get(1).getId(), is(eh2.getId()));
+		assertThat(ls.get(2).getId(), is(eh1.getId()));
+		
+		store.deleteEventHistories(1L, Schedules.date("1/2/2012"));
+		ls = store.findEventHistories(1L);
+		assertThat(ls.size(), is(2));
+		
+		store.deleteEventHistories(1L, Schedules.date("1/4/2012"));
+		ls = store.findEventHistories(1L);
+		assertThat(ls.size(), is(0));
+	}
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.