5876 |
15 Nov 11 |
nicklas |
1 |
/* |
5876 |
15 Nov 11 |
nicklas |
$Id $ |
5876 |
15 Nov 11 |
nicklas |
3 |
|
5876 |
15 Nov 11 |
nicklas |
Copyright (C) 2011 Nicklas Nordborg |
5876 |
15 Nov 11 |
nicklas |
5 |
|
5876 |
15 Nov 11 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
5876 |
15 Nov 11 |
nicklas |
Available at http://base.thep.lu.se/ |
5876 |
15 Nov 11 |
nicklas |
8 |
|
5876 |
15 Nov 11 |
nicklas |
BASE is free software; you can redistribute it and/or |
5876 |
15 Nov 11 |
nicklas |
modify it under the terms of the GNU General Public License |
5876 |
15 Nov 11 |
nicklas |
as published by the Free Software Foundation; either version 3 |
5876 |
15 Nov 11 |
nicklas |
of the License, or (at your option) any later version. |
5876 |
15 Nov 11 |
nicklas |
13 |
|
5876 |
15 Nov 11 |
nicklas |
BASE is distributed in the hope that it will be useful, |
5876 |
15 Nov 11 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5876 |
15 Nov 11 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5876 |
15 Nov 11 |
nicklas |
GNU General Public License for more details. |
5876 |
15 Nov 11 |
nicklas |
18 |
|
5876 |
15 Nov 11 |
nicklas |
You should have received a copy of the GNU General Public License |
5876 |
15 Nov 11 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5876 |
15 Nov 11 |
nicklas |
21 |
*/ |
5876 |
15 Nov 11 |
nicklas |
22 |
|
5876 |
15 Nov 11 |
nicklas |
23 |
import net.sf.basedb.core.BaseException; |
5885 |
22 Nov 11 |
nicklas |
24 |
import net.sf.basedb.core.ClonableProperty; |
5876 |
15 Nov 11 |
nicklas |
25 |
import net.sf.basedb.core.DbControl; |
5886 |
23 Nov 11 |
nicklas |
26 |
import net.sf.basedb.core.DynamicReporterQuery; |
5886 |
23 Nov 11 |
nicklas |
27 |
import net.sf.basedb.core.DynamicResultIterator; |
5876 |
15 Nov 11 |
nicklas |
28 |
import net.sf.basedb.core.Experiment; |
5876 |
15 Nov 11 |
nicklas |
29 |
import net.sf.basedb.core.ExtendedProperties; |
5876 |
15 Nov 11 |
nicklas |
30 |
import net.sf.basedb.core.ExtendedProperty; |
5876 |
15 Nov 11 |
nicklas |
31 |
import net.sf.basedb.core.Item; |
5876 |
15 Nov 11 |
nicklas |
32 |
import net.sf.basedb.core.ItemProxy; |
5876 |
15 Nov 11 |
nicklas |
33 |
import net.sf.basedb.core.ItemResultList; |
5876 |
15 Nov 11 |
nicklas |
34 |
import net.sf.basedb.core.Permission; |
5886 |
23 Nov 11 |
nicklas |
35 |
import net.sf.basedb.core.Reporter; |
5877 |
16 Nov 11 |
nicklas |
36 |
import net.sf.basedb.core.ReporterCloneBatcher; |
5876 |
15 Nov 11 |
nicklas |
37 |
import net.sf.basedb.core.ReporterCloneTemplate; |
5886 |
23 Nov 11 |
nicklas |
38 |
import net.sf.basedb.core.ReporterCloneBatcher.CloneSource; |
7381 |
22 May 17 |
nicklas |
39 |
import net.sf.basedb.core.data.ReporterData; |
5886 |
23 Nov 11 |
nicklas |
40 |
import net.sf.basedb.core.query.Dynamic; |
5886 |
23 Nov 11 |
nicklas |
41 |
import net.sf.basedb.core.query.SqlResult; |
5876 |
15 Nov 11 |
nicklas |
42 |
import net.sf.basedb.util.ConsoleProgressReporter; |
5876 |
15 Nov 11 |
nicklas |
43 |
|
5876 |
15 Nov 11 |
nicklas |
44 |
import java.util.Date; |
5876 |
15 Nov 11 |
nicklas |
45 |
import java.util.List; |
5876 |
15 Nov 11 |
nicklas |
46 |
import java.util.Set; |
5876 |
15 Nov 11 |
nicklas |
47 |
|
5876 |
15 Nov 11 |
nicklas |
48 |
public class TestReporterCloneTemplate |
5876 |
15 Nov 11 |
nicklas |
49 |
{ |
5876 |
15 Nov 11 |
nicklas |
50 |
|
5876 |
15 Nov 11 |
nicklas |
51 |
static boolean ok = true; |
5876 |
15 Nov 11 |
nicklas |
52 |
public static void main(String[] args) |
5876 |
15 Nov 11 |
nicklas |
53 |
{ |
5876 |
15 Nov 11 |
nicklas |
54 |
TestUtil.checkArgs(args); |
5876 |
15 Nov 11 |
nicklas |
55 |
TestUtil.begin(); |
5876 |
15 Nov 11 |
nicklas |
56 |
ok = test_all(); |
5876 |
15 Nov 11 |
nicklas |
57 |
TestUtil.stop(); |
5876 |
15 Nov 11 |
nicklas |
58 |
} |
5876 |
15 Nov 11 |
nicklas |
59 |
|
5876 |
15 Nov 11 |
nicklas |
60 |
static boolean test_all() |
5876 |
15 Nov 11 |
nicklas |
61 |
{ |
5876 |
15 Nov 11 |
nicklas |
62 |
write("++Testing reporter clone templates"); |
5876 |
15 Nov 11 |
nicklas |
63 |
write_header(); |
5876 |
15 Nov 11 |
nicklas |
// Standard tests: create, load, list |
5876 |
15 Nov 11 |
nicklas |
65 |
|
5876 |
15 Nov 11 |
nicklas |
66 |
List<ExtendedProperty> properties = ExtendedProperties.getProperties("ReporterData"); |
5876 |
15 Nov 11 |
nicklas |
67 |
|
5885 |
22 Nov 11 |
nicklas |
68 |
ClonableProperty symbol = ClonableProperty.createFromRegular(ClonableProperty.SYMBOL); |
5885 |
22 Nov 11 |
nicklas |
69 |
ClonableProperty ex1 = ClonableProperty.createFromExtended(properties.get(0).getName()); |
5876 |
15 Nov 11 |
nicklas |
70 |
|
5876 |
15 Nov 11 |
nicklas |
71 |
int id = test_create("Test reporter clone template", symbol, ex1); |
5876 |
15 Nov 11 |
nicklas |
72 |
test_load(id); |
5876 |
15 Nov 11 |
nicklas |
73 |
test_list(-1); |
5876 |
15 Nov 11 |
nicklas |
74 |
|
5876 |
15 Nov 11 |
nicklas |
75 |
boolean wasSetup = TestAnalyzeUtil.setupExperiment(); |
5876 |
15 Nov 11 |
nicklas |
76 |
try |
5876 |
15 Nov 11 |
nicklas |
77 |
{ |
5876 |
15 Nov 11 |
nicklas |
78 |
|
5876 |
15 Nov 11 |
nicklas |
79 |
int experimentId = TestAnalyzeUtil.getItemId("experiment.genepix"); |
5876 |
15 Nov 11 |
nicklas |
80 |
if (experimentId == 0) |
5876 |
15 Nov 11 |
nicklas |
81 |
{ |
5876 |
15 Nov 11 |
nicklas |
82 |
ok = false; |
5876 |
15 Nov 11 |
nicklas |
83 |
write("Test experiment was not setup correctly."); |
5876 |
15 Nov 11 |
nicklas |
84 |
} |
5876 |
15 Nov 11 |
nicklas |
85 |
|
5886 |
23 Nov 11 |
nicklas |
86 |
test_clone_reporters(id, experimentId, CloneSource.VIRTUAL, 572); |
5886 |
23 Nov 11 |
nicklas |
87 |
test_list_cloned_reporters(experimentId); |
5886 |
23 Nov 11 |
nicklas |
88 |
|
7381 |
22 May 17 |
nicklas |
89 |
test_externalId("B-actin_1/4", experimentId); |
7381 |
22 May 17 |
nicklas |
90 |
|
5886 |
23 Nov 11 |
nicklas |
91 |
test_clone_reporters(id, experimentId, CloneSource.RAW, 572); |
5886 |
23 Nov 11 |
nicklas |
92 |
test_list_cloned_reporters(experimentId); |
5886 |
23 Nov 11 |
nicklas |
93 |
|
5876 |
15 Nov 11 |
nicklas |
// Standard test: Delete |
5876 |
15 Nov 11 |
nicklas |
95 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
5877 |
16 Nov 11 |
nicklas |
96 |
test_remove_cloned_reporters(experimentId); |
5876 |
15 Nov 11 |
nicklas |
97 |
test_delete(id); |
5876 |
15 Nov 11 |
nicklas |
98 |
} |
5876 |
15 Nov 11 |
nicklas |
99 |
finally |
5876 |
15 Nov 11 |
nicklas |
100 |
{ |
5876 |
15 Nov 11 |
nicklas |
101 |
if (wasSetup) TestAnalyzeUtil.cleanupExperiment(); |
5876 |
15 Nov 11 |
nicklas |
102 |
write("++Testing reporter clone templates "+(ok ? "OK" : "Failed")+"\n"); |
5876 |
15 Nov 11 |
nicklas |
103 |
} |
5876 |
15 Nov 11 |
nicklas |
104 |
return ok; |
5876 |
15 Nov 11 |
nicklas |
105 |
} |
5876 |
15 Nov 11 |
nicklas |
106 |
|
5885 |
22 Nov 11 |
nicklas |
107 |
static int test_create(String name, ClonableProperty... properties) |
5876 |
15 Nov 11 |
nicklas |
108 |
{ |
5876 |
15 Nov 11 |
nicklas |
109 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.REPORTERCLONETEMPLATE)) return 0; |
5876 |
15 Nov 11 |
nicklas |
110 |
int id = 0; |
5876 |
15 Nov 11 |
nicklas |
111 |
DbControl dc = null; |
5876 |
15 Nov 11 |
nicklas |
112 |
try |
5876 |
15 Nov 11 |
nicklas |
113 |
{ |
5876 |
15 Nov 11 |
nicklas |
114 |
dc = TestUtil.getDbControl(); |
5876 |
15 Nov 11 |
nicklas |
115 |
ReporterCloneTemplate rct = ReporterCloneTemplate.getNew(dc); |
5876 |
15 Nov 11 |
nicklas |
116 |
rct.setName(name); |
5876 |
15 Nov 11 |
nicklas |
117 |
rct.setDescription("Added at "+new Date()); |
5876 |
15 Nov 11 |
nicklas |
118 |
if (properties != null) |
5876 |
15 Nov 11 |
nicklas |
119 |
{ |
5885 |
22 Nov 11 |
nicklas |
120 |
for (ClonableProperty cp : properties) |
5876 |
15 Nov 11 |
nicklas |
121 |
{ |
5885 |
22 Nov 11 |
nicklas |
122 |
rct.addClonableProperty(cp); |
5876 |
15 Nov 11 |
nicklas |
123 |
} |
5876 |
15 Nov 11 |
nicklas |
124 |
} |
5876 |
15 Nov 11 |
nicklas |
125 |
dc.saveItem(rct); |
5876 |
15 Nov 11 |
nicklas |
126 |
dc.commit(); |
5876 |
15 Nov 11 |
nicklas |
127 |
id = rct.getId(); |
5876 |
15 Nov 11 |
nicklas |
128 |
dc = TestUtil.getDbControl(); |
5876 |
15 Nov 11 |
nicklas |
129 |
dc.reattachItem(rct, false); |
5876 |
15 Nov 11 |
nicklas |
130 |
write_item(0, rct); |
5876 |
15 Nov 11 |
nicklas |
131 |
write("--Create reporter clone template OK"); |
5876 |
15 Nov 11 |
nicklas |
132 |
} |
5876 |
15 Nov 11 |
nicklas |
133 |
catch (Throwable ex) |
5876 |
15 Nov 11 |
nicklas |
134 |
{ |
5876 |
15 Nov 11 |
nicklas |
135 |
write("--Create reporter clone template FAILED"); |
5876 |
15 Nov 11 |
nicklas |
136 |
ex.printStackTrace(); |
5876 |
15 Nov 11 |
nicklas |
137 |
ok = false; |
5876 |
15 Nov 11 |
nicklas |
138 |
} |
5876 |
15 Nov 11 |
nicklas |
139 |
finally |
5876 |
15 Nov 11 |
nicklas |
140 |
{ |
5876 |
15 Nov 11 |
nicklas |
141 |
if (dc != null) dc.close(); |
5876 |
15 Nov 11 |
nicklas |
142 |
} |
5876 |
15 Nov 11 |
nicklas |
143 |
return id; |
5876 |
15 Nov 11 |
nicklas |
144 |
} |
5876 |
15 Nov 11 |
nicklas |
145 |
|
5876 |
15 Nov 11 |
nicklas |
146 |
static void test_load(int id) |
5876 |
15 Nov 11 |
nicklas |
147 |
{ |
5876 |
15 Nov 11 |
nicklas |
148 |
if (id == 0) return; |
5876 |
15 Nov 11 |
nicklas |
149 |
DbControl dc = null; |
5876 |
15 Nov 11 |
nicklas |
150 |
try |
5876 |
15 Nov 11 |
nicklas |
151 |
{ |
5876 |
15 Nov 11 |
nicklas |
152 |
dc = TestUtil.getDbControl(); |
5876 |
15 Nov 11 |
nicklas |
153 |
ReporterCloneTemplate rct = ReporterCloneTemplate.getById(dc, id); |
5876 |
15 Nov 11 |
nicklas |
154 |
write_item(0, rct); |
5876 |
15 Nov 11 |
nicklas |
155 |
write("--Load reporter clone template OK"); |
5876 |
15 Nov 11 |
nicklas |
156 |
} |
5876 |
15 Nov 11 |
nicklas |
157 |
catch (Throwable ex) |
5876 |
15 Nov 11 |
nicklas |
158 |
{ |
5876 |
15 Nov 11 |
nicklas |
159 |
write("--Load reporter clone template FAILED"); |
5876 |
15 Nov 11 |
nicklas |
160 |
ex.printStackTrace(); |
5876 |
15 Nov 11 |
nicklas |
161 |
ok = false; |
5876 |
15 Nov 11 |
nicklas |
162 |
} |
5876 |
15 Nov 11 |
nicklas |
163 |
finally |
5876 |
15 Nov 11 |
nicklas |
164 |
{ |
5876 |
15 Nov 11 |
nicklas |
165 |
if (dc != null) dc.close(); |
5876 |
15 Nov 11 |
nicklas |
166 |
} |
5876 |
15 Nov 11 |
nicklas |
167 |
} |
5876 |
15 Nov 11 |
nicklas |
168 |
|
5876 |
15 Nov 11 |
nicklas |
169 |
static void test_list(int expectedResults) |
5876 |
15 Nov 11 |
nicklas |
170 |
{ |
5876 |
15 Nov 11 |
nicklas |
171 |
DbControl dc = null; |
5876 |
15 Nov 11 |
nicklas |
172 |
try |
5876 |
15 Nov 11 |
nicklas |
173 |
{ |
5876 |
15 Nov 11 |
nicklas |
174 |
dc = TestUtil.getDbControl(); |
5876 |
15 Nov 11 |
nicklas |
175 |
ItemResultList<ReporterCloneTemplate> l = ReporterCloneTemplate.getQuery().list(dc); |
5876 |
15 Nov 11 |
nicklas |
176 |
for (int i = 0; i<l.size(); i++) |
5876 |
15 Nov 11 |
nicklas |
177 |
{ |
5876 |
15 Nov 11 |
nicklas |
178 |
write_item(i, l.get(i)); |
5876 |
15 Nov 11 |
nicklas |
179 |
} |
5876 |
15 Nov 11 |
nicklas |
180 |
if (expectedResults >= 0 && expectedResults != l.size()) |
5876 |
15 Nov 11 |
nicklas |
181 |
{ |
5876 |
15 Nov 11 |
nicklas |
182 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
5876 |
15 Nov 11 |
nicklas |
183 |
} |
5876 |
15 Nov 11 |
nicklas |
184 |
write("--List reporter clone templates OK ("+l.size()+")"); |
5876 |
15 Nov 11 |
nicklas |
185 |
} |
5876 |
15 Nov 11 |
nicklas |
186 |
catch (Throwable ex) |
5876 |
15 Nov 11 |
nicklas |
187 |
{ |
5876 |
15 Nov 11 |
nicklas |
188 |
write("--List reporter clone templates FAILED"); |
5876 |
15 Nov 11 |
nicklas |
189 |
ex.printStackTrace(); |
5876 |
15 Nov 11 |
nicklas |
190 |
ok = false; |
5876 |
15 Nov 11 |
nicklas |
191 |
} |
5876 |
15 Nov 11 |
nicklas |
192 |
finally |
5876 |
15 Nov 11 |
nicklas |
193 |
{ |
5876 |
15 Nov 11 |
nicklas |
194 |
if (dc != null) dc.close(); |
5876 |
15 Nov 11 |
nicklas |
195 |
} |
5876 |
15 Nov 11 |
nicklas |
196 |
} |
5876 |
15 Nov 11 |
nicklas |
197 |
|
5876 |
15 Nov 11 |
nicklas |
198 |
static void test_delete(int id) |
5876 |
15 Nov 11 |
nicklas |
199 |
{ |
5876 |
15 Nov 11 |
nicklas |
200 |
if (id == 0) return; |
5876 |
15 Nov 11 |
nicklas |
201 |
DbControl dc = null; |
5876 |
15 Nov 11 |
nicklas |
202 |
try |
5876 |
15 Nov 11 |
nicklas |
203 |
{ |
5876 |
15 Nov 11 |
nicklas |
204 |
dc = TestUtil.getDbControl(); |
5876 |
15 Nov 11 |
nicklas |
205 |
ReporterCloneTemplate rct = ReporterCloneTemplate.getById(dc, id); |
5876 |
15 Nov 11 |
nicklas |
206 |
dc.deleteItem(rct); |
5876 |
15 Nov 11 |
nicklas |
207 |
Set<ItemProxy> using = rct.getUsingItems(); |
5876 |
15 Nov 11 |
nicklas |
208 |
if (using.size() > 0) |
5876 |
15 Nov 11 |
nicklas |
209 |
{ |
5876 |
15 Nov 11 |
nicklas |
210 |
throw new BaseException(rct + " is used by " + using); |
5876 |
15 Nov 11 |
nicklas |
211 |
} |
5876 |
15 Nov 11 |
nicklas |
212 |
dc.commit(); |
5876 |
15 Nov 11 |
nicklas |
213 |
write("--Delete reporter clone template OK"); |
5876 |
15 Nov 11 |
nicklas |
214 |
} |
5876 |
15 Nov 11 |
nicklas |
215 |
catch (Throwable ex) |
5876 |
15 Nov 11 |
nicklas |
216 |
{ |
5876 |
15 Nov 11 |
nicklas |
217 |
write("--Delete reporter clone template FAILED"); |
5876 |
15 Nov 11 |
nicklas |
218 |
ex.printStackTrace(); |
5876 |
15 Nov 11 |
nicklas |
219 |
ok = false; |
5876 |
15 Nov 11 |
nicklas |
220 |
} |
5876 |
15 Nov 11 |
nicklas |
221 |
finally |
5876 |
15 Nov 11 |
nicklas |
222 |
{ |
5876 |
15 Nov 11 |
nicklas |
223 |
if (dc != null) dc.close(); |
5876 |
15 Nov 11 |
nicklas |
224 |
} |
5876 |
15 Nov 11 |
nicklas |
225 |
} |
5876 |
15 Nov 11 |
nicklas |
226 |
|
5876 |
15 Nov 11 |
nicklas |
227 |
static void write_header() |
5876 |
15 Nov 11 |
nicklas |
228 |
{ |
5876 |
15 Nov 11 |
nicklas |
229 |
if (!TestUtil.getSilent()) |
5876 |
15 Nov 11 |
nicklas |
230 |
{ |
5876 |
15 Nov 11 |
nicklas |
231 |
write(" \tID \tName \tDescription\tLocked\tProperties"); |
5876 |
15 Nov 11 |
nicklas |
232 |
write("-- \t-- \t--------- \t-----------\t------\t----------"); |
5876 |
15 Nov 11 |
nicklas |
233 |
} |
5876 |
15 Nov 11 |
nicklas |
234 |
} |
5876 |
15 Nov 11 |
nicklas |
235 |
static void write_item(int i, ReporterCloneTemplate rct) |
5876 |
15 Nov 11 |
nicklas |
236 |
throws BaseException |
5876 |
15 Nov 11 |
nicklas |
237 |
{ |
5876 |
15 Nov 11 |
nicklas |
238 |
if (!TestUtil.getSilent()) |
5876 |
15 Nov 11 |
nicklas |
239 |
{ |
5876 |
15 Nov 11 |
nicklas |
240 |
System.out.println(i+":\t"+rct.getId()+"\t"+rct.getName()+"\t"+rct.getDescription()+ |
5885 |
22 Nov 11 |
nicklas |
241 |
"\t"+rct.isLocked() + "\t" + rct.getClonableProperties()); |
5876 |
15 Nov 11 |
nicklas |
242 |
} |
5876 |
15 Nov 11 |
nicklas |
243 |
} |
5876 |
15 Nov 11 |
nicklas |
244 |
static void write(String message) |
5876 |
15 Nov 11 |
nicklas |
245 |
{ |
5876 |
15 Nov 11 |
nicklas |
246 |
System.out.println(message); |
5876 |
15 Nov 11 |
nicklas |
247 |
} |
5876 |
15 Nov 11 |
nicklas |
248 |
|
5886 |
23 Nov 11 |
nicklas |
249 |
static void test_clone_reporters(int id, int experimentId, CloneSource source, int numClonedExpected) |
5876 |
15 Nov 11 |
nicklas |
250 |
{ |
5876 |
15 Nov 11 |
nicklas |
251 |
if (id == 0 || experimentId == 0) return; |
5876 |
15 Nov 11 |
nicklas |
252 |
DbControl dc = null; |
5876 |
15 Nov 11 |
nicklas |
253 |
try |
5876 |
15 Nov 11 |
nicklas |
254 |
{ |
5876 |
15 Nov 11 |
nicklas |
255 |
dc = TestUtil.getDbControl(); |
5886 |
23 Nov 11 |
nicklas |
256 |
ReporterCloneTemplate template = ReporterCloneTemplate.getById(dc, id); |
5876 |
15 Nov 11 |
nicklas |
257 |
Experiment exp = Experiment.getById(dc, experimentId); |
5876 |
15 Nov 11 |
nicklas |
258 |
|
5877 |
16 Nov 11 |
nicklas |
259 |
ReporterCloneBatcher batcher = exp.getReporterCloneBatcher(dc); |
5886 |
23 Nov 11 |
nicklas |
260 |
int numCloned = batcher.cloneReporters(source, template, |
5886 |
23 Nov 11 |
nicklas |
261 |
TestUtil.getSilent() ? null : new ConsoleProgressReporter()); |
5886 |
23 Nov 11 |
nicklas |
262 |
if (numCloned != numClonedExpected && numClonedExpected >= 0) |
5886 |
23 Nov 11 |
nicklas |
263 |
{ |
5886 |
23 Nov 11 |
nicklas |
264 |
throw new BaseException("Expected "+numClonedExpected+" reporters, not "+numCloned); |
5886 |
23 Nov 11 |
nicklas |
265 |
} |
5876 |
15 Nov 11 |
nicklas |
266 |
|
5876 |
15 Nov 11 |
nicklas |
267 |
dc.commit(); |
5876 |
15 Nov 11 |
nicklas |
268 |
if (!TestUtil.getSilent()) write(""); |
5876 |
15 Nov 11 |
nicklas |
269 |
write("--Clone reporters OK"); |
5876 |
15 Nov 11 |
nicklas |
270 |
} |
5876 |
15 Nov 11 |
nicklas |
271 |
catch (Throwable ex) |
5876 |
15 Nov 11 |
nicklas |
272 |
{ |
5876 |
15 Nov 11 |
nicklas |
273 |
write("--Clone reporters FAILED"); |
5876 |
15 Nov 11 |
nicklas |
274 |
ex.printStackTrace(); |
5876 |
15 Nov 11 |
nicklas |
275 |
ok = false; |
5876 |
15 Nov 11 |
nicklas |
276 |
} |
5876 |
15 Nov 11 |
nicklas |
277 |
finally |
5876 |
15 Nov 11 |
nicklas |
278 |
{ |
5876 |
15 Nov 11 |
nicklas |
279 |
if (dc != null) dc.close(); |
5876 |
15 Nov 11 |
nicklas |
280 |
} |
5877 |
16 Nov 11 |
nicklas |
281 |
} |
5876 |
15 Nov 11 |
nicklas |
282 |
|
5877 |
16 Nov 11 |
nicklas |
283 |
static void test_remove_cloned_reporters(int experimentId) |
5877 |
16 Nov 11 |
nicklas |
284 |
{ |
5877 |
16 Nov 11 |
nicklas |
285 |
if (experimentId == 0) return; |
5877 |
16 Nov 11 |
nicklas |
286 |
DbControl dc = null; |
5877 |
16 Nov 11 |
nicklas |
287 |
try |
5877 |
16 Nov 11 |
nicklas |
288 |
{ |
5877 |
16 Nov 11 |
nicklas |
289 |
dc = TestUtil.getDbControl(); |
5877 |
16 Nov 11 |
nicklas |
290 |
Experiment exp = Experiment.getById(dc, experimentId); |
5877 |
16 Nov 11 |
nicklas |
291 |
|
5877 |
16 Nov 11 |
nicklas |
292 |
ReporterCloneBatcher batcher = exp.getReporterCloneBatcher(dc); |
5877 |
16 Nov 11 |
nicklas |
293 |
batcher.dropClonedReporters(); |
5877 |
16 Nov 11 |
nicklas |
294 |
|
5877 |
16 Nov 11 |
nicklas |
295 |
dc.commit(); |
5877 |
16 Nov 11 |
nicklas |
296 |
write("--Remove cloned reporters OK"); |
5877 |
16 Nov 11 |
nicklas |
297 |
} |
5877 |
16 Nov 11 |
nicklas |
298 |
catch (Throwable ex) |
5877 |
16 Nov 11 |
nicklas |
299 |
{ |
5877 |
16 Nov 11 |
nicklas |
300 |
write("--Remove cloned reporters FAILED"); |
5877 |
16 Nov 11 |
nicklas |
301 |
ex.printStackTrace(); |
5877 |
16 Nov 11 |
nicklas |
302 |
ok = false; |
5877 |
16 Nov 11 |
nicklas |
303 |
} |
5877 |
16 Nov 11 |
nicklas |
304 |
finally |
5877 |
16 Nov 11 |
nicklas |
305 |
{ |
5877 |
16 Nov 11 |
nicklas |
306 |
if (dc != null) dc.close(); |
5877 |
16 Nov 11 |
nicklas |
307 |
} |
5876 |
15 Nov 11 |
nicklas |
308 |
} |
5877 |
16 Nov 11 |
nicklas |
309 |
|
5886 |
23 Nov 11 |
nicklas |
310 |
static void test_list_cloned_reporters(int experimentId) |
5886 |
23 Nov 11 |
nicklas |
311 |
{ |
5886 |
23 Nov 11 |
nicklas |
312 |
if (experimentId == 0) return; |
5886 |
23 Nov 11 |
nicklas |
313 |
DbControl dc = null; |
5886 |
23 Nov 11 |
nicklas |
314 |
try |
5886 |
23 Nov 11 |
nicklas |
315 |
{ |
5886 |
23 Nov 11 |
nicklas |
316 |
dc = TestUtil.getDbControl(); |
5886 |
23 Nov 11 |
nicklas |
317 |
Experiment exp = Experiment.getById(dc, experimentId); |
5886 |
23 Nov 11 |
nicklas |
318 |
|
5886 |
23 Nov 11 |
nicklas |
319 |
DynamicReporterQuery query = Reporter.getDynamicQuery(exp); |
5886 |
23 Nov 11 |
nicklas |
320 |
ReporterCloneTemplate template = exp.getVirtualDb().getReporterCloneTemplate(); |
5886 |
23 Nov 11 |
nicklas |
321 |
|
5886 |
23 Nov 11 |
nicklas |
322 |
StringBuilder header = new StringBuilder(" "); |
5886 |
23 Nov 11 |
nicklas |
323 |
int numProperties = 0; |
5886 |
23 Nov 11 |
nicklas |
324 |
for (ClonableProperty cp : template.getClonableProperties()) |
5886 |
23 Nov 11 |
nicklas |
325 |
{ |
5886 |
23 Nov 11 |
nicklas |
326 |
header.append("\t").append(cp.getTitle()); |
5886 |
23 Nov 11 |
nicklas |
327 |
query.select(Dynamic.selectReporter(cp.getName())); |
5886 |
23 Nov 11 |
nicklas |
328 |
numProperties++; |
5886 |
23 Nov 11 |
nicklas |
329 |
} |
5886 |
23 Nov 11 |
nicklas |
330 |
if (!TestUtil.getSilent()) |
5886 |
23 Nov 11 |
nicklas |
331 |
{ |
5886 |
23 Nov 11 |
nicklas |
332 |
write(header.toString()); |
5886 |
23 Nov 11 |
nicklas |
333 |
write(header.toString().replaceAll("[^\t]", "-")); |
5886 |
23 Nov 11 |
nicklas |
334 |
} |
5886 |
23 Nov 11 |
nicklas |
335 |
|
5886 |
23 Nov 11 |
nicklas |
336 |
DynamicResultIterator it = query.iterate(dc); |
5886 |
23 Nov 11 |
nicklas |
337 |
int num = 1; |
5886 |
23 Nov 11 |
nicklas |
338 |
while (it.hasNext() && num < 50) |
5886 |
23 Nov 11 |
nicklas |
339 |
{ |
5886 |
23 Nov 11 |
nicklas |
340 |
SqlResult row = it.next(); |
5886 |
23 Nov 11 |
nicklas |
341 |
StringBuilder data = new StringBuilder(); |
5886 |
23 Nov 11 |
nicklas |
342 |
data.append(num); |
5886 |
23 Nov 11 |
nicklas |
343 |
for (int index = 1; index <= numProperties; index++) |
5886 |
23 Nov 11 |
nicklas |
344 |
{ |
5886 |
23 Nov 11 |
nicklas |
345 |
data.append("\t").append(row.getString(index)); |
5886 |
23 Nov 11 |
nicklas |
346 |
} |
5886 |
23 Nov 11 |
nicklas |
347 |
num++; |
5886 |
23 Nov 11 |
nicklas |
348 |
if (!TestUtil.getSilent()) write(data.toString()); |
5886 |
23 Nov 11 |
nicklas |
349 |
} |
5886 |
23 Nov 11 |
nicklas |
350 |
dc.commit(); |
5886 |
23 Nov 11 |
nicklas |
351 |
write("--List cloned reporters OK"); |
5886 |
23 Nov 11 |
nicklas |
352 |
} |
5886 |
23 Nov 11 |
nicklas |
353 |
catch (Throwable ex) |
5886 |
23 Nov 11 |
nicklas |
354 |
{ |
5886 |
23 Nov 11 |
nicklas |
355 |
write("--List cloned FAILED"); |
5886 |
23 Nov 11 |
nicklas |
356 |
ex.printStackTrace(); |
5886 |
23 Nov 11 |
nicklas |
357 |
ok = false; |
5886 |
23 Nov 11 |
nicklas |
358 |
} |
5886 |
23 Nov 11 |
nicklas |
359 |
finally |
5886 |
23 Nov 11 |
nicklas |
360 |
{ |
5886 |
23 Nov 11 |
nicklas |
361 |
if (dc != null) dc.close(); |
5886 |
23 Nov 11 |
nicklas |
362 |
} |
5886 |
23 Nov 11 |
nicklas |
363 |
} |
5886 |
23 Nov 11 |
nicklas |
364 |
|
7381 |
22 May 17 |
nicklas |
365 |
|
7381 |
22 May 17 |
nicklas |
366 |
static void test_externalId(String externalId, int experimentId) |
7381 |
22 May 17 |
nicklas |
367 |
{ |
7381 |
22 May 17 |
nicklas |
368 |
if (experimentId == 0) return; |
7381 |
22 May 17 |
nicklas |
369 |
DbControl dc = null; |
7381 |
22 May 17 |
nicklas |
370 |
try |
7381 |
22 May 17 |
nicklas |
371 |
{ |
7381 |
22 May 17 |
nicklas |
372 |
dc = TestUtil.getDbControl(); |
7381 |
22 May 17 |
nicklas |
373 |
|
7381 |
22 May 17 |
nicklas |
374 |
Experiment exp = Experiment.getById(dc, experimentId); |
7381 |
22 May 17 |
nicklas |
375 |
|
7381 |
22 May 17 |
nicklas |
376 |
ReporterCloneTemplate template = exp.getVirtualDb().getReporterCloneTemplate(); |
7381 |
22 May 17 |
nicklas |
377 |
StringBuilder header = new StringBuilder(" "); |
7381 |
22 May 17 |
nicklas |
378 |
int numProperties = 0; |
7381 |
22 May 17 |
nicklas |
379 |
for (ClonableProperty cp : template.getClonableProperties()) |
7381 |
22 May 17 |
nicklas |
380 |
{ |
7381 |
22 May 17 |
nicklas |
381 |
header.append("\t").append(cp.getTitle()); |
7381 |
22 May 17 |
nicklas |
382 |
numProperties++; |
7381 |
22 May 17 |
nicklas |
383 |
} |
7381 |
22 May 17 |
nicklas |
384 |
if (!TestUtil.getSilent()) |
7381 |
22 May 17 |
nicklas |
385 |
{ |
7381 |
22 May 17 |
nicklas |
386 |
write(header.toString()); |
7381 |
22 May 17 |
nicklas |
387 |
write(header.toString().replaceAll("[^\t]", "-")); |
7381 |
22 May 17 |
nicklas |
388 |
} |
7381 |
22 May 17 |
nicklas |
389 |
|
7381 |
22 May 17 |
nicklas |
390 |
ReporterData rd = Reporter.getByExternalId(dc, externalId, exp); |
7381 |
22 May 17 |
nicklas |
391 |
StringBuilder data = new StringBuilder(); |
7381 |
22 May 17 |
nicklas |
392 |
data.append(1); |
7381 |
22 May 17 |
nicklas |
393 |
for (ClonableProperty cp : template.getClonableProperties()) |
7381 |
22 May 17 |
nicklas |
394 |
{ |
7381 |
22 May 17 |
nicklas |
395 |
Object value = null; |
7381 |
22 May 17 |
nicklas |
396 |
String propertyName = cp.getName(); |
7381 |
22 May 17 |
nicklas |
397 |
if (cp.isExtendedProperty()) |
7381 |
22 May 17 |
nicklas |
398 |
{ |
7381 |
22 May 17 |
nicklas |
399 |
value = rd.getExtended(propertyName); |
7381 |
22 May 17 |
nicklas |
400 |
} |
7381 |
22 May 17 |
nicklas |
401 |
else if (propertyName.equals(ClonableProperty.EXTERNAL_ID)) |
7381 |
22 May 17 |
nicklas |
402 |
{ |
7381 |
22 May 17 |
nicklas |
403 |
value = rd.getExternalId(); |
7381 |
22 May 17 |
nicklas |
404 |
} |
7381 |
22 May 17 |
nicklas |
405 |
else if (propertyName.equals(ClonableProperty.NAME)) |
7381 |
22 May 17 |
nicklas |
406 |
{ |
7381 |
22 May 17 |
nicklas |
407 |
value = rd.getName(); |
7381 |
22 May 17 |
nicklas |
408 |
} |
7381 |
22 May 17 |
nicklas |
409 |
else if (propertyName.equals(ClonableProperty.ID)) |
7381 |
22 May 17 |
nicklas |
410 |
{ |
7381 |
22 May 17 |
nicklas |
411 |
value = rd.getId(); |
7381 |
22 May 17 |
nicklas |
412 |
} |
7381 |
22 May 17 |
nicklas |
413 |
data.append("\t").append(value); |
7381 |
22 May 17 |
nicklas |
414 |
} |
7381 |
22 May 17 |
nicklas |
415 |
if (!TestUtil.getSilent()) write(data.toString()); |
7381 |
22 May 17 |
nicklas |
416 |
|
7381 |
22 May 17 |
nicklas |
417 |
write("--Get cloned by external id OK"); |
7381 |
22 May 17 |
nicklas |
418 |
} |
7381 |
22 May 17 |
nicklas |
419 |
catch (Throwable ex) |
7381 |
22 May 17 |
nicklas |
420 |
{ |
7381 |
22 May 17 |
nicklas |
421 |
write("--Get cloned by external id FAILED"); |
7381 |
22 May 17 |
nicklas |
422 |
ex.printStackTrace(); |
7381 |
22 May 17 |
nicklas |
423 |
ok = false; |
7381 |
22 May 17 |
nicklas |
424 |
} |
7381 |
22 May 17 |
nicklas |
425 |
finally |
7381 |
22 May 17 |
nicklas |
426 |
{ |
7381 |
22 May 17 |
nicklas |
427 |
if (dc != null) dc.close(); |
7381 |
22 May 17 |
nicklas |
428 |
} |
7381 |
22 May 17 |
nicklas |
429 |
} |
7381 |
22 May 17 |
nicklas |
430 |
|
7381 |
22 May 17 |
nicklas |
431 |
|
5876 |
15 Nov 11 |
nicklas |
432 |
} |