5039 |
10 Aug 09 |
nicklas |
1 |
/* |
5039 |
10 Aug 09 |
nicklas |
$Id$ |
5039 |
10 Aug 09 |
nicklas |
3 |
|
5039 |
10 Aug 09 |
nicklas |
Copyright (C) 2005 Nicklas Nordborg |
5039 |
10 Aug 09 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg |
5039 |
10 Aug 09 |
nicklas |
6 |
|
5039 |
10 Aug 09 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
5039 |
10 Aug 09 |
nicklas |
Available at http://base.thep.lu.se/ |
5039 |
10 Aug 09 |
nicklas |
9 |
|
5039 |
10 Aug 09 |
nicklas |
BASE is free software; you can redistribute it and/or |
5039 |
10 Aug 09 |
nicklas |
modify it under the terms of the GNU General Public License |
5039 |
10 Aug 09 |
nicklas |
as published by the Free Software Foundation; either version 3 |
5039 |
10 Aug 09 |
nicklas |
of the License, or (at your option) any later version. |
5039 |
10 Aug 09 |
nicklas |
14 |
|
5039 |
10 Aug 09 |
nicklas |
BASE is distributed in the hope that it will be useful, |
5039 |
10 Aug 09 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5039 |
10 Aug 09 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5039 |
10 Aug 09 |
nicklas |
GNU General Public License for more details. |
5039 |
10 Aug 09 |
nicklas |
19 |
|
5039 |
10 Aug 09 |
nicklas |
You should have received a copy of the GNU General Public License |
5039 |
10 Aug 09 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5039 |
10 Aug 09 |
nicklas |
22 |
*/ |
5039 |
10 Aug 09 |
nicklas |
23 |
|
5039 |
10 Aug 09 |
nicklas |
24 |
import java.util.Date; |
5039 |
10 Aug 09 |
nicklas |
25 |
|
5039 |
10 Aug 09 |
nicklas |
26 |
import net.sf.basedb.core.Application; |
5039 |
10 Aug 09 |
nicklas |
27 |
import net.sf.basedb.core.BaseException; |
5039 |
10 Aug 09 |
nicklas |
28 |
import net.sf.basedb.core.BasicItem; |
5039 |
10 Aug 09 |
nicklas |
29 |
import net.sf.basedb.core.ChangeHistory; |
6430 |
10 Mar 14 |
nicklas |
30 |
import net.sf.basedb.core.Sample; |
5039 |
10 Aug 09 |
nicklas |
31 |
import net.sf.basedb.core.DbControl; |
5039 |
10 Aug 09 |
nicklas |
32 |
import net.sf.basedb.core.Item; |
5039 |
10 Aug 09 |
nicklas |
33 |
import net.sf.basedb.core.ItemNotFoundException; |
5039 |
10 Aug 09 |
nicklas |
34 |
import net.sf.basedb.core.ItemQuery; |
5039 |
10 Aug 09 |
nicklas |
35 |
import net.sf.basedb.core.ItemResultList; |
5039 |
10 Aug 09 |
nicklas |
36 |
import net.sf.basedb.core.ProgressReporter; |
5072 |
21 Aug 09 |
nicklas |
37 |
import net.sf.basedb.core.Type; |
5039 |
10 Aug 09 |
nicklas |
38 |
import net.sf.basedb.core.User; |
7167 |
07 Jun 16 |
nicklas |
39 |
import net.sf.basedb.core.log.ChangeType; |
5039 |
10 Aug 09 |
nicklas |
40 |
import net.sf.basedb.core.log.LogManagerFactory; |
7167 |
07 Jun 16 |
nicklas |
41 |
import net.sf.basedb.core.log.ManualLogEntry; |
5039 |
10 Aug 09 |
nicklas |
42 |
import net.sf.basedb.core.log.db.DbLogManagerFactory; |
5039 |
10 Aug 09 |
nicklas |
43 |
import net.sf.basedb.core.query.Expressions; |
5039 |
10 Aug 09 |
nicklas |
44 |
import net.sf.basedb.core.query.Hql; |
5039 |
10 Aug 09 |
nicklas |
45 |
import net.sf.basedb.core.query.Restrictions; |
5039 |
10 Aug 09 |
nicklas |
46 |
import net.sf.basedb.util.ConsoleProgressReporter; |
6086 |
17 Aug 12 |
nicklas |
47 |
import net.sf.basedb.util.extensions.Extension; |
6086 |
17 Aug 12 |
nicklas |
48 |
import net.sf.basedb.util.extensions.ExtensionBean; |
6086 |
17 Aug 12 |
nicklas |
49 |
import net.sf.basedb.util.extensions.Registry; |
6086 |
17 Aug 12 |
nicklas |
50 |
import net.sf.basedb.util.extensions.manager.Settings; |
5039 |
10 Aug 09 |
nicklas |
51 |
|
5039 |
10 Aug 09 |
nicklas |
52 |
public class TestChangeHistory |
5039 |
10 Aug 09 |
nicklas |
53 |
{ |
5039 |
10 Aug 09 |
nicklas |
54 |
|
5039 |
10 Aug 09 |
nicklas |
55 |
static boolean ok = true; |
5039 |
10 Aug 09 |
nicklas |
56 |
public static void main(String[] args) |
5039 |
10 Aug 09 |
nicklas |
57 |
{ |
5039 |
10 Aug 09 |
nicklas |
58 |
TestUtil.checkArgs(args); |
5039 |
10 Aug 09 |
nicklas |
59 |
TestUtil.begin(); |
5039 |
10 Aug 09 |
nicklas |
60 |
ok = test_all(); |
5039 |
10 Aug 09 |
nicklas |
61 |
TestUtil.stop(); |
5039 |
10 Aug 09 |
nicklas |
62 |
} |
5039 |
10 Aug 09 |
nicklas |
63 |
|
5039 |
10 Aug 09 |
nicklas |
64 |
static boolean test_all() |
5039 |
10 Aug 09 |
nicklas |
65 |
{ |
7166 |
07 Jun 16 |
nicklas |
66 |
write("++Testing history"); |
5039 |
10 Aug 09 |
nicklas |
67 |
write_header(); |
5039 |
10 Aug 09 |
nicklas |
68 |
|
5039 |
10 Aug 09 |
nicklas |
69 |
ChangeHistory.deleteStrayEntries(null); |
6086 |
17 Aug 12 |
nicklas |
70 |
|
6086 |
17 Aug 12 |
nicklas |
// Register a new instance of the DbLogger as an extension |
6086 |
17 Aug 12 |
nicklas |
// If the core logger is enabled, disable it |
6086 |
17 Aug 12 |
nicklas |
73 |
Settings xtSettings = Application.getExtensionsManager().getSettings(); |
6086 |
17 Aug 12 |
nicklas |
74 |
Registry xtRegistry = Application.getExtensionsManager().getRegistry(); |
6875 |
20 Apr 15 |
nicklas |
75 |
Extension<?> coreLogger = xtRegistry.getExtension("net.sf.basedb.core.db-log-manager"); |
6086 |
17 Aug 12 |
nicklas |
76 |
boolean coreLoggerWasEnabled = false; |
6086 |
17 Aug 12 |
nicklas |
77 |
if (coreLogger != null && xtSettings.isEnabled(coreLogger)) |
6086 |
17 Aug 12 |
nicklas |
78 |
{ |
6086 |
17 Aug 12 |
nicklas |
79 |
coreLoggerWasEnabled = true; |
6086 |
17 Aug 12 |
nicklas |
80 |
xtSettings.enableExtension(coreLogger.getId(), false); |
6086 |
17 Aug 12 |
nicklas |
81 |
} |
6086 |
17 Aug 12 |
nicklas |
82 |
|
6086 |
17 Aug 12 |
nicklas |
83 |
Extension<LogManagerFactory> logger = new ExtensionBean<LogManagerFactory>( |
6430 |
10 Mar 14 |
nicklas |
84 |
"test.db-logger", "net.sf.basedb.core.log-manager", 1, null, new DbLogManagerFactory(true, true), null); |
6086 |
17 Aug 12 |
nicklas |
85 |
xtRegistry.registerExtension(logger, null); |
6086 |
17 Aug 12 |
nicklas |
86 |
|
6086 |
17 Aug 12 |
nicklas |
//LogManagerFactory old = set_log_manager(new DbLogManagerFactory()); |
7822 |
08 Jun 20 |
nicklas |
88 |
Date since = new Date(System.currentTimeMillis()-1000); |
5039 |
10 Aug 09 |
nicklas |
89 |
int bioSourceId = TestBioSource.test_create("Biosource 1", false); |
6100 |
04 Sep 12 |
nicklas |
90 |
int sampleId = TestSample.test_create(bioSourceId, "Sample 1", 0, false); |
6430 |
10 Mar 14 |
nicklas |
91 |
test_update_sample(sampleId); |
7167 |
07 Jun 16 |
nicklas |
92 |
test_manual_logentry(Item.SAMPLE, sampleId, ChangeType.VIEW, "The sample was viewed by me."); |
5072 |
21 Aug 09 |
nicklas |
93 |
int annotationTypeId = TestAnnotationType.test_create("change", Type.INT, 0, null, null, Item.SAMPLE, 1, null, false); |
5072 |
21 Aug 09 |
nicklas |
94 |
TestAnnotation.test_annotatate(Item.SAMPLE, sampleId, annotationTypeId, 0, 1); |
5072 |
21 Aug 09 |
nicklas |
95 |
TestAnnotation.test_annotatate(Item.SAMPLE, sampleId, annotationTypeId, 0, 2); |
5072 |
21 Aug 09 |
nicklas |
96 |
TestAnnotation.test_remove_annotation(Item.SAMPLE, sampleId, annotationTypeId); |
5641 |
25 May 11 |
nicklas |
97 |
int extractId = TestExtract.test_create(sampleId, "Extract 1", 0, 0, false); |
5039 |
10 Aug 09 |
nicklas |
98 |
TestExtract.test_delete(extractId); |
5039 |
10 Aug 09 |
nicklas |
99 |
|
6600 |
17 Nov 14 |
nicklas |
// 1 CREATE event only |
5039 |
10 Aug 09 |
nicklas |
101 |
test_list_by_item(Item.BIOSOURCE, bioSourceId, 1); |
6600 |
17 Nov 14 |
nicklas |
102 |
|
5072 |
21 Aug 09 |
nicklas |
103 |
/* |
6600 |
17 Nov 14 |
nicklas |
1 CREATE |
6600 |
17 Nov 14 |
nicklas |
2 UPDATE (name and externalId) |
7167 |
07 Jun 16 |
nicklas |
1 VIEW |
6600 |
17 Nov 14 |
nicklas |
3 ADD+UPDATE+REMOVE ('change' annotation) |
6600 |
17 Nov 14 |
nicklas |
2 UPDATE (remainingQuantity when creating/deleting extract) |
6600 |
17 Nov 14 |
nicklas |
109 |
*/ |
7167 |
07 Jun 16 |
nicklas |
110 |
test_list_by_item(Item.SAMPLE, sampleId, 9); |
6600 |
17 Nov 14 |
nicklas |
111 |
/* |
7166 |
07 Jun 16 |
nicklas |
Total history log events: |
6600 |
17 Nov 14 |
nicklas |
4 CREATE (biosource, sample, annotationtype, extract) |
6600 |
17 Nov 14 |
nicklas |
1 ADD (annotation) |
6600 |
17 Nov 14 |
nicklas |
5 UPDATE (when updating the sample, it's annotation and child extract) |
6600 |
17 Nov 14 |
nicklas |
1 REMOVE (annotation) |
6600 |
17 Nov 14 |
nicklas |
1 DELETE (extract) |
7167 |
07 Jun 16 |
nicklas |
1 VIEW (sample) |
5072 |
21 Aug 09 |
nicklas |
119 |
*/ |
7167 |
07 Jun 16 |
nicklas |
120 |
test_list_by_user(TestUtil.getSessionControl().getLoggedInUserId(), since, 13); |
5039 |
10 Aug 09 |
nicklas |
121 |
|
5039 |
10 Aug 09 |
nicklas |
122 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
5039 |
10 Aug 09 |
nicklas |
// Standard test: Delete |
5039 |
10 Aug 09 |
nicklas |
124 |
TestSample.test_delete(sampleId); |
5039 |
10 Aug 09 |
nicklas |
125 |
TestBioSource.test_delete(bioSourceId); |
5072 |
21 Aug 09 |
nicklas |
126 |
TestAnnotationType.test_delete(annotationTypeId); |
7167 |
07 Jun 16 |
nicklas |
// 16 = The original 13 create+update + 3 delete |
7167 |
07 Jun 16 |
nicklas |
128 |
test_delete_stray(16); |
6086 |
17 Aug 12 |
nicklas |
129 |
|
6086 |
17 Aug 12 |
nicklas |
130 |
xtRegistry.unregisterExtension("test.db-logger"); |
6086 |
17 Aug 12 |
nicklas |
131 |
|
6086 |
17 Aug 12 |
nicklas |
132 |
if (coreLoggerWasEnabled) |
6086 |
17 Aug 12 |
nicklas |
133 |
{ |
6086 |
17 Aug 12 |
nicklas |
134 |
xtSettings.enableExtension(coreLogger.getId(), true); |
6086 |
17 Aug 12 |
nicklas |
135 |
} |
6086 |
17 Aug 12 |
nicklas |
136 |
|
7166 |
07 Jun 16 |
nicklas |
137 |
write("++Testing history "+(ok ? "OK" : "Failed")+"\n"); |
5039 |
10 Aug 09 |
nicklas |
138 |
return ok; |
5039 |
10 Aug 09 |
nicklas |
139 |
} |
5039 |
10 Aug 09 |
nicklas |
140 |
|
5039 |
10 Aug 09 |
nicklas |
141 |
static void test_list_by_item(Item itemType, int itemId, int expectedResults) |
5039 |
10 Aug 09 |
nicklas |
142 |
{ |
5039 |
10 Aug 09 |
nicklas |
143 |
DbControl dc = null; |
5039 |
10 Aug 09 |
nicklas |
144 |
try |
5039 |
10 Aug 09 |
nicklas |
145 |
{ |
5039 |
10 Aug 09 |
nicklas |
146 |
dc = TestUtil.getDbControl(); |
5039 |
10 Aug 09 |
nicklas |
147 |
BasicItem item = itemType.getById(dc, itemId); |
5039 |
10 Aug 09 |
nicklas |
148 |
ItemQuery<ChangeHistory> q = ChangeHistory.getHistoryOf(item); |
5039 |
10 Aug 09 |
nicklas |
149 |
ItemResultList<ChangeHistory> l = q.list(dc); |
5039 |
10 Aug 09 |
nicklas |
150 |
for (int i = 0; i<l.size(); i++) |
5039 |
10 Aug 09 |
nicklas |
151 |
{ |
5039 |
10 Aug 09 |
nicklas |
152 |
write_item(i, l.get(i)); |
5039 |
10 Aug 09 |
nicklas |
153 |
} |
5039 |
10 Aug 09 |
nicklas |
154 |
if (expectedResults >= 0 && expectedResults != l.size()) |
5039 |
10 Aug 09 |
nicklas |
155 |
{ |
5039 |
10 Aug 09 |
nicklas |
156 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
5039 |
10 Aug 09 |
nicklas |
157 |
} |
5072 |
21 Aug 09 |
nicklas |
158 |
write("--List history of " + item + " OK ("+l.size()+")"); |
5039 |
10 Aug 09 |
nicklas |
159 |
} |
5039 |
10 Aug 09 |
nicklas |
160 |
catch (Throwable ex) |
5039 |
10 Aug 09 |
nicklas |
161 |
{ |
5072 |
21 Aug 09 |
nicklas |
162 |
write("--List history of " + itemType + "[id=" + itemId + "] FAILED"); |
5039 |
10 Aug 09 |
nicklas |
163 |
ex.printStackTrace(); |
5039 |
10 Aug 09 |
nicklas |
164 |
ok = false; |
5039 |
10 Aug 09 |
nicklas |
165 |
} |
5039 |
10 Aug 09 |
nicklas |
166 |
finally |
5039 |
10 Aug 09 |
nicklas |
167 |
{ |
5039 |
10 Aug 09 |
nicklas |
168 |
if (dc != null) dc.close(); |
5039 |
10 Aug 09 |
nicklas |
169 |
} |
5039 |
10 Aug 09 |
nicklas |
170 |
} |
5039 |
10 Aug 09 |
nicklas |
171 |
|
5039 |
10 Aug 09 |
nicklas |
172 |
static void test_list_by_user(int userId, Date since, int expectedResults) |
5039 |
10 Aug 09 |
nicklas |
173 |
{ |
5039 |
10 Aug 09 |
nicklas |
174 |
DbControl dc = null; |
5039 |
10 Aug 09 |
nicklas |
175 |
try |
5039 |
10 Aug 09 |
nicklas |
176 |
{ |
5039 |
10 Aug 09 |
nicklas |
177 |
dc = TestUtil.getDbControl(); |
5039 |
10 Aug 09 |
nicklas |
178 |
User user = User.getById(dc, userId); |
5039 |
10 Aug 09 |
nicklas |
179 |
ItemQuery<ChangeHistory> q = ChangeHistory.getChangesBy(user); |
5039 |
10 Aug 09 |
nicklas |
180 |
if (since != null) |
5039 |
10 Aug 09 |
nicklas |
181 |
{ |
5039 |
10 Aug 09 |
nicklas |
182 |
q.restrict(Restrictions.gteq(Hql.property("hst", "time"), |
7822 |
08 Jun 20 |
nicklas |
183 |
Expressions.parameter("time", since, Type.TIMESTAMP))); |
5039 |
10 Aug 09 |
nicklas |
184 |
} |
5039 |
10 Aug 09 |
nicklas |
185 |
ItemResultList<ChangeHistory> l = q.list(dc); |
5039 |
10 Aug 09 |
nicklas |
186 |
for (int i = 0; i<l.size(); i++) |
5039 |
10 Aug 09 |
nicklas |
187 |
{ |
5039 |
10 Aug 09 |
nicklas |
188 |
write_item(i, l.get(i)); |
5039 |
10 Aug 09 |
nicklas |
189 |
} |
5039 |
10 Aug 09 |
nicklas |
190 |
if (expectedResults >= 0 && expectedResults != l.size()) |
5039 |
10 Aug 09 |
nicklas |
191 |
{ |
5039 |
10 Aug 09 |
nicklas |
192 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
5039 |
10 Aug 09 |
nicklas |
193 |
} |
5039 |
10 Aug 09 |
nicklas |
194 |
write("--List changes by user OK ("+l.size()+")"); |
5039 |
10 Aug 09 |
nicklas |
195 |
} |
5039 |
10 Aug 09 |
nicklas |
196 |
catch (Throwable ex) |
5039 |
10 Aug 09 |
nicklas |
197 |
{ |
5039 |
10 Aug 09 |
nicklas |
198 |
write("--List changes by user FAILED"); |
5039 |
10 Aug 09 |
nicklas |
199 |
ex.printStackTrace(); |
5039 |
10 Aug 09 |
nicklas |
200 |
ok = false; |
5039 |
10 Aug 09 |
nicklas |
201 |
} |
5039 |
10 Aug 09 |
nicklas |
202 |
finally |
5039 |
10 Aug 09 |
nicklas |
203 |
{ |
5039 |
10 Aug 09 |
nicklas |
204 |
if (dc != null) dc.close(); |
5039 |
10 Aug 09 |
nicklas |
205 |
} |
5039 |
10 Aug 09 |
nicklas |
206 |
} |
5039 |
10 Aug 09 |
nicklas |
207 |
|
5039 |
10 Aug 09 |
nicklas |
208 |
|
5039 |
10 Aug 09 |
nicklas |
209 |
static void write_header() |
5039 |
10 Aug 09 |
nicklas |
210 |
{ |
5039 |
10 Aug 09 |
nicklas |
211 |
if (!TestUtil.getSilent()) |
5039 |
10 Aug 09 |
nicklas |
212 |
{ |
6430 |
10 Mar 14 |
nicklas |
213 |
write(" \tID \tTime \tType\tItem \tChange info\tOld value\tNew value\tUser"); |
6430 |
10 Mar 14 |
nicklas |
214 |
write("-- \t-- \t---------\t----\t------\t-----------\t---------\t---------\t----"); |
5039 |
10 Aug 09 |
nicklas |
215 |
} |
5039 |
10 Aug 09 |
nicklas |
216 |
} |
5039 |
10 Aug 09 |
nicklas |
217 |
static void write_item(int i, ChangeHistory c) |
5039 |
10 Aug 09 |
nicklas |
218 |
throws BaseException |
5039 |
10 Aug 09 |
nicklas |
219 |
{ |
5072 |
21 Aug 09 |
nicklas |
220 |
String item = null; |
5039 |
10 Aug 09 |
nicklas |
221 |
try |
5039 |
10 Aug 09 |
nicklas |
222 |
{ |
5072 |
21 Aug 09 |
nicklas |
223 |
BasicItem b = c.getItem(null); |
5072 |
21 Aug 09 |
nicklas |
224 |
item = b.toString(); |
5039 |
10 Aug 09 |
nicklas |
225 |
} |
5039 |
10 Aug 09 |
nicklas |
226 |
catch (ItemNotFoundException ex) |
5072 |
21 Aug 09 |
nicklas |
227 |
{ |
5072 |
21 Aug 09 |
nicklas |
228 |
item = c.getItemType() + "[id=" + c.getItemId() + "; not found]"; |
5072 |
21 Aug 09 |
nicklas |
229 |
} |
5039 |
10 Aug 09 |
nicklas |
230 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+c.getId()+"\t"+c.getTime()+"\t"+ |
6430 |
10 Mar 14 |
nicklas |
231 |
c.getChangeType() + "\t" + item + "\t" + c.getChangeInfo()+"\t"+c.getOldValue()+"\t"+c.getNewValue()+"\t"+c.getUser(null)); |
5039 |
10 Aug 09 |
nicklas |
232 |
} |
5039 |
10 Aug 09 |
nicklas |
233 |
static void write(String message) |
5039 |
10 Aug 09 |
nicklas |
234 |
{ |
5039 |
10 Aug 09 |
nicklas |
235 |
System.out.println(message); |
5039 |
10 Aug 09 |
nicklas |
236 |
} |
5039 |
10 Aug 09 |
nicklas |
237 |
|
5039 |
10 Aug 09 |
nicklas |
238 |
static void test_delete_stray(int expectedResults) |
5039 |
10 Aug 09 |
nicklas |
239 |
{ |
5039 |
10 Aug 09 |
nicklas |
240 |
try |
5039 |
10 Aug 09 |
nicklas |
241 |
{ |
5039 |
10 Aug 09 |
nicklas |
242 |
ProgressReporter progress = TestUtil.getSilent() ? null : new ConsoleProgressReporter(); |
5039 |
10 Aug 09 |
nicklas |
243 |
int deletedLinks = ChangeHistory.deleteStrayEntries(progress); |
5039 |
10 Aug 09 |
nicklas |
244 |
if (expectedResults >= 0 && expectedResults != deletedLinks) |
5039 |
10 Aug 09 |
nicklas |
245 |
{ |
5039 |
10 Aug 09 |
nicklas |
246 |
throw new BaseException("Expected "+expectedResults+" deletions, not "+deletedLinks); |
5039 |
10 Aug 09 |
nicklas |
247 |
} |
5039 |
10 Aug 09 |
nicklas |
248 |
if (progress != null) progress.append("\n"); |
7166 |
07 Jun 16 |
nicklas |
249 |
write("--Delete stray history OK ("+deletedLinks+")"); |
5039 |
10 Aug 09 |
nicklas |
250 |
} |
5039 |
10 Aug 09 |
nicklas |
251 |
catch (Throwable ex) |
5039 |
10 Aug 09 |
nicklas |
252 |
{ |
7166 |
07 Jun 16 |
nicklas |
253 |
write("--Delete stray history FAILED"); |
5039 |
10 Aug 09 |
nicklas |
254 |
ex.printStackTrace(); |
5039 |
10 Aug 09 |
nicklas |
255 |
ok = false; |
5039 |
10 Aug 09 |
nicklas |
256 |
} |
5039 |
10 Aug 09 |
nicklas |
257 |
finally |
5039 |
10 Aug 09 |
nicklas |
258 |
{} |
5039 |
10 Aug 09 |
nicklas |
259 |
} |
5039 |
10 Aug 09 |
nicklas |
260 |
|
6430 |
10 Mar 14 |
nicklas |
261 |
static void test_update_sample(int sampleId) |
6430 |
10 Mar 14 |
nicklas |
262 |
{ |
6430 |
10 Mar 14 |
nicklas |
263 |
DbControl dc = null; |
6430 |
10 Mar 14 |
nicklas |
264 |
try |
6430 |
10 Mar 14 |
nicklas |
265 |
{ |
6430 |
10 Mar 14 |
nicklas |
266 |
dc = TestUtil.getDbControl(); |
6430 |
10 Mar 14 |
nicklas |
267 |
Sample s = Sample.getById(dc, sampleId); |
6430 |
10 Mar 14 |
nicklas |
268 |
s.setName("Updated name"); |
6430 |
10 Mar 14 |
nicklas |
269 |
s.setExternalId("Added external id"); |
6430 |
10 Mar 14 |
nicklas |
270 |
dc.commit(); |
6430 |
10 Mar 14 |
nicklas |
271 |
write("--Updated sample OK"); |
6430 |
10 Mar 14 |
nicklas |
272 |
} |
6430 |
10 Mar 14 |
nicklas |
273 |
catch (Throwable ex) |
6430 |
10 Mar 14 |
nicklas |
274 |
{ |
6430 |
10 Mar 14 |
nicklas |
275 |
write("--Updated sample FAILED"); |
6430 |
10 Mar 14 |
nicklas |
276 |
ex.printStackTrace(); |
6430 |
10 Mar 14 |
nicklas |
277 |
ok = false; |
6430 |
10 Mar 14 |
nicklas |
278 |
} |
6430 |
10 Mar 14 |
nicklas |
279 |
finally |
6430 |
10 Mar 14 |
nicklas |
280 |
{ |
6430 |
10 Mar 14 |
nicklas |
281 |
if (dc != null) dc.close(); |
6430 |
10 Mar 14 |
nicklas |
282 |
} |
6430 |
10 Mar 14 |
nicklas |
283 |
} |
7167 |
07 Jun 16 |
nicklas |
284 |
|
7167 |
07 Jun 16 |
nicklas |
285 |
static void test_manual_logentry(Item itemType, int itemId, ChangeType change, String info) |
7167 |
07 Jun 16 |
nicklas |
286 |
{ |
7167 |
07 Jun 16 |
nicklas |
287 |
DbControl dc = null; |
7167 |
07 Jun 16 |
nicklas |
288 |
try |
7167 |
07 Jun 16 |
nicklas |
289 |
{ |
7167 |
07 Jun 16 |
nicklas |
290 |
dc = TestUtil.getDbControl(); |
7167 |
07 Jun 16 |
nicklas |
291 |
BasicItem item = itemType.getById(dc, itemId); |
7167 |
07 Jun 16 |
nicklas |
292 |
dc.logEntry(new ManualLogEntry(item, change, info)); |
7167 |
07 Jun 16 |
nicklas |
293 |
dc.commit(); |
7167 |
07 Jun 16 |
nicklas |
294 |
write("--Manual log entry OK"); |
7167 |
07 Jun 16 |
nicklas |
295 |
} |
7167 |
07 Jun 16 |
nicklas |
296 |
catch (Throwable ex) |
7167 |
07 Jun 16 |
nicklas |
297 |
{ |
7167 |
07 Jun 16 |
nicklas |
298 |
write("--Manual log entry FAILED"); |
7167 |
07 Jun 16 |
nicklas |
299 |
ex.printStackTrace(); |
7167 |
07 Jun 16 |
nicklas |
300 |
ok = false; |
7167 |
07 Jun 16 |
nicklas |
301 |
} |
7167 |
07 Jun 16 |
nicklas |
302 |
finally |
7167 |
07 Jun 16 |
nicklas |
303 |
{ |
7167 |
07 Jun 16 |
nicklas |
304 |
if (dc != null) dc.close(); |
7167 |
07 Jun 16 |
nicklas |
305 |
} |
7167 |
07 Jun 16 |
nicklas |
306 |
|
7167 |
07 Jun 16 |
nicklas |
307 |
} |
5039 |
10 Aug 09 |
nicklas |
308 |
} |
5039 |
10 Aug 09 |
nicklas |
309 |
|