KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > calendar > store > LocalXMLFileStoreTest


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.calendar.store;
19
20 import java.io.File JavaDoc;
21 import java.util.Iterator JavaDoc;
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 JavaDoc file;
34
35     private LocalXMLFileStore storage;
36
37     protected void setUp() throws Exception JavaDoc {
38         file = new File JavaDoc("test_calendar");
39
40         storage = new LocalXMLFileStore(file);
41     }
42
43     public void testAddGet() throws Exception JavaDoc {
44         
45         XCSDocumentParser model = new XCSDocumentParser(IComponent.TYPE.EVENT);
46         String JavaDoc 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 JavaDoc {
58         String JavaDoc uuid1 = new UUIDGenerator().newUUID();
59         XCSDocumentParser model1 = new XCSDocumentParser(IComponent.TYPE.EVENT);
60         storage.save(uuid1, model1.getDocument());
61         String JavaDoc uuid2 = new UUIDGenerator().newUUID();
62         XCSDocumentParser model2 = new XCSDocumentParser(IComponent.TYPE.EVENT);
63         storage.save(uuid2, model2.getDocument());
64
65         Iterator JavaDoc 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 JavaDoc {
74         String JavaDoc 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             // this is the expected cases
84
return;
85         } catch (Exception JavaDoc 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 JavaDoc {
94
95         
96         // delete all data in directory
97
File JavaDoc[] list = file.listFiles();
98
99         for (int i = 0; i < list.length; i++) {
100             list[i].delete();
101         }
102
103         // delete folder
104
file.delete();
105         
106     }
107
108 }
109
Popular Tags