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.datepicker; 26 27 import java.time.chrono.Chronology; 28 import java.util.HashMap; 29 import javafx.scene.Node; 30 import javafx.scene.control.test.utils.ptables.AbstractPropertyController.SettingType; 31 import org.jemmy.Point; 32 import org.jemmy.fx.control.TextInputControlDock; 33 import org.jemmy.interfaces.Keyboard.KeyboardButtons; 34 import org.jemmy.interfaces.Parent; 35 import static org.junit.Assert.fail; 36 import org.junit.Test; 37 import org.junit.runner.RunWith; 38 import test.javaclient.shared.FilteredTestRunner; 39 40 /** 41 * 42 * @author Dmitry Zinkevich 43 */ 44 @RunWith(FilteredTestRunner.class) 45 public class ChronologiesTest extends TestBase { 46 /** 47 * Checks initial appearance of the DateChooser 48 * with predefined date using ISO chronology. 49 */ 50 @Test(timeout = 10000) 51 public void initialPopupAppearanceISO() throws Throwable { 52 selectObjectFromChoiceBox(SettingType.SETTER, Properties.chronology, Chronology.of("ISO")); 53 setDefaultDate(); 54 showPopup(); 55 56 checkScreenshot("DatePicker-initialPopupISO", getRootWrap(getPopupWrap())); 57 throwScreenshotError(); 58 } 59 60 /** 61 * Checks initial appearance of the DateChooser 62 * with predefined date using Minguo chronology. 63 */ 64 @Test(timeout = 10000) 65 public void initialPopupAppearanceMinguo() throws Throwable { 66 selectObjectFromChoiceBox(SettingType.SETTER, Properties.chronology, Chronology.of("Minguo")); 67 setDefaultDate(); 68 showPopup(); 69 70 checkScreenshot("DatePicker-initialPopupMinguo", getRootWrap(getPopupWrap())); 71 throwScreenshotError(); 72 } 73 74 /** 75 * Checks initial appearance of the DateChooser 76 * with predefined date using ThaiBuddhist chronology. 77 */ 78 @Test(timeout = 10000) 79 public void initialPopupAppearanceThaiBuddhist() throws Throwable { 80 selectObjectFromChoiceBox(SettingType.SETTER, Properties.chronology, Chronology.of("ThaiBuddhist")); 81 setDefaultDate(); 82 showPopup(); 83 84 checkScreenshot("DatePicker-initialPopupThaiBuddhist", getRootWrap(getPopupWrap())); 85 throwScreenshotError(); 86 } 87 88 /** 89 * Checks initial appearance of the DateChooser 90 * with predefined date using Japanese chronology. 91 */ 92 @Test(timeout = 10000) 93 public void initialPopupAppearanceJapanese() throws Throwable { 94 selectObjectFromChoiceBox(SettingType.SETTER, Properties.chronology, Chronology.of("Japanese")); 95 setDefaultDate(); 96 showPopup(); 97 98 checkScreenshot("DatePicker-initialPopupJapanese", getRootWrap(getPopupWrap())); 99 throwScreenshotError(); 100 } 101 102 /** 103 * Checks initial appearance of the DateChooser 104 * with predefined date using Hijrah-umalqura chronology. 105 */ 106 @Test(timeout = 10000) 107 public void initialPopupAppearanceHijrahUmalqura() throws Throwable { 108 final Chronology chronology = Chronology.of("Hijrah-umalqura"); 109 selectObjectFromChoiceBox(SettingType.SETTER, Properties.chronology, chronology); 110 setDefaultDate(); 111 showPopup(); 112 checkScreenshot("DatePicker-initialPopupHijrahUmalqura", getRootWrap(getPopupWrap())); 113 throwScreenshotError(); 114 } 115 116 /** 117 * Checks that DateField shows correct date representation 118 * according using ISO chronology. 119 */ 120 @Test(timeout = 10000) 121 public void dateRepresentationISO() { 122 selectObjectFromChoiceBox(SettingType.SETTER, Properties.chronology, Chronology.of("ISO")); 123 setDefaultDate(); 124 waitShownText("10/11/1990"); 125 } 126 127 /** 128 * Checks that DateField shows correct date representation 129 * according using Minguo chronology. 130 */ 131 @Test(timeout = 10000) 132 public void dateRepresentationMinguo() { 133 selectObjectFromChoiceBox(SettingType.SETTER, Properties.chronology, Chronology.of("Minguo")); 134 setDefaultDate(); 135 waitShownText("10/11/0079 1"); 136 } 137 138 /** 139 * Checks that DateField shows correct date representation 140 * according using Thai Buddhist chronology. 141 */ 142 @Test(timeout = 10000) 143 public void dateRepresentationThaiBuddhist() { 144 selectObjectFromChoiceBox(SettingType.SETTER, Properties.chronology, Chronology.of("ThaiBuddhist")); 145 setDefaultDate(); 146 waitShownText("10/11/2533 B.E."); 147 } 148 149 /** 150 * Checks that DateField shows correct date representation 151 * according using Japanese chronology. 152 */ 153 @Test(timeout = 10000) 154 public void dateRepresentationJapanese() { 155 selectObjectFromChoiceBox(SettingType.SETTER, Properties.chronology, Chronology.of("Japanese")); 156 setDefaultDate(); 157 waitShownText("10/11/0002 H"); 158 } 159 160 /** 161 * Checks that DateField shows correct date representation 162 * according using Hijrah-umalqura chronology. 163 */ 164 @Test(timeout = 10000) 165 public void dateRepresentationHijrahUmalqura() { 166 selectObjectFromChoiceBox(SettingType.SETTER, Properties.chronology, Chronology.of("Hijrah-umalqura")); 167 setDefaultDate(); 168 waitShownText("3/21/1411 AH"); 169 } 170 171 /** 172 * Test checks that after typing 173 * a correct date in the DateField the DateChooser will render 174 * it correctly. 175 * Using ISO chronology. 176 */ 177 @Test(timeout = 10000) 178 public void dateTypingISO() throws InterruptedException { 179 HashMap<String, String> expectedState = new HashMap<String, String>(3); 180 expectedState.put("selectedDay", "29"); 181 expectedState.put("monthName", "february"); 182 expectedState.put("year", "2012"); 183 checkTypedDate(Chronology.of("ISO"), expectedState, "2/29/2012"); 184 } 185 186 /** 187 * Test checks that after typing 188 * a correct date in the DateField the DateChooser will render 189 * it correctly. 190 * Using Minguo chronology. 191 */ 192 @Test(timeout = 10000) 193 public void dateTypingMinguo() throws InterruptedException { 194 HashMap<String, String> expectedState = new HashMap<String, String>(3); 195 expectedState.put("selectedDay", "29"); 196 expectedState.put("monthName", "february"); 197 expectedState.put("year", "101"); 198 checkTypedDate(Chronology.of("Minguo"), expectedState, "2/29/0101 1"); 199 } 200 201 /** 202 * Test checks that after typing 203 * a correct date in the DateField the DateChooser will render 204 * it correctly. 205 * Using ThaiBuddhist chronology. 206 */ 207 @Test(timeout = 10000) 208 public void dateTypingThaiBuddhist() throws InterruptedException { 209 HashMap<String, String> expectedState = new HashMap<String, String>(3); 210 expectedState.put("selectedDay", "29"); 211 expectedState.put("monthName", "february"); 212 expectedState.put("year", "2555"); 213 checkTypedDate(Chronology.of("ThaiBuddhist"), expectedState, "2/29/2555 B.E."); 214 } 215 216 /** 217 * Test checks that after typing 218 * a correct date in the DateField the DateChooser will render 219 * it correctly. 220 * Using Japanese chronology. 221 */ 222 @Test(timeout = 10000) 223 public void dateTypingJapanese() throws InterruptedException { 224 HashMap<String, String> expectedState = new HashMap<String, String>(3); 225 expectedState.put("selectedDay", "29"); 226 expectedState.put("monthName", "february"); 227 expectedState.put("year", "Heisei24"); 228 checkTypedDate(Chronology.of("Japanese"), expectedState, "2/29/0024 H"); 229 } 230 231 /** 232 * Test checks that after typing 233 * a correct date in the DateField the DateChooser will render 234 * it correctly. 235 * Using Hijrah-umalqura chronology. 236 */ 237 @Test(timeout = 10000) 238 public void dateTypingHijrahUmalqura() throws InterruptedException { 239 HashMap<String, String> expectedState = new HashMap<String, String>(3); 240 expectedState.put("selectedDay", "29"); 241 expectedState.put("monthName", "february"); 242 expectedState.put("year", "2012"); 243 checkTypedDate(Chronology.of("Hijrah-umalqura"), expectedState, "4/7/1433 AH"); 244 } 245 246 public void checkTypedDate(Chronology chronology, HashMap<String, String> expectedState, String date) throws InterruptedException { 247 selectObjectFromChoiceBox(SettingType.SETTER, Properties.chronology, chronology); 248 TextInputControlDock in = new TextInputControlDock(testedControl.as(Parent.class, Node.class)); 249 in.type(date); 250 in.keyboard().pushKey(KeyboardButtons.ENTER); 251 waitShownText(date); 252 253 clickDropDownButton(); 254 waitPopupShowingState(true); 255 256 PopupSceneDescription description = new PopupSceneDescription(); 257 description.extractData(); 258 259 testedControl.waitState(new DateState(expectedState, description)); 260 //Close pop up 261 scene.mouse().click(1, new Point(2, 2)); 262 } 263 }