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