{
// ---------getAllGlobalJobListener
List<JobListener> jobListenerCol = service_.getAllGlobalJobListener();
assertEquals("expect 1 GlobalJobListener is found", 1, jobListenerCol.size());
/* -----2 joblistener------------- */
JobListener jcontext = service_.getGlobalJobListener("JobContextConfigListener");
assertTrue("exepect found 'JobContextConfigListenner'", jcontext != null
&& jcontext.getName().equals("JobContextConfigListener"));
hasObjectInCollection(jcontext, jobListenerCol, new JobListenerComparator());
// --------------remove JobContextConfigListenner of SchedulerSerice-------
boolean b = service_.removeGlobalJobListener(jcontext.getName());
jcontext = service_.getGlobalJobListener("JobContextConfigListener");
assertTrue("expect JobContextConfigListenner is removed", b && jcontext == null);
jobListenerCol = service_.getAllGlobalJobListener();
assertEquals("expect 1 job listenner is found", 0, jobListenerCol.size());
// -----Test global trigger listener
List<TriggerListener> triggerListenerCol = service_.getAllGlobalTriggerListener();
assertEquals("expect no global trigger listener is found", 0, triggerListenerCol.size());
/* ----------add TriggerListenner--- */
service_.addGlobalTriggerListener(new GlobalTriggerListener());
// ------getAllTriggerListener---
TriggerListener globalTriggerListener = service_.getGlobalTriggerListener("GlobalTriggerListener");
assertTrue("expect 'GlobalTriggerListener' is found", globalTriggerListener != null
&& globalTriggerListener.getName().equals("GlobalTriggerListener"));
triggerListenerCol = service_.getAllGlobalTriggerListener();
assertEquals("expect 1 trigger listenner is found", 1, triggerListenerCol.size());
hasObjectInCollection(globalTriggerListener, triggerListenerCol, new TriggerListenerComparator());
// ----------------remove GlobalTriggerListener
b = service_.removeGlobaTriggerListener(globalTriggerListener.getName());
assertTrue("expect GlobalTriggerListener is removed", b);
triggerListenerCol = service_.getAllGlobalTriggerListener();
assertEquals("expect no trigger listenner is found", 0, triggerListenerCol.size());
// --------------Test non global Job Listener
jobListenerCol = service_.getAllJobListener();
assertEquals("expect no non global job listener is found", 0, jobListenerCol.size());
// ----add 2 Non Global Job Listenner----
service_.addGlobalJobListener(new GlobalJobListener());
service_.addJobListener(new FirstJobListener());
service_.addJobListener(new SecondJobListener());
JobListener globalListener = service_.getGlobalJobListener("GlobalJobListener");
JobListener joblistener1st = service_.getJobListener("FirstJobListener");
JobListener joblistener2nd = service_.getJobListener("SecondJobListener");
assertTrue("expect 'GlobalJobListener' is found", globalListener != null
&& globalListener.getName().equals("GlobalJobListener"));
assertTrue("expect 'FirstJobListener' is found", joblistener1st != null
&& joblistener1st.getName().equals("FirstJobListener"));
assertTrue("expect 'SecondJobListenner' is found", joblistener2nd != null
&& joblistener2nd.getName().equals("SecondJobListener"));
jobListenerCol = service_.getAllJobListener();
assertEquals("expect 1 global job listener is found", 1, service_.getAllGlobalJobListener().size());
assertEquals("expect 2 non global job listener is found", 2, jobListenerCol.size());
hasObjectInCollection(joblistener1st, jobListenerCol, new JobListenerComparator());
hasObjectInCollection(joblistener2nd, jobListenerCol, new JobListenerComparator());
GlobalJobListener.countCalled_ = 0;
FirstJobListener.countCalled_ = 0;
SecondJobListener.countCalled_ = 0;
assertEquals(0, GlobalJobListener.countCalled_);
assertEquals(0, FirstJobListener.countCalled_);
assertEquals(0, SecondJobListener.countCalled_);
service_.addJob(new JobInfo("GlobalJobListener", null/* default group */, AJob.class), new Date());
service_.addJob(new JobInfo("FirstJobListener", null/* default group */, AJob.class), new Date());
service_.addJob(new JobInfo("SecondJobListener", null/* default group */, AJob.class), new Date());
Thread.sleep(100);
//Scheduler can be faster and execute more than 3 tasks
assertTrue(GlobalJobListener.countCalled_ >= 3);
assertEquals(1, FirstJobListener.countCalled_);
assertEquals(1, SecondJobListener.countCalled_);
// ---remove FirstJobListenner---
b = service_.removeJobListener(joblistener1st.getName());
assertTrue("expect FirstJobListenner is removed", b);
joblistener1st = service_.getJobListener("FirstJobListenner");
assertTrue("expect FirstJobListenner is not found", joblistener1st == null);
jobListenerCol = service_.getAllJobListener();
assertEquals("now,expect 1 non global job is found", 1, jobListenerCol.size());
// ---remove SecondJobListenner---
b = service_.removeJobListener(joblistener2nd.getName());
joblistener2nd = service_.getJobListener("SecondJobListener");
assertTrue("expect SecondJobListenner is removed", b && joblistener2nd == null);
jobListenerCol = service_.getAllJobListener();
assertEquals("now,expect no non global job is found", 0, jobListenerCol.size());