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