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 package org.jemmy.env; 24 25 import java.io.File; 26 import java.io.FileWriter; 27 import java.io.IOException; 28 import java.io.PrintWriter; 29 import org.jemmy.control.Wrap; 30 import org.jemmy.timing.Waiter; 31 import org.testng.annotations.AfterClass; 32 import org.testng.annotations.AfterMethod; 33 import org.testng.annotations.BeforeClass; 34 import org.testng.annotations.BeforeMethod; 35 import org.testng.annotations.Test; 36 37 import static org.testng.Assert.assertEquals; 38 39 /** 40 * 41 * @author shura 42 */ 43 public class LoadTimeoutsTest { 44 45 private static final String WEIRD_NAME = "weird.timeout.name"; 46 private static final long DELTA_VALUE = 333; 47 private static final long WAIT_VALUE = 444; 48 private static final long WEIRD_VALUE = 555; 49 50 public LoadTimeoutsTest() { 51 } 52 53 @BeforeClass 54 public static void setUpClass() throws IOException { 55 createFiles(false); 56 } 57 public static void createFiles(boolean relative) throws IOException { 58 File timeouts = File.createTempFile("timeouts", "timeouts"); 59 PrintWriter out = new PrintWriter(new FileWriter(timeouts)); 60 out.println("default.wait.delta=" + DELTA_VALUE); 61 out.println("wait.state=" + WAIT_VALUE); 62 out.println(WEIRD_NAME + "=" + WEIRD_VALUE); 63 out.close(); 64 File properties = File.createTempFile("properties", "properties"); 65 out = new PrintWriter(new FileWriter(properties)); 66 out.println("timeouts=" + (relative ? timeouts.getName() : timeouts.getAbsolutePath())); 67 System.out.println("timeouts=" + (relative ? timeouts.getName() : timeouts.getAbsolutePath())); 68 out.close(); 69 // System.setProperty("jemmy.properties", properties.getAbsolutePath()); 70 // System.out.println("jemmy.properties=" + properties.getAbsolutePath()); 71 Environment.getEnvironment().loadProperties(properties.getAbsolutePath()); 72 } 73 74 @AfterClass 75 public static void tearDownClass() { 76 } 77 78 @BeforeMethod 79 public void setUp() { 80 } 81 82 @AfterMethod 83 public void tearDown() { 84 } 85 86 @Test() 87 public void testTimeouts() { 88 assertEquals(Environment.getEnvironment().getTimeout(WEIRD_NAME).getValue(), WEIRD_VALUE); 89 assertEquals(Environment.getEnvironment().getTimeout(Waiter.DEFAULT_DELTA).getValue(), DELTA_VALUE); 90 assertEquals(Environment.getEnvironment().getTimeout(Wrap.WAIT_STATE_TIMEOUT).getValue(), WAIT_VALUE); 91 } 92 93 }