1 19 20 package org.netbeans.api.convertor; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.io.FileReader ; 25 import java.io.Reader ; 26 import java.io.StringReader ; 27 import java.io.StringWriter ; 28 import java.util.ArrayList ; 29 import java.util.Set ; 30 import java.util.Collection ; 31 import java.util.Iterator ; 32 import javax.swing.JLabel ; 33 import org.netbeans.junit.*; 34 import junit.textui.TestRunner; 35 import org.netbeans.spi.convertor.Convertor; 36 import org.openide.filesystems.Repository; 37 import org.openide.modules.ModuleInfo; 38 import org.openide.util.Lookup; 39 40 41 45 public class ConvertorsTest extends NbTestCase { 46 47 48 public ConvertorsTest(String name) { 49 super (name); 50 } 51 52 public static void main(String [] args) { 53 TestRunner.run(new NbTestSuite(ConvertorsTest.class)); 54 } 55 56 protected void setUp () throws Exception { 57 Lookup.getDefault().lookup(ModuleInfo.class); 58 Repository.getDefault ().getDefaultFileSystem ().getRoot (); 59 } 60 61 public void testCanRead() throws Exception { 62 assertFalse(Convertors.canRead("http://www.dot.com/ns/smth", "tag")); 63 } 64 65 public void testCanWrite() throws Exception { 66 assertFalse(Convertors.canWrite(new JLabel ("aaa"))); 67 } 68 69 public void testListeners() throws Exception { 70 ModuleUtils.DEFAULT.install(); 71 72 Listener l = new Listener (); 73 Convertors.getDefault().addPropertyChangeListener(l); 74 Collection col = Convertors.getDefault().getConvertorDescriptors(); 75 int initialSize = col.size(); 76 ModuleUtils.DEFAULT.enableBookModule(true); 77 col = Convertors.getDefault().getConvertorDescriptors(); 78 assertTrue("Number of items in list of convertors does not much", col.size() == 1+initialSize); 79 assertTrue("Event not received", l.e.size() == 1); 80 assertTrue("Event name incorrect", ((PropertyChangeEvent )l.e.get(0)).getPropertyName().equals(Convertors.CONVERTOR_DESCRIPTORS)); 81 assertTrue("Number of old events incorrect", ((Set )((PropertyChangeEvent )l.e.get(0)).getOldValue()).size() == 0+initialSize); 82 assertTrue("Number of new events incorrect", ((Set )((PropertyChangeEvent )l.e.get(0)).getNewValue()).size() == 1+initialSize); 83 assertEquals("Event has incorrect new value", col, ((PropertyChangeEvent )l.e.get(0)).getNewValue()); 84 l.reset(); 85 86 ModuleUtils.DEFAULT.enableDVDConvertorModule(true); 87 col = Convertors.getDefault().getConvertorDescriptors(); 88 assertTrue("Number of items in list of convertors does not much", col.size() == 2+initialSize); 89 assertTrue("Event not received", l.e.size() == 1); 90 assertTrue("Event name incorrect", ((PropertyChangeEvent )l.e.get(0)).getPropertyName().equals(Convertors.CONVERTOR_DESCRIPTORS)); 91 assertTrue("Number of old events incorrect", ((Set )((PropertyChangeEvent )l.e.get(0)).getOldValue()).size() == 1+initialSize); 92 assertTrue("Number of new events incorrect", ((Set )((PropertyChangeEvent )l.e.get(0)).getNewValue()).size() == 2+initialSize); 93 assertEquals("Event has incorrect new value", col, ((PropertyChangeEvent )l.e.get(0)).getNewValue()); 94 l.reset(); 95 96 ModuleUtils.DEFAULT.enableShoppingCartConvertorModule(true); 97 col = Convertors.getDefault().getConvertorDescriptors(); 98 assertTrue("Number of items in list of convertors does not much", col.size() == 3+initialSize); 99 assertTrue("Event not received", l.e.size() == 1); 100 assertTrue("Event name incorrect", ((PropertyChangeEvent )l.e.get(0)).getPropertyName().equals(Convertors.CONVERTOR_DESCRIPTORS)); 101 assertTrue("Number of old events incorrect", ((Set )((PropertyChangeEvent )l.e.get(0)).getOldValue()).size() == 2+initialSize); 102 assertTrue("Number of new events incorrect", ((Set )((PropertyChangeEvent )l.e.get(0)).getNewValue()).size() == 3+initialSize); 103 assertEquals("Event has incorrect new value", col, ((PropertyChangeEvent )l.e.get(0)).getNewValue()); 104 l.reset(); 105 106 ModuleUtils.DEFAULT.enableShoppingCartConvertorModule(false); 107 col = Convertors.getDefault().getConvertorDescriptors(); 108 assertTrue("Number of items in list of convertors does not much", col.size() == 2+initialSize); 109 assertTrue("Event not received", l.e.size() == 1); 110 assertTrue("Event name incorrect", ((PropertyChangeEvent )l.e.get(0)).getPropertyName().equals(Convertors.CONVERTOR_DESCRIPTORS)); 111 assertTrue("Number of old events incorrect", ((Set )((PropertyChangeEvent )l.e.get(0)).getOldValue()).size() == 3+initialSize); 112 assertTrue("Number of new events incorrect", ((Set )((PropertyChangeEvent )l.e.get(0)).getNewValue()).size() == 2+initialSize); 113 assertEquals("Event has incorrect new value", col, ((PropertyChangeEvent )l.e.get(0)).getNewValue()); 114 l.reset(); 115 116 ModuleUtils.DEFAULT.enableDVDConvertorModule(false); 117 col = Convertors.getDefault().getConvertorDescriptors(); 118 assertTrue("Number of items in list of convertors does not much", col.size() == 1+initialSize); 119 assertTrue("Event not received", l.e.size() == 1); 120 assertTrue("Event name incorrect", ((PropertyChangeEvent )l.e.get(0)).getPropertyName().equals(Convertors.CONVERTOR_DESCRIPTORS)); 121 assertTrue("Number of old events incorrect", ((Set )((PropertyChangeEvent )l.e.get(0)).getOldValue()).size() == 2+initialSize); 122 assertTrue("Number of new events incorrect", ((Set )((PropertyChangeEvent )l.e.get(0)).getNewValue()).size() == 1+initialSize); 123 assertEquals("Event has incorrect new value", col, ((PropertyChangeEvent )l.e.get(0)).getNewValue()); 124 l.reset(); 125 126 ModuleUtils.DEFAULT.enableBookModule(false); 127 col = Convertors.getDefault().getConvertorDescriptors(); 128 assertTrue("Number of items in list of convertors does not much", col.size() == 0+initialSize); 129 assertTrue("Event not received", l.e.size() == 1); 130 assertTrue("Event name incorrect", ((PropertyChangeEvent )l.e.get(0)).getPropertyName().equals(Convertors.CONVERTOR_DESCRIPTORS)); 131 assertTrue("Number of old events incorrect", ((Set )((PropertyChangeEvent )l.e.get(0)).getOldValue()).size() == 1+initialSize); 132 assertTrue("Number of new events incorrect", ((Set )((PropertyChangeEvent )l.e.get(0)).getNewValue()).size() == 0+initialSize); 133 assertEquals("Event has incorrect new value", col, ((PropertyChangeEvent )l.e.get(0)).getNewValue()); 134 l.reset(); 135 136 ModuleUtils.DEFAULT.uninstall(); 137 Convertors.getDefault().removePropertyChangeListener(l); 138 } 139 140 private static class Listener implements PropertyChangeListener { 141 142 ArrayList e = new ArrayList (); 143 144 public Listener() { 145 } 146 147 public void reset() { 148 e = new ArrayList (); 149 } 150 151 public void propertyChange(java.beans.PropertyChangeEvent evt) { 152 e.add(evt); 153 } 154 155 } 156 157 } 158 | Popular Tags |