2103 |
11 Oct 07 |
olle |
1 |
/* |
2103 |
11 Oct 07 |
olle |
$Id$ |
2103 |
11 Oct 07 |
olle |
3 |
|
2103 |
11 Oct 07 |
olle |
Copyright (C) 2006, 2007 Gregory Vincic, Olle Mansson |
2103 |
11 Oct 07 |
olle |
5 |
|
2103 |
11 Oct 07 |
olle |
This file is part of Proteios. |
2103 |
11 Oct 07 |
olle |
Available at http://www.proteios.org/ |
2103 |
11 Oct 07 |
olle |
8 |
|
2103 |
11 Oct 07 |
olle |
Proteios is free software; you can redistribute it and/or modify it |
2103 |
11 Oct 07 |
olle |
under the terms of the GNU General Public License as published by |
2103 |
11 Oct 07 |
olle |
the Free Software Foundation; either version 2 of the License, or |
2103 |
11 Oct 07 |
olle |
(at your option) any later version. |
2103 |
11 Oct 07 |
olle |
13 |
|
2103 |
11 Oct 07 |
olle |
Proteios is distributed in the hope that it will be useful, but |
2103 |
11 Oct 07 |
olle |
WITHOUT ANY WARRANTY; without even the implied warranty of |
2103 |
11 Oct 07 |
olle |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2103 |
11 Oct 07 |
olle |
General Public License for more details. |
2103 |
11 Oct 07 |
olle |
18 |
|
2103 |
11 Oct 07 |
olle |
You should have received a copy of the GNU General Public License |
2103 |
11 Oct 07 |
olle |
along with this program; if not, write to the Free Software |
2103 |
11 Oct 07 |
olle |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
2103 |
11 Oct 07 |
olle |
02111-1307, USA. |
2103 |
11 Oct 07 |
olle |
23 |
*/ |
2103 |
11 Oct 07 |
olle |
24 |
package utilities; |
2103 |
11 Oct 07 |
olle |
25 |
|
2103 |
11 Oct 07 |
olle |
26 |
import org.proteios.PropertiesFile; |
2103 |
11 Oct 07 |
olle |
27 |
import org.proteios.core.Application; |
2103 |
11 Oct 07 |
olle |
28 |
import org.proteios.core.SessionControl; |
2103 |
11 Oct 07 |
olle |
29 |
import org.proteios.io.mzdata.MzDataImporter; |
2103 |
11 Oct 07 |
olle |
30 |
import org.xml.sax.SAXException; |
2103 |
11 Oct 07 |
olle |
31 |
|
2103 |
11 Oct 07 |
olle |
32 |
import java.net.URL; |
2103 |
11 Oct 07 |
olle |
33 |
|
2103 |
11 Oct 07 |
olle |
34 |
import javax.xml.stream.XMLStreamException; |
2103 |
11 Oct 07 |
olle |
35 |
|
2103 |
11 Oct 07 |
olle |
36 |
import junit.extensions.TestSetup; |
2103 |
11 Oct 07 |
olle |
37 |
import junit.framework.Test; |
2103 |
11 Oct 07 |
olle |
38 |
|
2103 |
11 Oct 07 |
olle |
39 |
/** |
2103 |
11 Oct 07 |
olle |
* This class performs setup operations that only should be |
2103 |
11 Oct 07 |
olle |
* performed once for all tests in a test suite containing tests |
2103 |
11 Oct 07 |
olle |
* of MzDataImporter items. The tests in this suite are part |
2103 |
11 Oct 07 |
olle |
* integration tests, and relies on a fixed mzData XML file to be |
2103 |
11 Oct 07 |
olle |
* imported. This import is performed by this class. |
2103 |
11 Oct 07 |
olle |
45 |
* |
2103 |
11 Oct 07 |
olle |
* @author Olle |
2103 |
11 Oct 07 |
olle |
* @version 2.0 |
2103 |
11 Oct 07 |
olle |
* @proteios.modified $Date$ |
2103 |
11 Oct 07 |
olle |
49 |
*/ |
2103 |
11 Oct 07 |
olle |
50 |
public class MzDataImpSetup |
2103 |
11 Oct 07 |
olle |
51 |
extends TestSetup |
2103 |
11 Oct 07 |
olle |
52 |
{ |
2103 |
11 Oct 07 |
olle |
53 |
private SessionControl sc = null; |
2103 |
11 Oct 07 |
olle |
54 |
private String testDataDirURLStr = null; |
2103 |
11 Oct 07 |
olle |
55 |
private URL testDataDirURL = null; |
2103 |
11 Oct 07 |
olle |
56 |
private String testDataDir = null; |
2103 |
11 Oct 07 |
olle |
57 |
private int peakListSetId; |
2103 |
11 Oct 07 |
olle |
58 |
|
2103 |
11 Oct 07 |
olle |
59 |
|
2103 |
11 Oct 07 |
olle |
60 |
/** |
2103 |
11 Oct 07 |
olle |
* Get the PeakListSetId for the PeakListSet |
2103 |
11 Oct 07 |
olle |
* created from the imported mzData file. |
2103 |
11 Oct 07 |
olle |
63 |
* |
2103 |
11 Oct 07 |
olle |
* @return id int id for the PeakListSet created from the mzdata file. |
2103 |
11 Oct 07 |
olle |
65 |
*/ |
2103 |
11 Oct 07 |
olle |
66 |
public int getPeakListSetId() |
2103 |
11 Oct 07 |
olle |
67 |
{ |
2103 |
11 Oct 07 |
olle |
68 |
return this.peakListSetId; |
2103 |
11 Oct 07 |
olle |
69 |
} |
2103 |
11 Oct 07 |
olle |
70 |
|
2103 |
11 Oct 07 |
olle |
71 |
/** |
2103 |
11 Oct 07 |
olle |
* Set the PeakListSetId for the PeakListSet |
2103 |
11 Oct 07 |
olle |
* created from the imported mzData file. |
2103 |
11 Oct 07 |
olle |
74 |
* |
2103 |
11 Oct 07 |
olle |
* @param peakListSetId int id for the PeakListSet created from the mzdata file. |
2103 |
11 Oct 07 |
olle |
76 |
*/ |
2103 |
11 Oct 07 |
olle |
77 |
public void setPeakListSetId(int peakListSetId) |
2103 |
11 Oct 07 |
olle |
78 |
{ |
2103 |
11 Oct 07 |
olle |
79 |
this.peakListSetId = peakListSetId; |
2103 |
11 Oct 07 |
olle |
80 |
} |
2103 |
11 Oct 07 |
olle |
81 |
|
2103 |
11 Oct 07 |
olle |
82 |
public MzDataImpSetup(Test suite) |
2103 |
11 Oct 07 |
olle |
83 |
{ |
2103 |
11 Oct 07 |
olle |
84 |
super(suite); |
2103 |
11 Oct 07 |
olle |
85 |
} |
2103 |
11 Oct 07 |
olle |
86 |
|
2103 |
11 Oct 07 |
olle |
87 |
protected void setUp() |
2103 |
11 Oct 07 |
olle |
88 |
throws Exception |
2103 |
11 Oct 07 |
olle |
89 |
{ |
2103 |
11 Oct 07 |
olle |
90 |
Application.start(); |
2103 |
11 Oct 07 |
olle |
91 |
SessionControl sc = null; |
2103 |
11 Oct 07 |
olle |
92 |
try |
2103 |
11 Oct 07 |
olle |
93 |
{ |
2103 |
11 Oct 07 |
olle |
94 |
sc = Application.getSessionControl("testSession", "test"); |
2103 |
11 Oct 07 |
olle |
95 |
} |
2103 |
11 Oct 07 |
olle |
96 |
catch (Exception e) |
2103 |
11 Oct 07 |
olle |
97 |
{ |
2103 |
11 Oct 07 |
olle |
//System.out.println("MzDataImpSetup:: setUp: Exception when getting session control: " + e); |
2103 |
11 Oct 07 |
olle |
99 |
sc = Application.newSessionControl("org.proteios.default", "test", "testSession"); |
2103 |
11 Oct 07 |
olle |
100 |
} |
2103 |
11 Oct 07 |
olle |
101 |
setSessionControl(sc); |
2103 |
11 Oct 07 |
olle |
//dc = sc.newDbControl(); |
2103 |
11 Oct 07 |
olle |
//if (dc == null) |
2103 |
11 Oct 07 |
olle |
104 |
//{ |
2103 |
11 Oct 07 |
olle |
// System.out.println("MzDataImpSetup:: setUp: dc == null"); |
2103 |
11 Oct 07 |
olle |
106 |
//} |
2103 |
11 Oct 07 |
olle |
107 |
/* |
2103 |
11 Oct 07 |
olle |
* Optional log in to Proteios as specific user. |
2103 |
11 Oct 07 |
olle |
109 |
* |
2103 |
11 Oct 07 |
olle |
* Note that if you log in here via sc.login(...) for |
2103 |
11 Oct 07 |
olle |
* SessionControl 'sc', you must log out via sc.logout() |
2103 |
11 Oct 07 |
olle |
* in method tearDown(), if you have more than one test, |
2103 |
11 Oct 07 |
olle |
* as otherwise you will get an error when setUp() tries |
2103 |
11 Oct 07 |
olle |
* to log in as the same user a second time. |
2103 |
11 Oct 07 |
olle |
115 |
*/ |
2103 |
11 Oct 07 |
olle |
116 |
/* |
2103 |
11 Oct 07 |
olle |
* We need to log in to Proteios in this case, as we want |
2103 |
11 Oct 07 |
olle |
* to import a given mzData XML file before performing the tests, |
2103 |
11 Oct 07 |
olle |
* and the import routine uses the logged in user to set |
2103 |
11 Oct 07 |
olle |
* ownership of imported items. |
2103 |
11 Oct 07 |
olle |
121 |
*/ |
2103 |
11 Oct 07 |
olle |
122 |
PropertiesFile pf = new PropertiesFile(); |
2103 |
11 Oct 07 |
olle |
123 |
sc.logout(); |
2103 |
11 Oct 07 |
olle |
124 |
sc.login(pf.getProperty("test.username"), pf.getProperty("test.password"), "", false); |
2103 |
11 Oct 07 |
olle |
125 |
/* |
2103 |
11 Oct 07 |
olle |
* Test-specific Initializations may be placed here. |
2103 |
11 Oct 07 |
olle |
127 |
*/ |
2103 |
11 Oct 07 |
olle |
128 |
testDataDirURLStr = pf.getProperty("test.data.url"); |
2103 |
11 Oct 07 |
olle |
129 |
/* |
2103 |
11 Oct 07 |
olle |
* Path to be used in tests taking |
2103 |
11 Oct 07 |
olle |
* a local path as argument. |
2103 |
11 Oct 07 |
olle |
132 |
*/ |
2103 |
11 Oct 07 |
olle |
133 |
testDataDir = null; |
2103 |
11 Oct 07 |
olle |
134 |
testDataDirURL = null; |
2103 |
11 Oct 07 |
olle |
135 |
testDataDirURL = new URL(testDataDirURLStr); |
2103 |
11 Oct 07 |
olle |
136 |
/* |
2103 |
11 Oct 07 |
olle |
* If the url String is a relative local path, |
2103 |
11 Oct 07 |
olle |
* creating a URL will expand the full path. |
2103 |
11 Oct 07 |
olle |
139 |
*/ |
2103 |
11 Oct 07 |
olle |
140 |
if (testDataDirURL != null && !testDataDirURL.toString().equals("") && testDataDirURL.toString().startsWith("file:")) |
2103 |
11 Oct 07 |
olle |
141 |
{ |
2103 |
11 Oct 07 |
olle |
142 |
/* |
2103 |
11 Oct 07 |
olle |
* Store full local path for use im tests |
2103 |
11 Oct 07 |
olle |
* taking a local path as argument. |
2103 |
11 Oct 07 |
olle |
145 |
*/ |
2103 |
11 Oct 07 |
olle |
146 |
testDataDir = testDataDirURL.getPath(); |
2103 |
11 Oct 07 |
olle |
147 |
} |
2103 |
11 Oct 07 |
olle |
//System.out.println(this.getClass().getSimpleName() + "::setUp() testDataDirURL = \"" + testDataDirURL + "\""); |
2103 |
11 Oct 07 |
olle |
//System.out.println(this.getClass().getSimpleName() + "::setUp() testDataDir = \"" + testDataDir + "\""); |
2103 |
11 Oct 07 |
olle |
150 |
/* |
2103 |
11 Oct 07 |
olle |
* Create an MzDataImporter, import mzData file |
2103 |
11 Oct 07 |
olle |
* with path 'testXmlFilePath', and get id for |
2103 |
11 Oct 07 |
olle |
* created PeakListSet. |
2103 |
11 Oct 07 |
olle |
154 |
*/ |
2103 |
11 Oct 07 |
olle |
155 |
MzDataImporter mzDataImporter = new MzDataImporter(sc); |
2103 |
11 Oct 07 |
olle |
156 |
try |
2103 |
11 Oct 07 |
olle |
157 |
{ |
2103 |
11 Oct 07 |
olle |
158 |
/* |
2103 |
11 Oct 07 |
olle |
* MzData file with path 'testXmlFilePath' should |
2103 |
11 Oct 07 |
olle |
* correspond to mzData file mzDataExtraBlocks.xml. |
2103 |
11 Oct 07 |
olle |
161 |
*/ |
2103 |
11 Oct 07 |
olle |
162 |
String testXmlFilePath = new String(testDataDir + "/mzData.xml"); |
2103 |
11 Oct 07 |
olle |
163 |
mzDataImporter.importFile(testXmlFilePath); |
2103 |
11 Oct 07 |
olle |
164 |
peakListSetId = mzDataImporter.getPeakListSet().getId(); |
2103 |
11 Oct 07 |
olle |
165 |
} catch (SAXException e) { |
2103 |
11 Oct 07 |
olle |
166 |
fail("MzDataImpSetup:: setUp(): importFile() throwed a SAXException for a valid mzData file."); |
2103 |
11 Oct 07 |
olle |
167 |
} catch (XMLStreamException e) { |
2103 |
11 Oct 07 |
olle |
168 |
fail("MzDataImpSetup:: setUp(): importFile() throwed an XMLStreamException for a valid mzData file."); |
2103 |
11 Oct 07 |
olle |
169 |
} |
2103 |
11 Oct 07 |
olle |
170 |
/* |
2103 |
11 Oct 07 |
olle |
* Log out from Proteios before the first test. |
2103 |
11 Oct 07 |
olle |
172 |
*/ |
2103 |
11 Oct 07 |
olle |
173 |
sc.logout(); |
2103 |
11 Oct 07 |
olle |
174 |
} |
2103 |
11 Oct 07 |
olle |
175 |
|
2103 |
11 Oct 07 |
olle |
176 |
|
2103 |
11 Oct 07 |
olle |
177 |
protected void tearDown() |
2103 |
11 Oct 07 |
olle |
178 |
throws Exception |
2103 |
11 Oct 07 |
olle |
179 |
{ |
2103 |
11 Oct 07 |
olle |
180 |
Application.stop(); |
2103 |
11 Oct 07 |
olle |
//dc.close(); |
2103 |
11 Oct 07 |
olle |
182 |
sc.logout(); |
2103 |
11 Oct 07 |
olle |
183 |
} |
2103 |
11 Oct 07 |
olle |
184 |
|
2103 |
11 Oct 07 |
olle |
185 |
|
2103 |
11 Oct 07 |
olle |
186 |
/** |
2103 |
11 Oct 07 |
olle |
* Get the SessionControl object. |
2103 |
11 Oct 07 |
olle |
188 |
* |
2103 |
11 Oct 07 |
olle |
* @return the SessionControl object |
2103 |
11 Oct 07 |
olle |
190 |
*/ |
2103 |
11 Oct 07 |
olle |
191 |
public SessionControl getSessionControl() |
2103 |
11 Oct 07 |
olle |
192 |
{ |
2103 |
11 Oct 07 |
olle |
193 |
return this.sc; |
2103 |
11 Oct 07 |
olle |
194 |
} |
2103 |
11 Oct 07 |
olle |
195 |
|
2103 |
11 Oct 07 |
olle |
196 |
/** |
2103 |
11 Oct 07 |
olle |
* Set the SessionControl object. |
2103 |
11 Oct 07 |
olle |
198 |
* |
2103 |
11 Oct 07 |
olle |
* @param sc the SessionControl object to set. |
2103 |
11 Oct 07 |
olle |
200 |
*/ |
2103 |
11 Oct 07 |
olle |
201 |
public void setSessionControl(SessionControl sc) |
2103 |
11 Oct 07 |
olle |
202 |
{ |
2103 |
11 Oct 07 |
olle |
203 |
this.sc = sc; |
2103 |
11 Oct 07 |
olle |
204 |
} |
2103 |
11 Oct 07 |
olle |
205 |
} |