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 
  26 package org.jemmy.env;
  27 
  28 import org.testng.annotations.AfterClass;
  29 import org.testng.annotations.AfterMethod;
  30 import org.testng.annotations.BeforeClass;
  31 import org.testng.annotations.BeforeMethod;
  32 import org.testng.annotations.Test;
  33 
  34 import static org.testng.Assert.assertEquals;
  35 import static org.testng.Assert.assertNotNull;
  36 
  37 /**
  38  *
  39  * @author shura
  40  */
  41 public class EnvironmentTest {
  42 
  43     /**
  44      *
  45      */
  46     public EnvironmentTest() {
  47     }
  48 
  49     /**
  50      *
  51      * @throws java.lang.Exception
  52      */
  53     @BeforeClass
  54     public static void setUpClass() throws Exception {
  55     }
  56 
  57     /**
  58      *
  59      * @throws java.lang.Exception
  60      */
  61     @AfterClass
  62     public static void tearDownClass() throws Exception {
  63     }
  64 
  65     Environment local;
  66 
  67     /**
  68      *
  69      */
  70     @BeforeMethod
  71     public void setUp() {
  72         Environment.getEnvironment().setTimeout(new Timeout("timeout", 1));
  73         local = new Environment(Environment.getEnvironment());
  74     }
  75 
  76     /**
  77      *
  78      */
  79     @AfterMethod
  80     public void tearDown() {
  81     }
  82 
  83     /**
  84      * Test of getEnvironment method, of class Environment.
  85      */
  86     @Test
  87     public void testGetEnvironment() {
  88         assertNotNull(Environment.getEnvironment());
  89         assertEquals(Environment.getEnvironment().getTimeout("timeout").getValue(), (long)1);
  90     }
  91 
  92     /**
  93      * Test of setEnvironmentIfNotSet method, of class Environment.
  94      */
  95     @Test
  96     public void testSetEnvironmentIfNotSet() {
  97         Environment parent = new Environment();
  98         parent.setPropertyIfNotSet(Boolean.class, false);
  99         assertEquals((boolean)parent.getProperty(Boolean.class), false);
 100 
 101         parent.setPropertyIfNotSet(Boolean.class, true);
 102         assertEquals((boolean)parent.getProperty(Boolean.class), false);
 103 
 104         Environment env = new Environment(parent);
 105         env.setPropertyIfNotSet(Boolean.class, true);
 106         assertEquals((boolean)env.getProperty(Boolean.class), false);
 107     }
 108 
 109     /**
 110      * Test of getParentEnvironment method, of class Environment.
 111      */
 112     @Test
 113     public void testGetParentEnvironment() {
 114         assertEquals((long)1, local.getTimeout("timeout").getValue());
 115     }
 116 
 117     /**
 118      *
 119      */
 120     @Test
 121     public void testPropByString() {
 122         Environment.getEnvironment().setProperty("some.property", this);
 123         assertEquals(local.getProperty("some.property"), this);
 124     }
 125 
 126     /**
 127      * Tests Environment.PropertyKey equals() and hashCode() functions.
 128      */
 129     @Test
 130     public void testKeyEqualsAndHashCode() {
 131         Object value = "value";
 132         Environment.getEnvironment().setProperty("testKeyEqualsAndHashCode", value);
 133         assertEquals(Environment.getEnvironment().setProperty("testKeyEqualsAndHashCode", this), value);
 134         assertEquals(Environment.getEnvironment().getProperty("testKeyEqualsAndHashCode"), this);
 135     }
 136 
 137     /**
 138      * Tests {@linkplain Environment#setTimeout(java.lang.String, long)} and
 139      * {@linkplain Environment#setTimeout(org.jemmy.env.Timeout, long) methods.
 140      */
 141     @Test
 142     public void testSetTimeout() {
 143         Timeout timeout = new Timeout("testSetTimeout", 100);
 144         Environment.getEnvironment().setTimeout(timeout.getName(), 200);
 145         assertEquals(Environment.getEnvironment().getTimeout(timeout.getName()).getValue(), 200l);
 146         assertEquals(Environment.getEnvironment().setTimeout(timeout, 300).getValue(), 200l);
 147         assertEquals(Environment.getEnvironment().getTimeout(timeout).getValue(), 300l);
 148     }
 149 
 150     // TODO: More tests on Environment
 151 
 152 /*
 153     @Test
 154     public void testSetParentEnvironment() {
 155         System.out.println("setParentEnvironment");
 156         Environment parent = null;
 157         Environment instance = new Environment();
 158         instance.setParentEnvironment(parent);
 159         // TODO review the generated test code and remove the default call to fail.
 160         fail("The test case is a prototype.");
 161     }
 162 
 163     @Test
 164     public void testGet() {
 165         System.out.println("get");
 166         Class cls = null;
 167         Environment instance = new Environment();
 168         List<T> expResult = null;
 169         List<T> result = instance.get(cls);
 170         assertEquals(expResult, result);
 171         // TODO review the generated test code and remove the default call to fail.
 172         fail("The test case is a prototype.");
 173     }
 174 
 175     @Test
 176     public void testSetLookupDriver() {
 177         System.out.println("setLookupDriver");
 178         LookupParent driver = null;
 179         Environment instance = new Environment();
 180         LookupParent expResult = null;
 181         LookupParent result = instance.setLookupDriver(driver);
 182         assertEquals(expResult, result);
 183         // TODO review the generated test code and remove the default call to fail.
 184         fail("The test case is a prototype.");
 185     }
 186 
 187     @Test
 188     public void testGetLookupDriver() {
 189         System.out.println("getLookupDriver");
 190         Environment instance = new Environment();
 191         LookupParent expResult = null;
 192         LookupParent result = instance.getLookupDriver();
 193         assertEquals(expResult, result);
 194         // TODO review the generated test code and remove the default call to fail.
 195         fail("The test case is a prototype.");
 196     }
 197 
 198     @Test
 199     public void testSetOutput() {
 200         System.out.println("setOutput");
 201         TestOut out = null;
 202         Environment instance = new Environment();
 203         TestOut expResult = null;
 204         TestOut result = instance.setOutput(out);
 205         assertEquals(expResult, result);
 206         // TODO review the generated test code and remove the default call to fail.
 207         fail("The test case is a prototype.");
 208     }
 209 
 210     @Test
 211     public void testGetOutput() {
 212         System.out.println("getOutput");
 213         Environment instance = new Environment();
 214         TestOut expResult = null;
 215         TestOut result = instance.getOutput();
 216         assertEquals(expResult, result);
 217         // TODO review the generated test code and remove the default call to fail.
 218         fail("The test case is a prototype.");
 219     }
 220 
 221     @Test
 222     public void testGetWaiter() {
 223         System.out.println("getWaiter");
 224         String timeoutName = "";
 225         Environment instance = new Environment();
 226         Waiter expResult = null;
 227         Waiter result = instance.getWaiter(timeoutName);
 228         assertEquals(expResult, result);
 229         // TODO review the generated test code and remove the default call to fail.
 230         fail("The test case is a prototype.");
 231     }
 232 
 233     @Test
 234     public void testGetTimeout() {
 235         System.out.println("getTimeout");
 236         String name = "";
 237         Environment instance = new Environment();
 238         Timeout expResult = null;
 239         Timeout result = instance.getTimeout(name);
 240         assertEquals(expResult, result);
 241         // TODO review the generated test code and remove the default call to fail.
 242         fail("The test case is a prototype.");
 243     }
 244 
 245     @Test
 246     public void testSetTimeout() {
 247         System.out.println("setTimeout");
 248         Timeout t = null;
 249         Environment instance = new Environment();
 250         Timeout expResult = null;
 251         Timeout result = instance.setTimeout(t);
 252         assertEquals(expResult, result);
 253         // TODO review the generated test code and remove the default call to fail.
 254         fail("The test case is a prototype.");
 255     }
 256 */
 257 }
 258