1 /* 2 * To change this template, choose Tools | Templates 3 * and open the template in the editor. 4 */ 5 6 package org.jemmy.browser; 7 8 import org.jemmy.Point; 9 import org.jemmy.Rectangle; 10 import org.jemmy.action.GetAction; 11 import org.jemmy.control.Property; 12 import org.jemmy.control.Wrap; 13 import org.jemmy.env.Environment; 14 import org.testng.annotations.BeforeClass; 15 import org.testng.annotations.DataProvider; 16 import org.testng.annotations.Test; 17 18 import javax.swing.JFrame; 19 import javax.swing.table.TableModel; 20 import java.awt.BorderLayout; 21 22 import static org.testng.Assert.fail; 23 24 25 /** 26 * 27 * @author shura 28 */ 29 public class PropPanelTest { 30 31 public PropPanelTest() { 32 } 33 34 static Wrap<? extends JFrame> frm; 35 static PropertiesPanel panel; 36 static TableModel table; 37 38 @BeforeClass 39 public static void setUpClass() throws Exception { 40 JFrame frame = new JFrame("test frame"); 41 frame.setVisible(true); 42 frame.setSize(400, 600); 43 frame.getContentPane().setLayout(new BorderLayout()); 44 panel = new PropertiesPanel(); 45 frame.getContentPane().add(panel, BorderLayout.CENTER); 46 frm = new TestWrap(Environment.getEnvironment(), frame); 47 panel.setWrap(frm); 48 table = panel.model; 49 } 50 @DataProvider(name = "testcases") 51 public Object[][] testcases() { 52 return new Object[][] { 53 {"bounds", Rectangle.class, null}, 54 {"control", JFrame.class, frm.getControl().toString()}, 55 {"clickPoint", Point.class, null}, 56 {"wrapper.class", Class.class, TestWrap.class.toString()}, 57 {"getTitle", String.class, "test frame"}, 58 {"control.class", Class.class, JFrame.class.toString()}, 59 {"isShowing", Boolean.class, "true"} 60 }; 61 } 62 63 @Test(dataProvider = "testcases") 64 public void checkTable(String name, Class cls, String expectedValue) { 65 for (int i = 0; i < table.getRowCount(); i++) { 66 if(table.getValueAt(i, 0).equals(name)) { 67 if(!table.getValueAt(i, 1).equals(cls.getName())) { 68 fail("Wrong class for " + name + ": " + table.getValueAt(i, 1) + " (expected " + cls.getName() + ")"); 69 } 70 if(expectedValue != null) { 71 if(!table.getValueAt(i, 2).equals(expectedValue)) { 72 fail("Wrong value for " + name + ": " + table.getValueAt(i, 2) + " (expected " + expectedValue + ")"); 73 } 74 } 75 return; 76 } 77 } 78 fail(name + " not found!"); 79 } 80 81 public static class TestWrap<T extends JFrame> extends Wrap<T> { 82 83 public TestWrap(Environment env, T frame) { 84 super(env, frame); 85 } 86 87 @Override 88 public Rectangle getScreenBounds() { 89 return new Rectangle( 90 getControl().getX(), 91 getControl().getY(), 92 getControl().getWidth(), 93 getControl().getHeight()); 94 } 95 @Property("getTitle") 96 public String getTitle() { 97 return new GetAction<String>() { 98 99 @Override 100 public void run(Object... parameters) throws Exception { 101 setResult(getControl().getTitle()); 102 } 103 }.dispatch(getEnvironment()); 104 } 105 @Property("isShowing") 106 public boolean isShowing() { 107 return new GetAction<Boolean>() { 108 109 @Override 110 public void run(Object... parameters) throws Exception { 111 setResult(getControl().isShowing()); 112 } 113 }.dispatch(getEnvironment()); 114 } 115 } 116 }