1 package org.columba.calendar.store; 19 20 import java.io.File ; 21 import java.util.Iterator ; 22 23 import junit.framework.TestCase; 24 25 import org.columba.calendar.base.UUIDGenerator; 26 import org.columba.calendar.model.api.IComponent; 27 import org.columba.calendar.parser.XCSDocumentParser; 28 import org.columba.calendar.store.api.StoreException; 29 import org.jdom.Document; 30 31 public class LocalXMLFileStoreTest extends TestCase { 32 33 private File file; 34 35 private LocalXMLFileStore storage; 36 37 protected void setUp() throws Exception { 38 file = new File ("test_calendar"); 39 40 storage = new LocalXMLFileStore(file); 41 } 42 43 public void testAddGet() throws Exception { 44 45 XCSDocumentParser model = new XCSDocumentParser(IComponent.TYPE.EVENT); 46 String uuid = model.getId(); 47 storage.save(uuid, model.getDocument()); 48 49 boolean exists = storage.exists(uuid); 50 assertTrue(exists); 51 52 Document result = storage.load(uuid); 53 assertNotNull(result); 54 55 } 56 57 public void testIterator() throws Exception { 58 String uuid1 = new UUIDGenerator().newUUID(); 59 XCSDocumentParser model1 = new XCSDocumentParser(IComponent.TYPE.EVENT); 60 storage.save(uuid1, model1.getDocument()); 61 String uuid2 = new UUIDGenerator().newUUID(); 62 XCSDocumentParser model2 = new XCSDocumentParser(IComponent.TYPE.EVENT); 63 storage.save(uuid2, model2.getDocument()); 64 65 Iterator it = storage.iterator(); 66 Document result1 = (Document) it.next(); 67 Document result2 = (Document) it.next(); 68 69 assertNotNull(result1); 70 assertNotNull(result2); 71 } 72 73 public void testRemove() throws Exception { 74 String uuid = new UUIDGenerator().newUUID(); 75 XCSDocumentParser model = new XCSDocumentParser(IComponent.TYPE.EVENT); 76 storage.save(uuid, model.getDocument()); 77 78 storage.remove(uuid); 79 80 try { 81 Document result = storage.load(uuid); 82 } catch (StoreException e) { 83 return; 85 } catch (Exception e) { 86 fail("Expected StoreException, not " + e.getMessage()); 87 } 88 89 fail("Expected StoreException, got no exception"); 90 91 } 92 93 protected void tearDown() throws Exception { 94 95 96 File [] list = file.listFiles(); 98 99 for (int i = 0; i < list.length; i++) { 100 list[i].delete(); 101 } 102 103 file.delete(); 105 106 } 107 108 } 109 | Popular Tags |