1 2 17 18 19 package org.apache.poi.poifs.eventfilesystem; 20 21 import junit.framework.*; 22 23 import java.util.*; 24 25 import org.apache.poi.poifs.filesystem.POIFSDocumentPath; 26 27 32 33 public class TestPOIFSReaderRegistry 34 extends TestCase 35 { 36 private POIFSReaderListener[] listeners = 37 { 38 new Listener(), new Listener(), new Listener(), new Listener() 39 }; 40 private POIFSDocumentPath[] paths = 41 { 42 new POIFSDocumentPath(), new POIFSDocumentPath(new String [] 43 { 44 "a" 45 }), new POIFSDocumentPath(new String [] 46 { 47 "b" 48 }), new POIFSDocumentPath(new String [] 49 { 50 "c" 51 }) 52 }; 53 private String [] names = 54 { 55 "a0", "a1", "a2", "a3" 56 }; 57 58 63 64 public TestPOIFSReaderRegistry(String name) 65 { 66 super(name); 67 } 68 69 72 73 public void testEmptyRegistry() 74 { 75 POIFSReaderRegistry registry = new POIFSReaderRegistry(); 76 77 for (int j = 0; j < paths.length; j++) 78 { 79 for (int k = 0; k < names.length; k++) 80 { 81 Iterator listeners = registry.getListeners(paths[ j ], 82 names[ k ]); 83 84 assertTrue(!listeners.hasNext()); 85 } 86 } 87 } 88 89 92 93 public void testMixedRegistrationOperations() 94 { 95 POIFSReaderRegistry registry = new POIFSReaderRegistry(); 96 97 for (int j = 0; j < listeners.length; j++) 98 { 99 for (int k = 0; k < paths.length; k++) 100 { 101 for (int n = 0; n < names.length; n++) 102 { 103 if ((j != k) && (k != n)) 104 { 105 registry.registerListener(listeners[ j ], paths[ k ], 106 names[ n ]); 107 } 108 } 109 } 110 } 111 for (int k = 0; k < paths.length; k++) 112 { 113 for (int n = 0; n < names.length; n++) 114 { 115 Iterator listeners = registry.getListeners(paths[ k ], 116 names[ n ]); 117 118 if (k == n) 119 { 120 assertTrue(!listeners.hasNext()); 121 } 122 else 123 { 124 Set registeredListeners = new HashSet(); 125 126 while (listeners.hasNext()) 127 { 128 registeredListeners.add(listeners.next()); 129 } 130 assertEquals(this.listeners.length - 1, 131 registeredListeners.size()); 132 for (int j = 0; j < this.listeners.length; j++) 133 { 134 if (j == k) 135 { 136 assertTrue(!registeredListeners 137 .contains(this.listeners[ j ])); 138 } 139 else 140 { 141 assertTrue(registeredListeners 142 .contains(this.listeners[ j ])); 143 } 144 } 145 } 146 } 147 } 148 for (int j = 0; j < listeners.length; j++) 149 { 150 registry.registerListener(listeners[ j ]); 151 } 152 for (int k = 0; k < paths.length; k++) 153 { 154 for (int n = 0; n < names.length; n++) 155 { 156 Iterator listeners = 157 registry.getListeners(paths[ k ], names[ n ]); 158 Set registeredListeners = new HashSet(); 159 160 while (listeners.hasNext()) 161 { 162 registeredListeners.add(listeners.next()); 163 } 164 assertEquals(this.listeners.length, 165 registeredListeners.size()); 166 for (int j = 0; j < this.listeners.length; j++) 167 { 168 assertTrue(registeredListeners 169 .contains(this.listeners[ j ])); 170 } 171 } 172 } 173 } 174 175 180 181 public static void main(String [] ignored_args) 182 { 183 System.out.println( 184 "Testing org.apache.poi.poifs.eventfilesystem.POIFSReaderRegistry"); 185 junit.textui.TestRunner.run(TestPOIFSReaderRegistry.class); 186 } 187 } 188 | Popular Tags |