1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package lib; 25cdf0e10cSrcweir import com.sun.star.uno.XInterface; 26cdf0e10cSrcweir 27cdf0e10cSrcweir import java.util.Hashtable; 28cdf0e10cSrcweir 29cdf0e10cSrcweir 30cdf0e10cSrcweir /** 31cdf0e10cSrcweir * The class contains an instance of a given implementation object and 32cdf0e10cSrcweir * auxiliary objects associated with it and required for the object testing. 33cdf0e10cSrcweir * 34cdf0e10cSrcweir * @see TestCase 35cdf0e10cSrcweir */ 36cdf0e10cSrcweir 37cdf0e10cSrcweir public final class TestEnvironment { 38cdf0e10cSrcweir /** 39cdf0e10cSrcweir * Contains object relations - auxiliary objects associated with the 40cdf0e10cSrcweir * tested object and required for testing. 41cdf0e10cSrcweir */ 42cdf0e10cSrcweir private final Hashtable relations = new Hashtable(10); 43cdf0e10cSrcweir 44cdf0e10cSrcweir /** 45cdf0e10cSrcweir * An instance of the tested implementation object. 46cdf0e10cSrcweir */ 47cdf0e10cSrcweir private final XInterface testObject; 48cdf0e10cSrcweir 49cdf0e10cSrcweir /** 50cdf0e10cSrcweir * Indicates that the testObject is in invalid state and should notbe 51cdf0e10cSrcweir * used for testing anymore. 52cdf0e10cSrcweir */ 53cdf0e10cSrcweir private boolean disposed = false; 54cdf0e10cSrcweir 55cdf0e10cSrcweir /** 56cdf0e10cSrcweir * A reference to TestCase which has created the test environment. 57cdf0e10cSrcweir */ 58cdf0e10cSrcweir private TestCase tCase; 59cdf0e10cSrcweir 60cdf0e10cSrcweir /** 61cdf0e10cSrcweir * Creates an instance of test environment with testObject. 62cdf0e10cSrcweir * 63cdf0e10cSrcweir * @param testObject object to test 64cdf0e10cSrcweir * 65cdf0e10cSrcweir * @throws java.lang.IllegalArgumentException if the testObject is 66cdf0e10cSrcweir * <tt>null</tt>. 67cdf0e10cSrcweir */ TestEnvironment( XInterface testObject )68cdf0e10cSrcweir public TestEnvironment( XInterface testObject ) { 69cdf0e10cSrcweir if (testObject == null) { 70cdf0e10cSrcweir throw new IllegalArgumentException( 71cdf0e10cSrcweir "Couldn't create a test object"); 72cdf0e10cSrcweir } 73cdf0e10cSrcweir this.testObject = testObject; 74cdf0e10cSrcweir } 75cdf0e10cSrcweir 76cdf0e10cSrcweir /** 77cdf0e10cSrcweir * @return the object to test. 78cdf0e10cSrcweir */ getTestObject()79cdf0e10cSrcweir public XInterface getTestObject() { 80cdf0e10cSrcweir return testObject; 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir /** 84cdf0e10cSrcweir * Adds to the environment an auxiliary object required for testing. 85cdf0e10cSrcweir * 86cdf0e10cSrcweir * @param name a name to reference the auxiliary object 87cdf0e10cSrcweir * 88cdf0e10cSrcweir * @param relation the auxiliary object related to the tested one 89cdf0e10cSrcweir */ addObjRelation( String name, Object relation)90cdf0e10cSrcweir public void addObjRelation( String name, Object relation) { 91cdf0e10cSrcweir relations.put( name, relation ); 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir /** 95cdf0e10cSrcweir * Returns an auxiliary object referenced by tname. 96cdf0e10cSrcweir * 97cdf0e10cSrcweir * @param name a name of the object relation 98cdf0e10cSrcweir * 99cdf0e10cSrcweir * @return the auxiliary object(object relation) 100cdf0e10cSrcweir */ getObjRelation( String name )101cdf0e10cSrcweir public Object getObjRelation( String name ) { 102cdf0e10cSrcweir return relations.get( name ); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir /** 106cdf0e10cSrcweir * Checks if an auxiliary object has been registered with name 107cdf0e10cSrcweir * 108cdf0e10cSrcweir * @param name a name referencing an auxiliarx object 109cdf0e10cSrcweir * 110cdf0e10cSrcweir * @return <tt>true</tt> if the object has been associated, <tt>false</tt> 111cdf0e10cSrcweir * otherwise. 112cdf0e10cSrcweir */ hasObjRelation(String name)113cdf0e10cSrcweir public boolean hasObjRelation(String name) { 114cdf0e10cSrcweir return (relations.get(name) != null) ; 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir /** 118cdf0e10cSrcweir * Sets the <code>TestCase</code> that created the environment. 119cdf0e10cSrcweir */ setTestCase( TestCase tCase)120cdf0e10cSrcweir public void setTestCase( TestCase tCase) { 121cdf0e10cSrcweir this.tCase = tCase; 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir /** 125cdf0e10cSrcweir * @return the <code>TestCase</code> created the environment. 126cdf0e10cSrcweir */ getTestCase()127cdf0e10cSrcweir public TestCase getTestCase() { 128cdf0e10cSrcweir return tCase; 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir /** 132cdf0e10cSrcweir * Makes the environment invalid, i.e. it should not be used for 133cdf0e10cSrcweir * testing anymore. 134cdf0e10cSrcweir */ dispose()135cdf0e10cSrcweir public void dispose() { 136cdf0e10cSrcweir disposed = true; 137cdf0e10cSrcweir } 138cdf0e10cSrcweir 139cdf0e10cSrcweir /** 140cdf0e10cSrcweir * Checks if the environment has been disposed. 141cdf0e10cSrcweir * 142cdf0e10cSrcweir * @return <tt>true</tt< if it has been disposed, <tt>false</tt> otherwise. 143cdf0e10cSrcweir * 144cdf0e10cSrcweir * @see #dispose() 145cdf0e10cSrcweir */ isDisposed()146cdf0e10cSrcweir public boolean isDisposed() { 147cdf0e10cSrcweir return disposed; 148cdf0e10cSrcweir } 149cdf0e10cSrcweir }