1 /*
   2  * Copyright (c) 2014, 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. Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package javafx.scene.control.test.cell;
  26 
  27 import client.test.Smoke;
  28 import com.sun.javafx.scene.control.LabeledText;
  29 import java.util.Map;
  30 import javafx.collections.FXCollections;
  31 import javafx.collections.ObservableList;
  32 import javafx.scene.Node;
  33 import javafx.scene.control.TableCell;
  34 import javafx.scene.control.TableView;
  35 import javafx.scene.control.TextField;
  36 import javafx.scene.control.test.cellapps.CellsApp.CellType;
  37 import javafx.scene.control.test.cellapps.CellsApp.DataItem;
  38 import javafx.scene.control.test.cellapps.TableCellsApp;
  39 import org.jemmy.action.GetAction;
  40 import org.jemmy.control.Wrap;
  41 import org.jemmy.env.Timeout;
  42 import org.jemmy.fx.ByID;
  43 import org.jemmy.fx.Root;
  44 import org.jemmy.interfaces.*;
  45 import org.jemmy.lookup.Lookup;
  46 import org.jemmy.lookup.LookupCriteria;
  47 import org.jemmy.timing.State;
  48 import org.jemmy.timing.Waiter;
  49 import org.junit.Before;
  50 import org.junit.BeforeClass;
  51 import org.junit.Test;
  52 import org.junit.runner.RunWith;
  53 import test.javaclient.shared.FilteredTestRunner;
  54 
  55 @RunWith(FilteredTestRunner.class)
  56 public class TableCellsTest extends TreeTableCellsTest {
  57 
  58     @BeforeClass
  59     public static void setUpClass() throws Exception {
  60         TableCellsApp.main(null);
  61     }
  62 
  63     @Before
  64     @Override
  65     public void tableSetUpClass() throws Exception {
  66         updateWraps();
  67         testedControl = parent.lookup(TableView.class, new ByID<TableView>(TableCellsApp.TABLE_VIEW_ID)).wrap();
  68         cellID = TableCellsApp.TABLE_EDIT_ID;
  69         choiceID = TableCellsApp.TABLE_FACTORY_CHOICE_ID;
  70     }
  71 
  72     @Override
  73     protected Wrap select(final String data) {
  74         Wrap wrap = testedControl.as(Table.class, DataItem.class).lookup(new LookupCriteria<DataItem>() {
  75             public boolean check(DataItem tableData) {
  76                 return tableData.toString().contains(data);
  77             }
  78         }).wrap();
  79         wrap.mouse().click();
  80         return wrap;
  81     }
  82 
  83     /**
  84      * Content of tableView can be stored
  85      */
  86     @Smoke
  87     @Test(timeout = 300000)
  88     public void MapCellFactoryTest() {
  89         doFactoryChange(CellType.MapValue);
  90         testedControl = parent.lookup(TableView.class, new ByID<TableView>(TableCellsApp.TABLE_VIEW_ID)).wrap();
  91         Lookup lookup = testedControl.as(Parent.class, Node.class).lookup(new LookupCriteria<Node>() {
  92             public boolean check(Node cntrl) {
  93                 if ((cntrl instanceof LabeledText) && (((LabeledText) cntrl).getText().equals(TableCellsApp.ContentOfMaps.get(0)))) {
  94                     return true;
  95                 }
  96                 return false;
  97             }
  98         });
  99         lookup.wrap(0).mouse().click();
 100         lookup.wrap(0).mouse().click();
 101         Lookup lookupOfTextField = testedControl.as(Parent.class, Node.class).lookup(new LookupCriteria<Node>() {
 102             public boolean check(Node cntrl) {
 103                 if (cntrl instanceof TextField) {
 104                     return true;
 105                 }
 106                 return false;
 107             }
 108         });
 109         Wrap<? extends TextField> wrap = ((Wrap<? extends TextField>) lookupOfTextField.wrap(0));
 110         wrap.keyboard().pushKey(Keyboard.KeyboardButtons.HOME);
 111         wrap.keyboard().pushKey(Keyboard.KeyboardButtons.END, Keyboard.KeyboardModifiers.SHIFT_DOWN_MASK);
 112         wrap.keyboard().pushKey(Keyboard.KeyboardButtons.DELETE);
 113 
 114         final String newValue = "NewValue";
 115         wrap.as(Text.class).type(newValue);
 116         wrap.keyboard().pushKey(Keyboard.KeyboardButtons.ENTER);
 117         new Waiter(new Timeout("", 2000)).ensureState(new State() {
 118             public Object reached() {
 119                 if (new GetAction<String>() {
 120                     @Override
 121                     public void run(Object... os) throws Exception {
 122                         setResult(((Map<String, String>) ((TableView) testedControl.getControl()).getItems().get(0)).get(TableCellsApp.Column1MapKey));
 123                     }
 124                 }.dispatch(Root.ROOT.getEnvironment()).equals(newValue)) {
 125                     return true;
 126                 } else {
 127                     return null;
 128                 }
 129             }
 130         });
 131 
 132         new Waiter(new Timeout("", 2000)).ensureState(new State() {
 133             public Object reached() {
 134                 final Wrap<? extends TableCell> tableCell = javafx.scene.control.test.tableview.TestBaseCommon.getCellWrap(testedControl, 0, 0);
 135                 if (new GetAction<String>() {
 136                     @Override
 137                     public void run(Object... os) throws Exception {
 138                         setResult((String) tableCell.getControl().getItem());
 139                     }
 140                 }.dispatch(Root.ROOT.getEnvironment()).equals(newValue)) {
 141                     return true;
 142                 } else {
 143                     return null;
 144                 }
 145             }
 146         });
 147     }
 148 
 149     @Override
 150     protected ObservableList<DataItem> getCurrentProgramValues() {
 151         return new GetAction<ObservableList<DataItem>>() {
 152             @Override
 153             public void run(Object... os) throws Exception {
 154                 setResult(FXCollections.observableArrayList(((TableView) testedControl.getControl()).getItems()));
 155             }
 156         }.dispatch(testedControl.getEnvironment());
 157     }
 158 }
--- EOF ---