View Javadoc

1   /*
2    * Created on 15.07.2004
3    * 
4    * © 2004 Stoffwechsel Development GbR
5    *
6    */
7   package net.stff.ical.test;
8   
9   import java.util.Calendar;
10  import java.util.Date;
11  import java.util.Vector;
12  
13  import junit.framework.TestCase;
14  import net.stff.ical.beans.CalendarDay;
15  import net.stff.ical.beans.IEvent;
16  import net.stff.ical.beans.VEvent;
17  
18  /***
19   * @author buntekuh
20   *
21   */
22  public class TestCalendarDay extends TestCase {
23  
24  	public static void main(String[] args) {
25  		junit.textui.TestRunner.run(TestCalendarDay.class);
26  	}
27  
28  	/*
29  	 * @see TestCase#setUp()
30  	 */
31  	protected void setUp() throws Exception {
32  		super.setUp();
33  	}
34  
35  	/*
36  	 * @see TestCase#tearDown()
37  	 */
38  	protected void tearDown() throws Exception {
39  		super.tearDown();
40  	}
41  
42  	/***
43  	 * Constructor for TestCalendarDay.
44  	 * @param name
45  	 */
46  	public TestCalendarDay(String name) {
47  		super(name);
48  	}
49  
50  	/*
51  	public final void testSetSortedEvents() {
52  	    // yyyyMMdd'T'HHmmss
53  	    IEvent e1, e2, e3;
54  	    Vector v= new Vector();
55  	    CalendarDay cd= new CalendarDay();
56  
57  	    //init
58  	    e1= new IEvent();
59  	    e1.setDtstart(VEvent.parseDate("20040708T010000")); // from 1 in the morning
60  	    e1.setDtend(VEvent.parseDate("20040708T070000")); // till 7
61  	    v.add(e1);
62  	    e2= new IEvent();
63  	    e2.setDtstart(VEvent.parseDate("20040708T050000")); // from 5 in the morning
64  	    e2.setDtend(VEvent.parseDate("20040708T090000")); // till 9
65  	    v.add(e2);
66  	    e3= new IEvent();
67  	    e3.setDtstart(VEvent.parseDate("20040708T080000")); // from 8 in the morning
68  	    e3.setDtend(VEvent.parseDate("20040708T100000")); // till 10
69  	    v.add(e3);
70  	    // e1 and e3 follow each other, so they should be in the first list
71  	    // e3 collides, so it should be in the second
72  	    
73  	    //exec
74  	    cd.setSortedEvents(v);
75  	    List result= cd.getEvents();
76  	    
77  	    assertEquals(2, result.size());
78  	    List l1= (List)result.get(0);
79  	    assertEquals(2, l1.size());
80  	    l1= (List)result.get(1);
81  	    assertEquals(1, l1.size());
82  
83  	}
84  	*/
85  	public final void testScheduleEvents() {
86  	    // yyyyMMdd'T'HHmmss
87  	    IEvent e1, e2, e3;
88  	    Vector v= new Vector();
89  	    CalendarDay cd= new CalendarDay();
90  
91  	    //init
92  	    e1= new IEvent();
93  	    e1.setSummary("e1");
94  	    e1.setDtstart(VEvent.parseDate("20040708T010000")); // from 1 in the morning
95  	    e1.setDtend(VEvent.parseDate("20040708T070000")); // till 7
96  	    v.add(e1);
97  	    e2= new IEvent();
98  	    e2.setSummary("e2");
99  	    e2.setDtstart(VEvent.parseDate("20040708T050000")); // from 5 in the morning
100 	    e2.setDtend(VEvent.parseDate("20040708T090000")); // till 9
101 	    v.add(e2);
102 	    e3= new IEvent();
103 	    e3.setSummary("e3");
104 	    e3.setDtstart(VEvent.parseDate("20040708T080000")); // from 8 in the morning
105 	    e3.setDtend(VEvent.parseDate("20040708T100000")); // till 10
106 	    v.add(e3);
107 	    // e1 and e3 follow each other, so they should be in the first list
108 	    // e3 collides, so it should be in the second
109 	    
110 	    //exec
111 	    //cd.setSortedEvents(v);
112 	    Date s= VEvent.parseDate("20040708T000000");
113 	    Calendar cc= Calendar.getInstance();
114 	    cc.setTime(s);
115 	    cd.schedule(v, cc, 12, 60);
116 	    /*
117 	     * --------------
118 	     * | 0|----|----|
119 	     * | 1|#e1#|----|
120 	     * | 2|#e1#|----|
121 	     * | 3|#e1#|----|
122 	     * | 4|#e1#|----|
123 	     * | 5|#e1#|#e2#|
124 	     * | 6|#e1#|#e2#|
125 	     * | 7|----|#e2#|
126 	     * | 8|#e3#|#e2#|
127 	     * | 9|#e3#|----|
128 	     * |10|----|----|
129 	     * |11|----|----|
130 	     * --------------
131 	     */
132 	    
133 	    Object[][] tt= cd.getTimetable();
134 	    int[] dim= cd.getDimensions();
135 	    assertEquals(12, dim[0]);	//i.e.: we have 12 periods
136 	    assertEquals(2, dim[1]);	//i.e.: we show 2 columns
137 	    
138 	    assertNull(tt[0][0]);
139 	    assertNull(tt[0][1]);
140 	    IEvent ev= (IEvent)tt[1][0];
141 	    assertEquals("e1", ev.getSummary());
142 	    assertEquals(ev.getDuration(), 6);
143 	    assertNull(tt[1][1]);
144 	    
145 	    assertEquals("persist", tt[5][0]);
146 	    ev= (IEvent)tt[5][1];
147 	    assertEquals("e2", ev.getSummary());
148 	    assertEquals(ev.getDuration(), 4);
149 	    
150 	    assertNull(tt[7][0]);
151 	    
152 	    ev= (IEvent)tt[8][0];
153 	    assertEquals("e3", ev.getSummary());
154 	    
155 	    assertNull(tt[10][0]);
156 	    
157 	}
158 
159 }