01: package org.columba.calendar.store;
02:
03: import java.io.File;
04:
05: import junit.framework.TestCase;
06:
07: import org.columba.calendar.base.UUIDGenerator;
08: import org.columba.calendar.model.Event;
09: import org.columba.calendar.model.EventInfo;
10: import org.columba.calendar.model.api.IComponentInfo;
11: import org.columba.calendar.store.api.StoreException;
12:
13: public class LocalCalendarStoreTest extends TestCase {
14:
15: private File file;
16:
17: private LocalCalendarStore storage;
18:
19: protected void setUp() throws Exception {
20: file = new File("test_calendar");
21:
22: storage = new LocalCalendarStore(file);
23: }
24:
25: public void testAddGet() throws Exception {
26: String uuid = new UUIDGenerator().newUUID();
27:
28: Event model = new Event(uuid);
29: model.setSummary("summary");
30: model.setDescription("description");
31:
32: EventInfo eventInfo = new EventInfo(uuid, "calendar1", model);
33: storage.add(eventInfo);
34:
35: boolean exists = storage.exists(uuid);
36: assertTrue(exists);
37:
38: IComponentInfo result = storage.get(uuid);
39: assertNotNull(result);
40:
41: }
42:
43: public void testRemove() throws Exception {
44: String uuid = new UUIDGenerator().newUUID();
45:
46: Event model = new Event(uuid);
47: model.setSummary("summary");
48: model.setDescription("description");
49:
50: EventInfo eventInfo = new EventInfo(uuid, "calendar1", model);
51:
52: storage.add(eventInfo);
53:
54: storage.remove(uuid);
55:
56: try {
57: IComponentInfo result = storage.get(uuid);
58: } catch (StoreException e) {
59: // that is the expected case
60: return;
61: } catch (Exception e) {
62: fail("Expected a StoreException, not " + e.getMessage());
63: }
64:
65: fail("Expected a StoreException");
66:
67: }
68:
69: protected void tearDown() throws Exception {
70: // // delete all data in directory
71: // File[] list = file.listFiles();
72: //
73: // for (int i = 0; i < list.length; i++) {
74: // list[i].delete();
75: // }
76: //
77: // // delete folder
78: // file.delete();
79: }
80:
81: }
|