1 7 22 23 package de.schlichtherle.key.passwd.swing; 24 25 import de.schlichtherle.key.*; 26 27 import java.awt.*; 28 import java.lang.reflect.*; 29 30 import javax.swing.*; 31 32 import junit.framework.*; 33 import junit.framework.Test; 34 35 import org.netbeans.jemmy.*; 36 import org.netbeans.jemmy.operators.*; 37 38 43 public class AesKeyStrengthPanelTest extends TestCase { 44 static { 45 JemmyProperties.setCurrentOutput(TestOut.getNullOutput()); } 47 48 private AesKeyStrengthPanel instance; 49 private JFrame frame; 50 private JFrameOperator frameOp; 51 52 public AesKeyStrengthPanelTest(String testName) { 53 super(testName); 54 } 55 56 protected void setUp() throws Exception { 57 EventQueue.invokeLater(new Runnable () { 58 public void run() { 59 instance = new AesKeyStrengthPanel(); 60 frame = new JFrame(); 61 frame.getContentPane().add(instance); 62 frame.pack(); 63 frame.setLocationRelativeTo(null); 64 frame.setVisible(true); 65 } 66 }); 67 68 frameOp = new JFrameOperator(); } 70 71 protected void tearDown() throws Exception { 72 EventQueue.invokeAndWait(new Runnable () { 73 public void run() { 74 frame.setVisible(false); 75 frame.dispose(); 76 } 77 }); 78 } 79 80 public static Test suite() throws Exception { 81 89 90 TestSuite suite = new TestSuite(AesKeyStrengthPanelTest.class); 91 92 return suite; 93 } 94 95 98 public void testKeyStrength() throws Exception { 99 int keyStrength, expResult, selection; 100 101 JComboBoxOperator comboBoxOp = new JComboBoxOperator(frameOp); 102 103 107 expResult = AesKeyProvider.KEY_STRENGTH_256; 108 keyStrength = instance.getKeyStrength(); 109 assertEquals(expResult, keyStrength); 110 selection = comboBoxOp.getSelectedIndex(); 111 assertEquals(expResult, selection); 112 sleep(); 113 114 118 expResult = AesKeyProvider.KEY_STRENGTH_128; 119 instance.setKeyStrength(expResult); 120 keyStrength = instance.getKeyStrength(); 121 assertEquals(expResult, keyStrength); 122 selection = comboBoxOp.getSelectedIndex(); 123 assertEquals(expResult, selection); 124 sleep(); 125 126 expResult = AesKeyProvider.KEY_STRENGTH_192; 127 instance.setKeyStrength(expResult); 128 keyStrength = instance.getKeyStrength(); 129 assertEquals(expResult, keyStrength); 130 selection = comboBoxOp.getSelectedIndex(); 131 assertEquals(expResult, selection); 132 sleep(); 133 134 expResult = AesKeyProvider.KEY_STRENGTH_256; 135 instance.setKeyStrength(expResult); 136 keyStrength = instance.getKeyStrength(); 137 assertEquals(expResult, keyStrength); 138 selection = comboBoxOp.getSelectedIndex(); 139 assertEquals(expResult, selection); 140 sleep(); 141 142 expResult = AesKeyProvider.KEY_STRENGTH_256; 143 try { 144 instance.setKeyStrength(AesKeyProvider.KEY_STRENGTH_128 - 1); 145 fail("Expected IllegalArgumentException"); 146 } catch (IllegalArgumentException expected) { 147 } 148 keyStrength = instance.getKeyStrength(); 149 assertEquals(expResult, keyStrength); 150 selection = comboBoxOp.getSelectedIndex(); 151 assertEquals(expResult, selection); 152 154 expResult = AesKeyProvider.KEY_STRENGTH_256; 155 try { 156 instance.setKeyStrength(AesKeyProvider.KEY_STRENGTH_256 + 1); 157 fail("Expected IllegalArgumentException"); 158 } catch (IllegalArgumentException expected) { 159 } 160 keyStrength = instance.getKeyStrength(); 161 assertEquals(expResult, keyStrength); 162 selection = comboBoxOp.getSelectedIndex(); 163 assertEquals(expResult, selection); 164 166 170 expResult = AesKeyProvider.KEY_STRENGTH_128; 171 comboBoxOp.setSelectedIndex(expResult); 172 keyStrength = instance.getKeyStrength(); 173 assertEquals(expResult, keyStrength); 174 selection = comboBoxOp.getSelectedIndex(); 175 assertEquals(expResult, selection); 176 sleep(); 177 178 expResult = AesKeyProvider.KEY_STRENGTH_192; 179 comboBoxOp.setSelectedIndex(expResult); 180 keyStrength = instance.getKeyStrength(); 181 assertEquals(expResult, keyStrength); 182 selection = comboBoxOp.getSelectedIndex(); 183 assertEquals(expResult, selection); 184 sleep(); 185 186 expResult = AesKeyProvider.KEY_STRENGTH_256; 187 comboBoxOp.setSelectedIndex(expResult); 188 keyStrength = instance.getKeyStrength(); 189 assertEquals(expResult, keyStrength); 190 selection = comboBoxOp.getSelectedIndex(); 191 assertEquals(expResult, selection); 192 sleep(); 193 }; 194 195 private static void sleep() { 196 try { 198 Thread.sleep(50); 199 } catch (InterruptedException ex) { 200 throw new UndeclaredThrowableException(ex); 201 } 202 } 203 } 204 | Popular Tags |