api/core/test/src/utilities/ApplicationSetup.java

Code
Comments
Other
Rev Date Author Line
2101 11 Oct 07 olle 1 /*
2101 11 Oct 07 olle 2  $Id$
2101 11 Oct 07 olle 3
2101 11 Oct 07 olle 4  Copyright (C) 2006 Gregory Vincic, Olle Mansson
2101 11 Oct 07 olle 5  Copyright (C) 2007 Olle Mansson
2101 11 Oct 07 olle 6
2101 11 Oct 07 olle 7  This file is part of Proteios.
2101 11 Oct 07 olle 8  Available at http://www.proteios.org/
2101 11 Oct 07 olle 9
2101 11 Oct 07 olle 10  Proteios is free software; you can redistribute it and/or modify it
2101 11 Oct 07 olle 11  under the terms of the GNU General Public License as published by
2101 11 Oct 07 olle 12  the Free Software Foundation; either version 2 of the License, or
2101 11 Oct 07 olle 13  (at your option) any later version.
2101 11 Oct 07 olle 14
2101 11 Oct 07 olle 15  Proteios is distributed in the hope that it will be useful, but
2101 11 Oct 07 olle 16  WITHOUT ANY WARRANTY; without even the implied warranty of
2101 11 Oct 07 olle 17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
2101 11 Oct 07 olle 18  General Public License for more details.
2101 11 Oct 07 olle 19
2101 11 Oct 07 olle 20  You should have received a copy of the GNU General Public License
2101 11 Oct 07 olle 21  along with this program; if not, write to the Free Software
2101 11 Oct 07 olle 22  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
2101 11 Oct 07 olle 23  02111-1307, USA.
2101 11 Oct 07 olle 24  */
2101 11 Oct 07 olle 25 package utilities;
2101 11 Oct 07 olle 26
2101 11 Oct 07 olle 27 //import org.proteios.PropertiesFile;
2101 11 Oct 07 olle 28 import org.proteios.core.Application;
2101 11 Oct 07 olle 29 import org.proteios.core.SessionControl;
2101 11 Oct 07 olle 30 import junit.extensions.TestSetup;
2101 11 Oct 07 olle 31 import junit.framework.Test;
2101 11 Oct 07 olle 32
2101 11 Oct 07 olle 33 /**
2101 11 Oct 07 olle 34  * This class performs setup operations that only should be
2101 11 Oct 07 olle 35  * performed once for all tests in a test suite containing tests
2101 11 Oct 07 olle 36  * of Proteios items. Method Application.start() is called before
2101 11 Oct 07 olle 37  * the first test, and Application.stop() after the last test.
2101 11 Oct 07 olle 38  * 
2101 11 Oct 07 olle 39  * @author Olle
2101 11 Oct 07 olle 40  * @version 2.0
2101 11 Oct 07 olle 41  * @proteios.modified $Date$
2101 11 Oct 07 olle 42  */
2101 11 Oct 07 olle 43 public class ApplicationSetup
2101 11 Oct 07 olle 44     extends TestSetup
2101 11 Oct 07 olle 45 {
2101 11 Oct 07 olle 46   private SessionControl sc = null;
2101 11 Oct 07 olle 47
2101 11 Oct 07 olle 48   public ApplicationSetup(Test suite)
2101 11 Oct 07 olle 49   {
2101 11 Oct 07 olle 50     super(suite);
2101 11 Oct 07 olle 51   }
2101 11 Oct 07 olle 52
2101 11 Oct 07 olle 53   protected void setUp()
2101 11 Oct 07 olle 54       throws Exception
2101 11 Oct 07 olle 55   {
2101 11 Oct 07 olle 56     Application.start();
2101 11 Oct 07 olle 57     SessionControl sc = null;
2101 11 Oct 07 olle 58     try
2101 11 Oct 07 olle 59     {
2101 11 Oct 07 olle 60       sc = Application.getSessionControl("testSession", "test");
2101 11 Oct 07 olle 61     }
2101 11 Oct 07 olle 62     catch (Exception e)
2101 11 Oct 07 olle 63     {
2101 11 Oct 07 olle 64       //System.out.println("ApplicationSetup:: setUp: Exception when getting session control: " + e);
2101 11 Oct 07 olle 65       sc = Application.newSessionControl("org.proteios.default", "test", "testSession");
2101 11 Oct 07 olle 66     }
2101 11 Oct 07 olle 67     setSessionControl(sc);
2101 11 Oct 07 olle 68     /*
2101 11 Oct 07 olle 69      * Optional - log in to Proteios
2101 11 Oct 07 olle 70      */
2101 11 Oct 07 olle 71     //PropertiesFile pf = new PropertiesFile();
2101 11 Oct 07 olle 72     //sc.login(pf.getProperty("test.username"), pf.getProperty("test.password"), "", false);
2101 11 Oct 07 olle 73   }
2101 11 Oct 07 olle 74
2101 11 Oct 07 olle 75
2101 11 Oct 07 olle 76   protected void tearDown()
2101 11 Oct 07 olle 77       throws Exception
2101 11 Oct 07 olle 78   {
2101 11 Oct 07 olle 79     Application.stop();
2101 11 Oct 07 olle 80     //sc.logout();
2101 11 Oct 07 olle 81   }
2101 11 Oct 07 olle 82
2101 11 Oct 07 olle 83   /**
2101 11 Oct 07 olle 84    * Get the SessionControl object.
2101 11 Oct 07 olle 85    * 
2101 11 Oct 07 olle 86    * @return the SessionControl object
2101 11 Oct 07 olle 87    */
2101 11 Oct 07 olle 88   public SessionControl getSessionControl()
2101 11 Oct 07 olle 89   {
2101 11 Oct 07 olle 90     return this.sc;
2101 11 Oct 07 olle 91   }
2101 11 Oct 07 olle 92
2101 11 Oct 07 olle 93   /**
2101 11 Oct 07 olle 94    * Set the SessionControl object.
2101 11 Oct 07 olle 95    * 
2101 11 Oct 07 olle 96    * @param sc the SessionControl object to set.
2101 11 Oct 07 olle 97    */
2101 11 Oct 07 olle 98   public void setSessionControl(SessionControl sc)
2101 11 Oct 07 olle 99   {
2101 11 Oct 07 olle 100     this.sc = sc;
2101 11 Oct 07 olle 101   }
2101 11 Oct 07 olle 102 }