package org.pinae.rafiki.trigger.impl;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.junit.Test;
import org.pinae.rafiki.trigger.TriggerException;

public class MixedTriggerTest {

	@Test
	public void testMatch() throws ParseException, TriggerException {
		assertTrue(match("2014-05-10 13:00:10"));
		assertTrue(match("2014-05-15 12:00:00"));
		assertFalse(match("2014-05-15 10:00:00"));
		assertFalse(match("2014-05-13 10:00:00"));
		assertFalse(match("2014-05-10 10:00:15"));
	}
	
	private boolean match(String date) throws ParseException, TriggerException {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
		Date now = df.parse(date);
		
		CronTrigger cronTrigger = new CronTrigger("0-30/10 * * 5-12 MAY SAT 2014");
		cronTrigger.setStartTime(new Date(0));
		CalendarTrigger calendarTrigger = new CalendarTrigger();
		calendarTrigger.setStartTime(new Date(0));
		calendarTrigger.setTime("2014-05-15 12:00:00 - 2015-05-15 13:00:00");
		
		MixedTrigger trigger = new MixedTrigger();
		trigger.setOperate(MixedTrigger.OR);
		trigger.addTrigger(cronTrigger);
		trigger.addTrigger(calendarTrigger);
		
		return trigger.match(now);
	}
}

@@ -416,25 +416,25 @@
 atch(%222014-0
-5
+6
 -10 13:00:10
@@ -434,16 +434,33 @@
 3:00:10%22
+, MixedTrigger.OR
 ));%0A%09%09as
@@ -499,53 +499,210 @@
 :00%22
-));%0A%09%09assertFalse(match(%222014-05-15 10:00:00%22
+, MixedTrigger.OR));%0A%09%09assertTrue(match(%222014-05-15 12:00:40%22, MixedTrigger.OR));%0A%09%09assertFalse(match(%222014-05-16 10:00:00%22, MixedTrigger.OR));%0A%09%09assertFalse(match(%222014-05-04 10:00:00%22, MixedTrigger.OR
 ));%0A
@@ -735,64 +735,227 @@
 05-1
-3
+0
  10:00:
-00%22));%0A%09%09assertFalse(match(%222014-05-10 10:00:15%22
+15%22, MixedTrigger.OR));%0A%09%09%0A%09%09assertTrue(match(%222014-05-15 12:00:00%22, MixedTrigger.AND));%0A%09%09assertFalse(match(%222014-05-15 12:00:40%22, MixedTrigger.AND));%0A%09%09assertFalse(match(%222014-06-10 13:00:10%22, MixedTrigger.AND
 ));%0A
@@ -993,16 +993,29 @@
 ing date
+, int operate
 ) throws
@@ -1217,17 +1217,15 @@
  5-1
-2 MAY SAT
+5/5 * *
  201
@@ -1426,17 +1426,17 @@
 00 - 201
-5
+4
 -05-15 1
@@ -1515,31 +1515,23 @@
 Operate(
-MixedTrigger.OR
+operate
 );%0A%09%09tri

Update MixedTrigger Test Case