1 19 20 package org.openide.windows; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.io.ObjectInputStream ; 25 import junit.framework.TestCase; 26 import org.openide.util.io.NbMarshalledObject; 27 28 32 public class TopComponentTest extends TestCase { 33 34 public TopComponentTest(String testName) { 35 super(testName); 36 } 37 38 41 public void testReadExternal() throws Exception { 42 TopComponent tc = new TopComponent(); 44 tc.setName("testName"); 45 tc.setDisplayName("testdisplayName"); 46 tc.setToolTipText("testTooltip"); 47 NbMarshalledObject obj = new NbMarshalledObject(tc); 48 tc.close(); 49 50 tc = (TopComponent)obj.get(); 51 assertNotNull("One again", tc); 52 assertEquals("testName", tc.getName()); 53 assertEquals("testTooltip", tc.getToolTipText()); 54 assertEquals("testdisplayName", tc.getDisplayName()); 55 56 tc = new TopComponent(); 58 tc.setName("testName"); 59 tc.setToolTipText("testTooltip"); 60 obj = new NbMarshalledObject(tc); 61 tc.close(); 62 63 tc = (TopComponent)obj.get(); 64 assertNotNull("One again", tc); 65 assertEquals("testName", tc.getName()); 66 assertEquals("testTooltip", tc.getToolTipText()); 67 assertNull(tc.getDisplayName()); 68 69 } 70 71 74 public void testOldReadExternal() throws Exception { 75 TopComponent tc = null; 76 try { 77 ObjectInputStream stream = new ObjectInputStream ( 78 getClass().getResourceAsStream("data/oldTcWithoutDisplayName.ser")); 79 tc = (TopComponent)stream.readObject(); 80 stream.close(); 81 } catch (Exception exc) { 82 exc.printStackTrace(); 83 fail("Cannot read tc"); 84 } 85 86 87 assertNotNull("One again", tc); 88 assertEquals("testName", tc.getName()); 89 assertEquals("testTooltip", tc.getToolTipText()); 90 assertEquals("If the old component does not have a display name, then keep it null", null, tc.getDisplayName()); 91 } 92 93 TopComponent tcOpened = null; 94 TopComponent tcClosed = null; 95 96 public void testOpenedClosed () throws Exception { 97 System.out.println("Testing property firing of TopComponent's registry"); 98 tcOpened = null; 99 tcClosed = null; 100 101 TopComponent.getRegistry().addPropertyChangeListener( 102 new PropertyChangeListener () { 103 public void propertyChange(PropertyChangeEvent evt) { 104 if (TopComponent.Registry.PROP_TC_OPENED.equals(evt.getPropertyName())) { 105 tcOpened = (TopComponent) evt.getNewValue(); 106 } 107 if (TopComponent.Registry.PROP_TC_CLOSED.equals(evt.getPropertyName())) { 108 tcClosed = (TopComponent) evt.getNewValue(); 109 } 110 } 111 }); 112 113 TopComponent tc = new TopComponent(); 114 115 tc.open(); 116 assertNotNull("Property change was not fired, tcOpened is null", tcOpened); 117 assertEquals("New value in property change is wrong", tc, tcOpened); 118 119 tc.close(); 120 assertNotNull("Property change was not fired, tcClosed is null", tcClosed); 121 assertEquals("New value in property change is wrong", tc, tcClosed); 122 123 } 124 125 126 127 } 128 | Popular Tags |