1 19 20 package org.openide.actions; 21 22 import org.netbeans.junit.*; 23 import junit.textui.TestRunner; 24 import org.openide.actions.*; 25 import org.openide.util.actions.SystemAction; 26 import org.openide.nodes.Node; 27 import org.openide.nodes.AbstractNode; 28 import org.openide.nodes.Children; 29 import org.openide.nodes.Index; 30 import java.util.Arrays ; 31 32 35 public class MoveUpActionTest extends NbTestCase { 36 37 static { 38 ActionsInfraHid.class.getName(); 40 } 41 42 public MoveUpActionTest(String name) { 43 super(name); 44 } 45 46 public static void main(String [] args) { 47 TestRunner.run(new NbTestSuite(MoveUpActionTest.class)); 48 } 49 50 private Node n, n1, n2, n3; 51 52 protected void setUp() throws Exception { 53 n1 = new AbstractNode(Children.LEAF); 54 n1.setName("n1"); 55 n2 = new AbstractNode(Children.LEAF); 56 n2.setName("n2"); 57 n3 = new AbstractNode(Children.LEAF); 58 n3.setName("n3"); 59 final Index.ArrayChildren c = new Index.ArrayChildren() { 60 { 61 add(new Node[] {n1, n2, n3}); 62 } 63 public void reorder() { 64 reorder(new int[] {1, 2, 0}); 65 } 66 }; 67 n = new AbstractNode(c) { 68 { 69 getCookieSet().add(c); 70 } 71 }; 72 n.setName("n"); 73 } 74 75 79 protected boolean runInEQ() 80 { 81 return true; 82 } 83 84 public void testBasicUsage() throws Exception { 85 SystemAction mua = SystemAction.get(MoveUpAction.class); 86 SystemAction mda = SystemAction.get(MoveDownAction.class); 87 SystemAction roa = SystemAction.get(ReorderAction.class); 88 ActionsInfraHid.WaitPCL l = null; 89 try { 90 assertNull(ActionsInfraHid.UT.getCurrentNodes()); 91 assertFalse(mua.isEnabled()); 92 assertFalse(mda.isEnabled()); 93 assertFalse(roa.isEnabled()); 94 l = new ActionsInfraHid.WaitPCL(SystemAction.PROP_ENABLED); 95 mua.addPropertyChangeListener(l); 96 assertFalse(mua.isEnabled()); 97 assertFalse(mda.isEnabled()); 98 assertFalse(roa.isEnabled()); 99 ActionsInfraHid.UT.setCurrentNodes(new Node[] {n}); 100 if (!l.changed()) { 101 Thread.sleep(1000); 102 } 103 l.gotit = 0; 104 assertFalse(mua.isEnabled()); 105 assertFalse(mda.isEnabled()); 106 assertTrue(roa.isEnabled()); 107 assertEquals(Arrays.asList(new Node[] {n1, n2, n3}), Arrays.asList(n.getChildren().getNodes())); 108 roa.actionPerformed(null); 109 assertEquals(Arrays.asList(new Node[] {n3, n1, n2}), Arrays.asList(n.getChildren().getNodes())); 110 assertTrue(roa.isEnabled()); 111 ActionsInfraHid.UT.setCurrentNodes(new Node[] {n1, n2}); 112 if (!l.changed()) { 113 Thread.sleep(1000); 114 } 115 l.gotit = 0; 116 assertFalse(mua.isEnabled()); 117 assertFalse(mda.isEnabled()); 118 assertFalse(roa.isEnabled()); 119 ActionsInfraHid.UT.setCurrentNodes(new Node[] {n1}); 120 if (!l.changed()) { 121 Thread.sleep(1000); 122 } 123 l.gotit = 0; 124 assertTrue("MoveUp is enabled on a node in the middle of its parents", mua.isEnabled()); 125 assertTrue(mda.isEnabled()); 126 assertFalse(roa.isEnabled()); 127 mua.actionPerformed(null); 128 assertEquals(Arrays.asList(new Node[] {n1, n3, n2}), Arrays.asList(n.getChildren().getNodes())); 129 if (!l.changed()) { 130 Thread.sleep(1000); 131 } 132 l.gotit = 0; 133 assertTrue("MoveUp is turned off after a node is moved to the very top", !mua.isEnabled()); 134 assertTrue(mda.isEnabled()); 135 assertFalse(roa.isEnabled()); 136 ActionsInfraHid.UT.setCurrentNodes(new Node[] {n2}); 137 if (!l.changed()) { 138 Thread.sleep(1000); 139 } 140 l.gotit = 0; 141 assertTrue(mua.isEnabled()); 142 assertFalse(mda.isEnabled()); 143 assertFalse(roa.isEnabled()); 144 ActionsInfraHid.UT.setCurrentNodes(new Node[] {n3}); 145 if (!l.changed()) { 146 Thread.sleep(1000); 147 } 148 l.gotit = 0; 149 assertTrue(mua.isEnabled()); 150 assertTrue(mda.isEnabled()); 151 assertFalse(roa.isEnabled()); 152 mda.actionPerformed(null); 153 assertEquals(Arrays.asList(new Node[] {n1, n2, n3}), Arrays.asList(n.getChildren().getNodes())); 154 if (!l.changed()) { 155 Thread.sleep(1000); 156 } 157 l.gotit = 0; 158 assertTrue(mua.isEnabled()); 159 assertFalse(mda.isEnabled()); 160 assertFalse(roa.isEnabled()); 161 } finally { 162 if (l != null) { 163 mua.removePropertyChangeListener(l); 164 mda.removePropertyChangeListener(l); 165 roa.removePropertyChangeListener(l); 166 } 167 ActionsInfraHid.UT.setCurrentNodes(new Node[0]); 168 ActionsInfraHid.UT.setCurrentNodes(null); 169 } 170 } 171 172 } 173 | Popular Tags |