1 /* 2 * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package org.jemmy.browser; 25 26 import org.jemmy.Point; 27 import org.jemmy.Rectangle; 28 import org.jemmy.action.GetAction; 29 import org.jemmy.control.Property; 30 import org.jemmy.control.Wrap; 31 import org.jemmy.env.Environment; 32 import org.testng.annotations.BeforeClass; 33 import org.testng.annotations.DataProvider; 34 import org.testng.annotations.Test; 35 36 import javax.swing.JFrame; 37 import javax.swing.table.TableModel; 38 import java.awt.BorderLayout; 39 40 import static org.testng.Assert.fail; 41 42 43 /** 44 * 45 * @author shura 46 */ 47 public class PropPanelTest { 48 49 public PropPanelTest() { 50 } 51 52 static Wrap<? extends JFrame> frm; 53 static PropertiesPanel panel; 54 static TableModel table; 55 56 @BeforeClass 57 public static void setUpClass() throws Exception { 58 JFrame frame = new JFrame("test frame"); 59 frame.setVisible(true); 60 frame.setSize(400, 600); 61 frame.getContentPane().setLayout(new BorderLayout()); 62 panel = new PropertiesPanel(); 63 frame.getContentPane().add(panel, BorderLayout.CENTER); 64 frm = new TestWrap(Environment.getEnvironment(), frame); 65 panel.setWrap(frm); 66 table = panel.model; 67 } 68 @DataProvider(name = "testcases") 69 public Object[][] testcases() { 70 return new Object[][] { 71 {"bounds", Rectangle.class, null}, 72 {"control", JFrame.class, frm.getControl().toString()}, 73 {"clickPoint", Point.class, null}, 74 {"wrapper.class", Class.class, TestWrap.class.toString()}, 75 {"getTitle", String.class, "test frame"}, 76 {"control.class", Class.class, JFrame.class.toString()}, 77 {"isShowing", Boolean.class, "true"} 78 }; 79 } 80 81 @Test(dataProvider = "testcases") 82 public void checkTable(String name, Class cls, String expectedValue) { 83 for (int i = 0; i < table.getRowCount(); i++) { 84 if(table.getValueAt(i, 0).equals(name)) { 85 if(!table.getValueAt(i, 1).equals(cls.getName())) { 86 fail("Wrong class for " + name + ": " + table.getValueAt(i, 1) + " (expected " + cls.getName() + ")"); 87 } 88 if(expectedValue != null) { 89 if(!table.getValueAt(i, 2).equals(expectedValue)) { 90 fail("Wrong value for " + name + ": " + table.getValueAt(i, 2) + " (expected " + expectedValue + ")"); 91 } 92 } 93 return; 94 } 95 } 96 fail(name + " not found!"); 97 } 98 99 public static class TestWrap<T extends JFrame> extends Wrap<T> { 100 101 public TestWrap(Environment env, T frame) { 102 super(env, frame); 103 } 104 105 @Override 106 public Rectangle getScreenBounds() { 107 return new Rectangle( 108 getControl().getX(), 109 getControl().getY(), 110 getControl().getWidth(), 111 getControl().getHeight()); 112 } 113 @Property("getTitle") 114 public String getTitle() { 115 return new GetAction<String>() { 116 117 @Override 118 public void run(Object... parameters) throws Exception { 119 setResult(getControl().getTitle()); 120 } 121 }.dispatch(getEnvironment()); 122 } 123 @Property("isShowing") 124 public boolean isShowing() { 125 return new GetAction<Boolean>() { 126 127 @Override 128 public void run(Object... parameters) throws Exception { 129 setResult(getControl().isShowing()); 130 } 131 }.dispatch(getEnvironment()); 132 } 133 } 134 }