1 17 package org.apache.excalibur.store.impl; 18 19 import java.io.File ; 20 import java.io.IOException ; 21 22 import junit.framework.TestCase; 23 24 import org.apache.avalon.framework.logger.ConsoleLogger; 25 import org.apache.avalon.framework.logger.Logger; 26 import org.apache.avalon.framework.logger.NullLogger; 27 import org.apache.avalon.framework.parameters.Parameters; 28 29 35 public class ClearJispFilesystemStoreTestCase extends TestCase { 36 37 38 private JispFilesystemStore m_store; 39 40 41 private final Logger m_logger = 42 new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG); 43 44 45 private int MAX_ENTRIES = 100; 46 47 48 private File m_tempDir; 49 50 53 public void setUp() throws Exception { 54 m_logger.debug("-BGN--> setUp() fixture for " + getName()); 55 56 m_tempDir = File.createTempFile("jisp", "test"); 57 m_tempDir.delete(); 58 m_tempDir.mkdir(); 59 60 m_store = new JispFilesystemStore(); 61 62 m_store.enableLogging(new NullLogger()); 64 65 final Parameters params = new Parameters(); 67 params.setParameter("directory", m_tempDir.toString()); 68 params.makeReadOnly(); 69 70 m_store.parameterize(params); 72 73 75 fillStore(); 76 77 m_logger.debug("-END--> setUp() fixture for " + getName()); 78 79 } 80 81 85 private void fillStore() throws IOException { 86 String key = null; 87 String value = null; 88 m_logger.debug("filling the database..."); 89 for (int i = 0; i < MAX_ENTRIES; i++) { 90 key = "key" + i; 91 value = "value" + i; 92 m_store.store(key, value); 93 } 94 m_logger.debug("filling the database...OK"); 95 } 96 97 101 public void testRemove() { 102 m_logger.debug("-BGN--> testRemove()"); 103 final String key = "key" + (MAX_ENTRIES - 10); 105 m_logger.debug("removing key: " + key); 106 m_store.remove(key); 107 Object item = m_store.get(key); 109 if (item != null) { 110 assertTrue("The store item for key=" + key + " has value of " + item.toString(), item == null); 111 } else { 112 assertTrue(item == null); 113 } 114 m_logger.debug("-END--> testRemove()"); 115 116 } 117 118 123 public void testClear() throws Exception { 124 m_logger.debug("-BGN--> testClear()"); 125 final int sizeBefore = m_store.size(); 126 m_logger.debug("store size before clear:" + sizeBefore); 127 m_logger.debug("index count before clear:" + m_store.m_Index.count()); 128 m_store.clear(); 129 final int sizeAfter = m_store.size(); 130 m_logger.debug("store size after clear:" + sizeAfter); 131 m_logger.debug("index count after clear:" + m_store.m_Index.count()); 132 assertTrue(sizeAfter == 0); 133 m_logger.debug("-END--> testClear()"); 134 } 135 136 139 protected void tearDown() throws Exception { 140 m_logger.debug("-BGN--> tearUp() fixture for test " + getName()); 141 m_logger.debug("deleting index and database"); 142 deleteAll(m_tempDir); 143 m_logger.debug("-END--> tearUp() fixture for test " + getName()); 144 } 145 146 150 private void deleteAll(File f) { 151 if (f.isDirectory()) { 152 File [] children = f.listFiles(); 153 for (int i = 0; i < children.length; i++) { 154 deleteAll(children[i]); 155 } 156 } 157 158 f.delete(); 159 } 160 } 161 162 163 | Popular Tags |