3468 |
08 Jun 07 |
nicklas |
1 |
/* |
3468 |
08 Jun 07 |
nicklas |
$Id$ |
3468 |
08 Jun 07 |
nicklas |
3 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2007 Nicklas Nordborg |
3468 |
08 Jun 07 |
nicklas |
5 |
|
3468 |
08 Jun 07 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
3468 |
08 Jun 07 |
nicklas |
Available at http://base.thep.lu.se/ |
3468 |
08 Jun 07 |
nicklas |
8 |
|
3468 |
08 Jun 07 |
nicklas |
BASE is free software; you can redistribute it and/or |
3468 |
08 Jun 07 |
nicklas |
modify it under the terms of the GNU General Public License |
4480 |
05 Sep 08 |
jari |
as published by the Free Software Foundation; either version 3 |
3468 |
08 Jun 07 |
nicklas |
of the License, or (at your option) any later version. |
3468 |
08 Jun 07 |
nicklas |
13 |
|
3468 |
08 Jun 07 |
nicklas |
BASE is distributed in the hope that it will be useful, |
3468 |
08 Jun 07 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
3468 |
08 Jun 07 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3468 |
08 Jun 07 |
nicklas |
GNU General Public License for more details. |
3468 |
08 Jun 07 |
nicklas |
18 |
|
3468 |
08 Jun 07 |
nicklas |
You should have received a copy of the GNU General Public License |
4514 |
11 Sep 08 |
jari |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
3468 |
08 Jun 07 |
nicklas |
21 |
*/ |
3468 |
08 Jun 07 |
nicklas |
22 |
import net.sf.basedb.core.*; |
3472 |
11 Jun 07 |
nicklas |
23 |
import net.sf.basedb.core.query.Aggregations; |
3472 |
11 Jun 07 |
nicklas |
24 |
import net.sf.basedb.core.query.Dynamic; |
3472 |
11 Jun 07 |
nicklas |
25 |
import net.sf.basedb.core.query.Expression; |
3472 |
11 Jun 07 |
nicklas |
26 |
import net.sf.basedb.core.query.Selects; |
3472 |
11 Jun 07 |
nicklas |
27 |
import net.sf.basedb.core.query.SqlResult; |
3468 |
08 Jun 07 |
nicklas |
28 |
|
3468 |
08 Jun 07 |
nicklas |
29 |
public class TestDirty |
3468 |
08 Jun 07 |
nicklas |
30 |
{ |
3468 |
08 Jun 07 |
nicklas |
31 |
static boolean ok = true; |
3468 |
08 Jun 07 |
nicklas |
32 |
|
3468 |
08 Jun 07 |
nicklas |
33 |
public static void main(String[] args) |
3468 |
08 Jun 07 |
nicklas |
34 |
{ |
3468 |
08 Jun 07 |
nicklas |
35 |
TestUtil.checkArgs(args); |
3468 |
08 Jun 07 |
nicklas |
36 |
TestUtil.begin(); |
3468 |
08 Jun 07 |
nicklas |
37 |
ok = test_all(); |
3468 |
08 Jun 07 |
nicklas |
38 |
TestUtil.stop(); |
3468 |
08 Jun 07 |
nicklas |
39 |
} |
3468 |
08 Jun 07 |
nicklas |
40 |
|
3468 |
08 Jun 07 |
nicklas |
41 |
static boolean test_all() |
3468 |
08 Jun 07 |
nicklas |
42 |
{ |
3468 |
08 Jun 07 |
nicklas |
43 |
write("++Testing import of dirty data"); |
3468 |
08 Jun 07 |
nicklas |
44 |
boolean caseInsensitive = HibernateUtil.getDbEngine().caseInsensitiveComparison(); |
3468 |
08 Jun 07 |
nicklas |
45 |
write("--case insensitive = " + caseInsensitive); |
3468 |
08 Jun 07 |
nicklas |
46 |
|
3468 |
08 Jun 07 |
nicklas |
// Tests for checking case sensitivity and white space truncation |
3626 |
03 Aug 07 |
nicklas |
48 |
TestReporter.test_import_from_file("data/test.import.dirty.txt", "\"Block\"\\t\"Column\"\\t\"Row\"\\t\"Name\"\\t\"ID\".*", "\\t", 4, 3); |
3468 |
08 Jun 07 |
nicklas |
49 |
|
3468 |
08 Jun 07 |
nicklas |
// If DB is case sensitive the two reporters should be different |
3468 |
08 Jun 07 |
nicklas |
51 |
int id1 = TestReporter.test_externalId("demoblank"); |
3468 |
08 Jun 07 |
nicklas |
52 |
int id2= TestReporter.test_externalId("demoBLANK"); |
3468 |
08 Jun 07 |
nicklas |
53 |
if (caseInsensitive) |
3468 |
08 Jun 07 |
nicklas |
54 |
{ |
3468 |
08 Jun 07 |
nicklas |
55 |
write("--demoblank == demoBLANK " + (id1 == id2 ? "OK" : "FAILED")); |
3471 |
11 Jun 07 |
nicklas |
56 |
ok = ok && (id1 == id2); |
3468 |
08 Jun 07 |
nicklas |
57 |
} |
3468 |
08 Jun 07 |
nicklas |
58 |
else |
3468 |
08 Jun 07 |
nicklas |
59 |
{ |
3468 |
08 Jun 07 |
nicklas |
60 |
write("--demoblank != demoBLANK " + (id1 != id2 ? "OK" : "FAILED")); |
3471 |
11 Jun 07 |
nicklas |
61 |
ok = ok && (id1 != id2); |
3468 |
08 Jun 07 |
nicklas |
62 |
} |
3468 |
08 Jun 07 |
nicklas |
63 |
|
3468 |
08 Jun 07 |
nicklas |
// Check that white space has been trimmed |
3471 |
11 Jun 07 |
nicklas |
65 |
int id3 = TestReporter.test_externalId("demoB"); |
3471 |
11 Jun 07 |
nicklas |
66 |
int id4 = TestReporter.test_externalId("demoB "); |
3471 |
11 Jun 07 |
nicklas |
67 |
write("--demoB == demoB<space> " + (id3 == id4 ? "OK" : "FAILED")); |
3471 |
11 Jun 07 |
nicklas |
68 |
ok = ok && (id3 == id4); |
3468 |
08 Jun 07 |
nicklas |
69 |
|
3633 |
06 Aug 07 |
nicklas |
70 |
ok = ok && TestReporter.test_list(caseInsensitive ? 3 : 4); |
3471 |
11 Jun 07 |
nicklas |
71 |
|
3468 |
08 Jun 07 |
nicklas |
// Test import raw data |
3820 |
12 Oct 07 |
nicklas |
73 |
int arrayDesignId = TestArrayDesign.test_create(Platform.GENERIC, false); |
3468 |
08 Jun 07 |
nicklas |
74 |
TestArrayDesign.test_import_from_file(arrayDesignId, "data/test.import.dirty.txt", |
4246 |
24 Apr 08 |
nicklas |
75 |
"\"Block\"\\t\"Column\"\\t\"Row\"\\t\"Name\"\\t\"ID\".*", null, 0, 2, 1, 4); |
3468 |
08 Jun 07 |
nicklas |
76 |
|
5748 |
19 Sep 11 |
nicklas |
77 |
int rawBioAssayId = TestRawBioAssay.test_create(Platform.GENERIC, "genepix", null, 0, 0, 0, 0, arrayDesignId, false); |
3719 |
12 Sep 07 |
nicklas |
78 |
int fileId = TestFile.test_create("data/test.import.dirty.txt", false, false); |
3468 |
08 Jun 07 |
nicklas |
79 |
|
3468 |
08 Jun 07 |
nicklas |
80 |
int pluginDefinitionId = TestPluginDefinition.test_get("net.sf.basedb.plugins.RawDataFlatFileImporter"); |
3468 |
08 Jun 07 |
nicklas |
81 |
int pluginConfigurationId = TestRawDataFlatFileImporter.test_create_configuration(pluginDefinitionId); |
3468 |
08 Jun 07 |
nicklas |
82 |
int jobId = TestRawDataFlatFileImporter.test_create_job(pluginConfigurationId, rawBioAssayId, fileId); |
5319 |
20 Apr 10 |
nicklas |
83 |
ok = ok && TestJob.test_execute(jobId, false); |
3471 |
11 Jun 07 |
nicklas |
84 |
ok = ok && TestRawBioAssay.test_list_raw_data(rawBioAssayId, 0, 0, 5, false); |
3472 |
11 Jun 07 |
nicklas |
85 |
test_sum_count(rawBioAssayId, "x", 9920f, 5); |
3472 |
11 Jun 07 |
nicklas |
86 |
test_sum_count(rawBioAssayId, "y", 22930f, 4); |
3666 |
14 Aug 07 |
nicklas |
87 |
test_sum_count(rawBioAssayId, "diameter", 240f, 4); |
3468 |
08 Jun 07 |
nicklas |
88 |
|
3468 |
08 Jun 07 |
nicklas |
89 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
4256 |
29 Apr 08 |
nicklas |
90 |
TestRawBioAssay.test_delete(rawBioAssayId); |
4256 |
29 Apr 08 |
nicklas |
91 |
TestArrayDesign.test_delete(arrayDesignId); |
3468 |
08 Jun 07 |
nicklas |
92 |
TestJob.test_delete(jobId); |
3468 |
08 Jun 07 |
nicklas |
93 |
TestPluginConfiguration.test_delete(pluginConfigurationId); |
3820 |
12 Oct 07 |
nicklas |
94 |
TestFile.test_delete(fileId); |
3468 |
08 Jun 07 |
nicklas |
95 |
TestReporter.test_delete(); |
3468 |
08 Jun 07 |
nicklas |
96 |
write("++Testing import of dirty data "+(ok ? "OK" : "Failed")+"\n"); |
3468 |
08 Jun 07 |
nicklas |
97 |
return ok; |
3468 |
08 Jun 07 |
nicklas |
98 |
} |
3468 |
08 Jun 07 |
nicklas |
99 |
|
3468 |
08 Jun 07 |
nicklas |
100 |
static void write(String message) |
3468 |
08 Jun 07 |
nicklas |
101 |
{ |
3468 |
08 Jun 07 |
nicklas |
102 |
System.out.println(message); |
3468 |
08 Jun 07 |
nicklas |
103 |
} |
3468 |
08 Jun 07 |
nicklas |
104 |
|
3472 |
11 Jun 07 |
nicklas |
105 |
static void test_sum_count(int rawBioAssayId, String property, float expectedSum, int expectedCount) |
3472 |
11 Jun 07 |
nicklas |
106 |
{ |
3472 |
11 Jun 07 |
nicklas |
107 |
if (rawBioAssayId == 0) return; |
3472 |
11 Jun 07 |
nicklas |
108 |
DbControl dc = null; |
3472 |
11 Jun 07 |
nicklas |
109 |
try |
3472 |
11 Jun 07 |
nicklas |
110 |
{ |
3472 |
11 Jun 07 |
nicklas |
111 |
dc = TestUtil.getDbControl(); |
3472 |
11 Jun 07 |
nicklas |
112 |
Expression rawExpression = Dynamic.rawData(property); |
3472 |
11 Jun 07 |
nicklas |
113 |
RawBioAssay rba = RawBioAssay.getById(dc, rawBioAssayId); |
3472 |
11 Jun 07 |
nicklas |
114 |
DynamicRawDataQuery query = rba.getDynamicRawData(); |
3472 |
11 Jun 07 |
nicklas |
115 |
query.select(Selects.expression(Aggregations.sum(rawExpression), "s")); |
3472 |
11 Jun 07 |
nicklas |
116 |
query.select(Selects.expression(Aggregations.count(rawExpression, false), "c")); |
3472 |
11 Jun 07 |
nicklas |
117 |
|
3472 |
11 Jun 07 |
nicklas |
118 |
DynamicResultIterator iterator = query.iterate(dc); |
3472 |
11 Jun 07 |
nicklas |
119 |
SqlResult result = iterator.next(); |
3472 |
11 Jun 07 |
nicklas |
120 |
|
3472 |
11 Jun 07 |
nicklas |
121 |
float sum = result.getFloat(1); |
3472 |
11 Jun 07 |
nicklas |
122 |
int count = result.getInt(2); |
3472 |
11 Jun 07 |
nicklas |
123 |
|
3666 |
14 Aug 07 |
nicklas |
124 |
if (Math.abs(expectedSum - sum) > 0.1) |
3472 |
11 Jun 07 |
nicklas |
125 |
{ |
3472 |
11 Jun 07 |
nicklas |
126 |
throw new Exception("Unexpected sum for '"+property+"': " + sum +"; expected " +expectedSum); |
3472 |
11 Jun 07 |
nicklas |
127 |
} |
3472 |
11 Jun 07 |
nicklas |
128 |
if (expectedCount != count) |
3472 |
11 Jun 07 |
nicklas |
129 |
{ |
3472 |
11 Jun 07 |
nicklas |
130 |
throw new Exception("Unexpected count for '"+property+"': " + count +"; expected " +expectedCount); |
3472 |
11 Jun 07 |
nicklas |
131 |
} |
3472 |
11 Jun 07 |
nicklas |
132 |
write("--Test sum and count for '" + property + "' OK (sum=" + sum + "; count="+ count +")"); |
3472 |
11 Jun 07 |
nicklas |
133 |
} |
3472 |
11 Jun 07 |
nicklas |
134 |
catch (Throwable ex) |
3472 |
11 Jun 07 |
nicklas |
135 |
{ |
3472 |
11 Jun 07 |
nicklas |
136 |
write("--Test sum and count FAILED"); |
3472 |
11 Jun 07 |
nicklas |
137 |
ex.printStackTrace(); |
3472 |
11 Jun 07 |
nicklas |
138 |
ok = false; |
3472 |
11 Jun 07 |
nicklas |
139 |
} |
3472 |
11 Jun 07 |
nicklas |
140 |
finally |
3472 |
11 Jun 07 |
nicklas |
141 |
{ |
3472 |
11 Jun 07 |
nicklas |
142 |
if (dc != null) dc.close(); |
3472 |
11 Jun 07 |
nicklas |
143 |
} |
3472 |
11 Jun 07 |
nicklas |
144 |
} |
3472 |
11 Jun 07 |
nicklas |
145 |
|
3468 |
08 Jun 07 |
nicklas |
146 |
} |
3468 |
08 Jun 07 |
nicklas |
147 |
|