2382 |
14 Jun 06 |
nicklas |
1 |
/* |
2382 |
14 Jun 06 |
nicklas |
$Id$ |
2382 |
14 Jun 06 |
nicklas |
3 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2006, 2007 Nicklas Nordborg |
2382 |
14 Jun 06 |
nicklas |
5 |
|
2382 |
14 Jun 06 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
2382 |
14 Jun 06 |
nicklas |
Available at http://base.thep.lu.se/ |
2382 |
14 Jun 06 |
nicklas |
8 |
|
2382 |
14 Jun 06 |
nicklas |
BASE is free software; you can redistribute it and/or |
2382 |
14 Jun 06 |
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 |
2382 |
14 Jun 06 |
nicklas |
of the License, or (at your option) any later version. |
2382 |
14 Jun 06 |
nicklas |
13 |
|
2382 |
14 Jun 06 |
nicklas |
BASE is distributed in the hope that it will be useful, |
2382 |
14 Jun 06 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
2382 |
14 Jun 06 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2382 |
14 Jun 06 |
nicklas |
GNU General Public License for more details. |
2382 |
14 Jun 06 |
nicklas |
18 |
|
2382 |
14 Jun 06 |
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/>. |
2382 |
14 Jun 06 |
nicklas |
21 |
*/ |
2382 |
14 Jun 06 |
nicklas |
22 |
import java.util.Date; |
5340 |
10 May 10 |
nicklas |
23 |
import java.util.Set; |
2382 |
14 Jun 06 |
nicklas |
24 |
|
2382 |
14 Jun 06 |
nicklas |
25 |
import net.sf.basedb.core.AnyToAny; |
2382 |
14 Jun 06 |
nicklas |
26 |
import net.sf.basedb.core.BaseException; |
5021 |
26 Jun 09 |
nicklas |
27 |
import net.sf.basedb.core.BasicItem; |
2382 |
14 Jun 06 |
nicklas |
28 |
import net.sf.basedb.core.DbControl; |
2382 |
14 Jun 06 |
nicklas |
29 |
import net.sf.basedb.core.File; |
5021 |
26 Jun 09 |
nicklas |
30 |
import net.sf.basedb.core.Item; |
5340 |
10 May 10 |
nicklas |
31 |
import net.sf.basedb.core.ItemProxy; |
2382 |
14 Jun 06 |
nicklas |
32 |
import net.sf.basedb.core.ItemResultList; |
5021 |
26 Jun 09 |
nicklas |
33 |
import net.sf.basedb.core.ProgressReporter; |
2382 |
14 Jun 06 |
nicklas |
34 |
import net.sf.basedb.core.Sample; |
5021 |
26 Jun 09 |
nicklas |
35 |
import net.sf.basedb.util.ConsoleProgressReporter; |
2382 |
14 Jun 06 |
nicklas |
36 |
|
2382 |
14 Jun 06 |
nicklas |
37 |
public class TestAnyToAny |
2382 |
14 Jun 06 |
nicklas |
38 |
{ |
2382 |
14 Jun 06 |
nicklas |
39 |
static boolean ok = true; |
2382 |
14 Jun 06 |
nicklas |
40 |
|
2382 |
14 Jun 06 |
nicklas |
41 |
public static void main(String[] args) |
2382 |
14 Jun 06 |
nicklas |
42 |
{ |
2382 |
14 Jun 06 |
nicklas |
43 |
TestUtil.checkArgs(args); |
2382 |
14 Jun 06 |
nicklas |
44 |
TestUtil.begin(); |
2382 |
14 Jun 06 |
nicklas |
45 |
ok = test_all(); |
2382 |
14 Jun 06 |
nicklas |
46 |
TestUtil.stop(); |
2382 |
14 Jun 06 |
nicklas |
47 |
} |
2382 |
14 Jun 06 |
nicklas |
48 |
|
2382 |
14 Jun 06 |
nicklas |
49 |
static boolean test_all() |
2382 |
14 Jun 06 |
nicklas |
50 |
{ |
2382 |
14 Jun 06 |
nicklas |
51 |
write("++Testing any-to-any"); |
2382 |
14 Jun 06 |
nicklas |
52 |
write_header(); |
5024 |
27 Jul 09 |
nicklas |
53 |
|
5024 |
27 Jul 09 |
nicklas |
// Delete "garbage" from previous tests |
5024 |
27 Jul 09 |
nicklas |
55 |
AnyToAny.deleteStrayLinks(null); |
5024 |
27 Jul 09 |
nicklas |
56 |
|
2382 |
14 Jun 06 |
nicklas |
// Standard tests: create, load, list |
6100 |
04 Sep 12 |
nicklas |
58 |
int sampleId = TestSample.test_create(0, null, 0, true); |
3719 |
12 Sep 07 |
nicklas |
59 |
int fileId1 = TestFile.test_create("Linked file #1", false, true); |
3719 |
12 Sep 07 |
nicklas |
60 |
int fileId2 = TestFile.test_create("Linked file #2", false, true); |
5021 |
26 Jun 09 |
nicklas |
61 |
int id = test_create(sampleId, Item.FILE, fileId1, "first", true); |
5021 |
26 Jun 09 |
nicklas |
62 |
int id2 = test_create(sampleId, Item.FILE, fileId2, "second", true); |
5021 |
26 Jun 09 |
nicklas |
// Set up test for stray links |
5021 |
26 Jun 09 |
nicklas |
64 |
int clientId = TestClient.test_create("test-stray-links", false); |
5021 |
26 Jun 09 |
nicklas |
65 |
int helpId = TestHelp.test_create(clientId, "stray-link-test", true); |
5021 |
26 Jun 09 |
nicklas |
66 |
test_create(sampleId, Item.HELP, helpId, "help", false); |
2382 |
14 Jun 06 |
nicklas |
67 |
test_load(id); |
5021 |
26 Jun 09 |
nicklas |
68 |
test_list_from(sampleId, 3); |
2382 |
14 Jun 06 |
nicklas |
69 |
test_list_to(fileId1, 1); |
3454 |
06 Jun 07 |
nicklas |
70 |
test_exists(sampleId, "first", true); |
3454 |
06 Jun 07 |
nicklas |
71 |
test_exists(sampleId, "third", false); |
2382 |
14 Jun 06 |
nicklas |
72 |
|
6684 |
14 Jan 15 |
nicklas |
// Test relinking to a new item in a single transaction |
6684 |
14 Jan 15 |
nicklas |
74 |
int sampleId2 = test_relink(id); |
6684 |
14 Jan 15 |
nicklas |
75 |
|
5021 |
26 Jun 09 |
nicklas |
// Standard test: Delete |
2382 |
14 Jun 06 |
nicklas |
77 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
5021 |
26 Jun 09 |
nicklas |
78 |
TestClient.test_delete(clientId); // Cascade deletes the help item |
5021 |
26 Jun 09 |
nicklas |
79 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
5021 |
26 Jun 09 |
nicklas |
80 |
|
5021 |
26 Jun 09 |
nicklas |
81 |
test_delete_stray(1); |
5021 |
26 Jun 09 |
nicklas |
82 |
test_list_from(sampleId, 2); |
2382 |
14 Jun 06 |
nicklas |
83 |
test_delete(id); |
2382 |
14 Jun 06 |
nicklas |
84 |
test_delete_all(sampleId, 1); |
2382 |
14 Jun 06 |
nicklas |
85 |
|
2382 |
14 Jun 06 |
nicklas |
86 |
TestSample.test_delete(sampleId); |
6684 |
14 Jan 15 |
nicklas |
87 |
TestSample.test_delete(sampleId2); |
2382 |
14 Jun 06 |
nicklas |
88 |
TestFile.test_delete(fileId1); |
2382 |
14 Jun 06 |
nicklas |
89 |
TestFile.test_delete(fileId2); |
2382 |
14 Jun 06 |
nicklas |
90 |
write("++Testing any-to-any "+(ok ? "OK" : "Failed")+"\n"); |
2382 |
14 Jun 06 |
nicklas |
91 |
return ok; |
2382 |
14 Jun 06 |
nicklas |
92 |
} |
2382 |
14 Jun 06 |
nicklas |
93 |
|
5021 |
26 Jun 09 |
nicklas |
94 |
static int test_create(int sampleId, Item itemType, int itemId, String name, boolean usingTo) |
2382 |
14 Jun 06 |
nicklas |
95 |
{ |
5021 |
26 Jun 09 |
nicklas |
96 |
if (sampleId == 0 || itemId == 0) return 0; |
2382 |
14 Jun 06 |
nicklas |
97 |
int id = 0; |
2382 |
14 Jun 06 |
nicklas |
98 |
DbControl dc = null; |
2382 |
14 Jun 06 |
nicklas |
99 |
try |
2382 |
14 Jun 06 |
nicklas |
100 |
{ |
2382 |
14 Jun 06 |
nicklas |
101 |
dc = TestUtil.getDbControl(); |
2382 |
14 Jun 06 |
nicklas |
102 |
Sample s = Sample.getById(dc, sampleId); |
5021 |
26 Jun 09 |
nicklas |
103 |
BasicItem item = itemType.getById(dc, itemId); |
5021 |
26 Jun 09 |
nicklas |
104 |
AnyToAny a = AnyToAny.getNew(dc, s, item, name, usingTo); |
2382 |
14 Jun 06 |
nicklas |
105 |
a.setDescription("Added at "+new Date()); |
2382 |
14 Jun 06 |
nicklas |
106 |
dc.saveItem(a); |
2382 |
14 Jun 06 |
nicklas |
107 |
dc.commit(); |
2382 |
14 Jun 06 |
nicklas |
108 |
id = a.getId(); |
2382 |
14 Jun 06 |
nicklas |
109 |
dc = TestUtil.getDbControl(); |
5060 |
19 Aug 09 |
nicklas |
110 |
dc.reattachItem(a, false); |
2382 |
14 Jun 06 |
nicklas |
111 |
write_item(0, a); |
2382 |
14 Jun 06 |
nicklas |
112 |
write("--Create any-to-any OK"); |
2382 |
14 Jun 06 |
nicklas |
113 |
} |
2382 |
14 Jun 06 |
nicklas |
114 |
catch (Throwable ex) |
2382 |
14 Jun 06 |
nicklas |
115 |
{ |
2382 |
14 Jun 06 |
nicklas |
116 |
write("--Create any-to-any FAILED"); |
2382 |
14 Jun 06 |
nicklas |
117 |
ex.printStackTrace(); |
2382 |
14 Jun 06 |
nicklas |
118 |
ok = false; |
2382 |
14 Jun 06 |
nicklas |
119 |
} |
2382 |
14 Jun 06 |
nicklas |
120 |
finally |
2382 |
14 Jun 06 |
nicklas |
121 |
{ |
2382 |
14 Jun 06 |
nicklas |
122 |
if (dc != null) dc.close(); |
2382 |
14 Jun 06 |
nicklas |
123 |
} |
2382 |
14 Jun 06 |
nicklas |
124 |
return id; |
2382 |
14 Jun 06 |
nicklas |
125 |
} |
2382 |
14 Jun 06 |
nicklas |
126 |
|
6684 |
14 Jan 15 |
nicklas |
127 |
static int test_relink(int id) |
6684 |
14 Jan 15 |
nicklas |
128 |
{ |
6684 |
14 Jan 15 |
nicklas |
129 |
if (id == 0) return 0; |
6684 |
14 Jan 15 |
nicklas |
130 |
int sampleId = 0; |
6684 |
14 Jan 15 |
nicklas |
131 |
DbControl dc = null; |
6684 |
14 Jan 15 |
nicklas |
132 |
try |
6684 |
14 Jan 15 |
nicklas |
133 |
{ |
6684 |
14 Jan 15 |
nicklas |
134 |
dc = TestUtil.getDbControl(); |
6684 |
14 Jan 15 |
nicklas |
135 |
Sample s = Sample.getNew(dc); |
6684 |
14 Jan 15 |
nicklas |
136 |
dc.saveItem(s); |
6684 |
14 Jan 15 |
nicklas |
137 |
|
6684 |
14 Jan 15 |
nicklas |
138 |
AnyToAny a = AnyToAny.getById(dc, id); |
6684 |
14 Jan 15 |
nicklas |
139 |
a.setTo(s); |
6684 |
14 Jan 15 |
nicklas |
140 |
a.setDescription("Relinked "+new Date()); |
6684 |
14 Jan 15 |
nicklas |
141 |
dc.commit(); |
6684 |
14 Jan 15 |
nicklas |
142 |
|
6684 |
14 Jan 15 |
nicklas |
143 |
sampleId = s.getId(); |
6684 |
14 Jan 15 |
nicklas |
144 |
dc = TestUtil.getDbControl(); |
6684 |
14 Jan 15 |
nicklas |
145 |
dc.reattachItem(a, false); |
6684 |
14 Jan 15 |
nicklas |
146 |
write_item(0, a); |
6684 |
14 Jan 15 |
nicklas |
147 |
if (a.getToId() != sampleId) |
6684 |
14 Jan 15 |
nicklas |
148 |
{ |
6684 |
14 Jan 15 |
nicklas |
149 |
throw new BaseException("Relink failed: " + a.getToId() + " != " + sampleId); |
6684 |
14 Jan 15 |
nicklas |
150 |
} |
6684 |
14 Jan 15 |
nicklas |
151 |
write("--Relink any-to-any OK"); |
6684 |
14 Jan 15 |
nicklas |
152 |
} |
6684 |
14 Jan 15 |
nicklas |
153 |
catch (Throwable ex) |
6684 |
14 Jan 15 |
nicklas |
154 |
{ |
6684 |
14 Jan 15 |
nicklas |
155 |
write("--Relink any-to-any FAILED"); |
6684 |
14 Jan 15 |
nicklas |
156 |
ex.printStackTrace(); |
6684 |
14 Jan 15 |
nicklas |
157 |
ok = false; |
6684 |
14 Jan 15 |
nicklas |
158 |
} |
6684 |
14 Jan 15 |
nicklas |
159 |
finally |
6684 |
14 Jan 15 |
nicklas |
160 |
{ |
6684 |
14 Jan 15 |
nicklas |
161 |
if (dc != null) dc.close(); |
6684 |
14 Jan 15 |
nicklas |
162 |
} |
6684 |
14 Jan 15 |
nicklas |
163 |
return sampleId; |
6684 |
14 Jan 15 |
nicklas |
164 |
} |
6684 |
14 Jan 15 |
nicklas |
165 |
|
2382 |
14 Jun 06 |
nicklas |
166 |
static void test_load(int id) |
2382 |
14 Jun 06 |
nicklas |
167 |
{ |
2382 |
14 Jun 06 |
nicklas |
168 |
if (id == 0) return; |
2382 |
14 Jun 06 |
nicklas |
169 |
DbControl dc = null; |
2382 |
14 Jun 06 |
nicklas |
170 |
try |
2382 |
14 Jun 06 |
nicklas |
171 |
{ |
2382 |
14 Jun 06 |
nicklas |
172 |
dc = TestUtil.getDbControl(); |
2382 |
14 Jun 06 |
nicklas |
173 |
AnyToAny a = AnyToAny.getById(dc, id); |
2382 |
14 Jun 06 |
nicklas |
174 |
write_item(0, a); |
2382 |
14 Jun 06 |
nicklas |
175 |
write("--Load any-to-any OK"); |
2382 |
14 Jun 06 |
nicklas |
176 |
} |
2382 |
14 Jun 06 |
nicklas |
177 |
catch (Throwable ex) |
2382 |
14 Jun 06 |
nicklas |
178 |
{ |
2382 |
14 Jun 06 |
nicklas |
179 |
write("--Load any-to-any FAILED"); |
2382 |
14 Jun 06 |
nicklas |
180 |
ex.printStackTrace(); |
2382 |
14 Jun 06 |
nicklas |
181 |
ok = false; |
2382 |
14 Jun 06 |
nicklas |
182 |
} |
2382 |
14 Jun 06 |
nicklas |
183 |
finally |
2382 |
14 Jun 06 |
nicklas |
184 |
{ |
2382 |
14 Jun 06 |
nicklas |
185 |
if (dc != null) dc.close(); |
2382 |
14 Jun 06 |
nicklas |
186 |
} |
2382 |
14 Jun 06 |
nicklas |
187 |
} |
2382 |
14 Jun 06 |
nicklas |
188 |
|
2382 |
14 Jun 06 |
nicklas |
189 |
static void test_delete(int id) |
2382 |
14 Jun 06 |
nicklas |
190 |
{ |
2382 |
14 Jun 06 |
nicklas |
191 |
if (id == 0) return; |
2382 |
14 Jun 06 |
nicklas |
192 |
DbControl dc = null; |
2382 |
14 Jun 06 |
nicklas |
193 |
try |
2382 |
14 Jun 06 |
nicklas |
194 |
{ |
2382 |
14 Jun 06 |
nicklas |
195 |
dc = TestUtil.getDbControl(); |
2382 |
14 Jun 06 |
nicklas |
196 |
AnyToAny a = AnyToAny.getById(dc, id); |
2382 |
14 Jun 06 |
nicklas |
197 |
dc.deleteItem(a); |
5340 |
10 May 10 |
nicklas |
198 |
Set<ItemProxy> using = a.getUsingItems(); |
5340 |
10 May 10 |
nicklas |
199 |
if (using.size() > 0) |
5340 |
10 May 10 |
nicklas |
200 |
{ |
5340 |
10 May 10 |
nicklas |
201 |
throw new BaseException(a + " is used by " + using); |
5340 |
10 May 10 |
nicklas |
202 |
} |
2382 |
14 Jun 06 |
nicklas |
203 |
dc.commit(); |
2382 |
14 Jun 06 |
nicklas |
204 |
write("--Delete any-to-any OK"); |
2382 |
14 Jun 06 |
nicklas |
205 |
} |
2382 |
14 Jun 06 |
nicklas |
206 |
catch (Throwable ex) |
2382 |
14 Jun 06 |
nicklas |
207 |
{ |
2382 |
14 Jun 06 |
nicklas |
208 |
write("--Delete any-to-any FAILED"); |
2382 |
14 Jun 06 |
nicklas |
209 |
ex.printStackTrace(); |
2382 |
14 Jun 06 |
nicklas |
210 |
ok = false; |
2382 |
14 Jun 06 |
nicklas |
211 |
} |
2382 |
14 Jun 06 |
nicklas |
212 |
finally |
2382 |
14 Jun 06 |
nicklas |
213 |
{ |
2382 |
14 Jun 06 |
nicklas |
214 |
if (dc != null) dc.close(); |
2382 |
14 Jun 06 |
nicklas |
215 |
} |
2382 |
14 Jun 06 |
nicklas |
216 |
} |
2382 |
14 Jun 06 |
nicklas |
217 |
|
2382 |
14 Jun 06 |
nicklas |
218 |
static void write_header() |
2382 |
14 Jun 06 |
nicklas |
219 |
{ |
2382 |
14 Jun 06 |
nicklas |
220 |
if (!TestUtil.getSilent()) |
2382 |
14 Jun 06 |
nicklas |
221 |
{ |
2382 |
14 Jun 06 |
nicklas |
222 |
write(" \tID \tName \tDescription\tFrom \tTo"); |
2382 |
14 Jun 06 |
nicklas |
223 |
write("-- \t-- \t--------- \t-----------\t--------\t----------"); |
2382 |
14 Jun 06 |
nicklas |
224 |
} |
2382 |
14 Jun 06 |
nicklas |
225 |
} |
2382 |
14 Jun 06 |
nicklas |
226 |
static void write_item(int i, AnyToAny a) |
2382 |
14 Jun 06 |
nicklas |
227 |
throws BaseException |
2382 |
14 Jun 06 |
nicklas |
228 |
{ |
2382 |
14 Jun 06 |
nicklas |
229 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+a.getId()+"\t"+a.getName()+"\t"+ |
6684 |
14 Jan 15 |
nicklas |
230 |
a.getDescription()+"\t"+a.getFromType()+"["+a.getFromId()+"]\t"+a.getToType()+"["+a.getToId()+"]"); |
2382 |
14 Jun 06 |
nicklas |
231 |
} |
2382 |
14 Jun 06 |
nicklas |
232 |
static void write(String message) |
2382 |
14 Jun 06 |
nicklas |
233 |
{ |
2382 |
14 Jun 06 |
nicklas |
234 |
System.out.println(message); |
2382 |
14 Jun 06 |
nicklas |
235 |
} |
2382 |
14 Jun 06 |
nicklas |
236 |
|
2382 |
14 Jun 06 |
nicklas |
237 |
static void test_list_from(int sampleId, int expectedResults) |
2382 |
14 Jun 06 |
nicklas |
238 |
{ |
2382 |
14 Jun 06 |
nicklas |
239 |
if (sampleId == 0) return; |
2382 |
14 Jun 06 |
nicklas |
240 |
DbControl dc = null; |
2382 |
14 Jun 06 |
nicklas |
241 |
try |
2382 |
14 Jun 06 |
nicklas |
242 |
{ |
2382 |
14 Jun 06 |
nicklas |
243 |
dc = TestUtil.getDbControl(); |
2382 |
14 Jun 06 |
nicklas |
244 |
Sample s = Sample.getById(dc, sampleId); |
2382 |
14 Jun 06 |
nicklas |
245 |
ItemResultList<AnyToAny> l = AnyToAny.getLinksFrom(s).list(dc); |
2382 |
14 Jun 06 |
nicklas |
246 |
for (int i = 0; i<l.size(); i++) |
2382 |
14 Jun 06 |
nicklas |
247 |
{ |
2382 |
14 Jun 06 |
nicklas |
248 |
write_item(i, l.get(i)); |
2382 |
14 Jun 06 |
nicklas |
249 |
} |
2382 |
14 Jun 06 |
nicklas |
250 |
if (expectedResults >= 0 && expectedResults != l.size()) |
2382 |
14 Jun 06 |
nicklas |
251 |
{ |
2382 |
14 Jun 06 |
nicklas |
252 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
2382 |
14 Jun 06 |
nicklas |
253 |
} |
2382 |
14 Jun 06 |
nicklas |
254 |
write("--List any-to-any from item OK ("+l.size()+")"); |
2382 |
14 Jun 06 |
nicklas |
255 |
} |
2382 |
14 Jun 06 |
nicklas |
256 |
catch (Throwable ex) |
2382 |
14 Jun 06 |
nicklas |
257 |
{ |
2382 |
14 Jun 06 |
nicklas |
258 |
write("--List any-to-any from item FAILED"); |
2382 |
14 Jun 06 |
nicklas |
259 |
ex.printStackTrace(); |
2382 |
14 Jun 06 |
nicklas |
260 |
ok = false; |
2382 |
14 Jun 06 |
nicklas |
261 |
} |
2382 |
14 Jun 06 |
nicklas |
262 |
finally |
2382 |
14 Jun 06 |
nicklas |
263 |
{ |
2382 |
14 Jun 06 |
nicklas |
264 |
if (dc != null) dc.close(); |
2382 |
14 Jun 06 |
nicklas |
265 |
} |
2382 |
14 Jun 06 |
nicklas |
266 |
} |
2382 |
14 Jun 06 |
nicklas |
267 |
|
2382 |
14 Jun 06 |
nicklas |
268 |
static void test_list_to(int fileId, int expectedResults) |
2382 |
14 Jun 06 |
nicklas |
269 |
{ |
2382 |
14 Jun 06 |
nicklas |
270 |
if (fileId == 0) return; |
2382 |
14 Jun 06 |
nicklas |
271 |
DbControl dc = null; |
2382 |
14 Jun 06 |
nicklas |
272 |
try |
2382 |
14 Jun 06 |
nicklas |
273 |
{ |
2382 |
14 Jun 06 |
nicklas |
274 |
dc = TestUtil.getDbControl(); |
2382 |
14 Jun 06 |
nicklas |
275 |
File f = File.getById(dc, fileId); |
2382 |
14 Jun 06 |
nicklas |
276 |
ItemResultList<AnyToAny> l = AnyToAny.getLinksTo(f).list(dc); |
2382 |
14 Jun 06 |
nicklas |
277 |
for (int i = 0; i<l.size(); i++) |
2382 |
14 Jun 06 |
nicklas |
278 |
{ |
2382 |
14 Jun 06 |
nicklas |
279 |
write_item(i, l.get(i)); |
2382 |
14 Jun 06 |
nicklas |
280 |
} |
2382 |
14 Jun 06 |
nicklas |
281 |
if (expectedResults >= 0 && expectedResults != l.size()) |
2382 |
14 Jun 06 |
nicklas |
282 |
{ |
2382 |
14 Jun 06 |
nicklas |
283 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
2382 |
14 Jun 06 |
nicklas |
284 |
} |
2382 |
14 Jun 06 |
nicklas |
285 |
write("--List any-to-any to item OK ("+l.size()+")"); |
2382 |
14 Jun 06 |
nicklas |
286 |
} |
2382 |
14 Jun 06 |
nicklas |
287 |
catch (Throwable ex) |
2382 |
14 Jun 06 |
nicklas |
288 |
{ |
2382 |
14 Jun 06 |
nicklas |
289 |
write("--List any-to-any to item FAILED"); |
2382 |
14 Jun 06 |
nicklas |
290 |
ex.printStackTrace(); |
2382 |
14 Jun 06 |
nicklas |
291 |
ok = false; |
2382 |
14 Jun 06 |
nicklas |
292 |
} |
2382 |
14 Jun 06 |
nicklas |
293 |
finally |
2382 |
14 Jun 06 |
nicklas |
294 |
{ |
2382 |
14 Jun 06 |
nicklas |
295 |
if (dc != null) dc.close(); |
2382 |
14 Jun 06 |
nicklas |
296 |
} |
2382 |
14 Jun 06 |
nicklas |
297 |
} |
2382 |
14 Jun 06 |
nicklas |
298 |
|
2382 |
14 Jun 06 |
nicklas |
299 |
static void test_delete_all(int sampleId, int expectedResults) |
2382 |
14 Jun 06 |
nicklas |
300 |
{ |
2382 |
14 Jun 06 |
nicklas |
301 |
if (sampleId == 0) return; |
2382 |
14 Jun 06 |
nicklas |
302 |
DbControl dc = null; |
2382 |
14 Jun 06 |
nicklas |
303 |
try |
2382 |
14 Jun 06 |
nicklas |
304 |
{ |
2382 |
14 Jun 06 |
nicklas |
305 |
dc = TestUtil.getDbControl(); |
2382 |
14 Jun 06 |
nicklas |
306 |
Sample s = Sample.getById(dc, sampleId); |
2382 |
14 Jun 06 |
nicklas |
307 |
int deletedLinks = AnyToAny.unlinkAllFrom(dc, s); |
2382 |
14 Jun 06 |
nicklas |
308 |
dc.commit(); |
2382 |
14 Jun 06 |
nicklas |
309 |
if (expectedResults >= 0 && expectedResults != deletedLinks) |
2382 |
14 Jun 06 |
nicklas |
310 |
{ |
2382 |
14 Jun 06 |
nicklas |
311 |
throw new BaseException("Expected "+expectedResults+" results, not "+deletedLinks); |
2382 |
14 Jun 06 |
nicklas |
312 |
} |
2382 |
14 Jun 06 |
nicklas |
313 |
write("--Delete all any-to-any from item OK ("+deletedLinks+")"); |
2382 |
14 Jun 06 |
nicklas |
314 |
} |
2382 |
14 Jun 06 |
nicklas |
315 |
catch (Throwable ex) |
2382 |
14 Jun 06 |
nicklas |
316 |
{ |
2382 |
14 Jun 06 |
nicklas |
317 |
write("--Delete all any-to-any from item FAILED"); |
2382 |
14 Jun 06 |
nicklas |
318 |
ex.printStackTrace(); |
2382 |
14 Jun 06 |
nicklas |
319 |
ok = false; |
2382 |
14 Jun 06 |
nicklas |
320 |
} |
2382 |
14 Jun 06 |
nicklas |
321 |
finally |
2382 |
14 Jun 06 |
nicklas |
322 |
{ |
2382 |
14 Jun 06 |
nicklas |
323 |
if (dc != null) dc.close(); |
2382 |
14 Jun 06 |
nicklas |
324 |
} |
2382 |
14 Jun 06 |
nicklas |
325 |
} |
3454 |
06 Jun 07 |
nicklas |
326 |
|
5021 |
26 Jun 09 |
nicklas |
327 |
static void test_delete_stray(int expectedResults) |
5021 |
26 Jun 09 |
nicklas |
328 |
{ |
5021 |
26 Jun 09 |
nicklas |
329 |
try |
5021 |
26 Jun 09 |
nicklas |
330 |
{ |
5021 |
26 Jun 09 |
nicklas |
331 |
ProgressReporter progress = TestUtil.getSilent() ? null : new ConsoleProgressReporter(); |
5021 |
26 Jun 09 |
nicklas |
332 |
int deletedLinks = AnyToAny.deleteStrayLinks(progress); |
5021 |
26 Jun 09 |
nicklas |
333 |
if (expectedResults >= 0 && expectedResults != deletedLinks) |
5021 |
26 Jun 09 |
nicklas |
334 |
{ |
5021 |
26 Jun 09 |
nicklas |
335 |
throw new BaseException("Expected "+expectedResults+" deletions, not "+deletedLinks); |
5021 |
26 Jun 09 |
nicklas |
336 |
} |
5021 |
26 Jun 09 |
nicklas |
337 |
if (progress != null) progress.append("\n"); |
5021 |
26 Jun 09 |
nicklas |
338 |
write("--Delete stray any-to-any links OK ("+deletedLinks+")"); |
5021 |
26 Jun 09 |
nicklas |
339 |
} |
5021 |
26 Jun 09 |
nicklas |
340 |
catch (Throwable ex) |
5021 |
26 Jun 09 |
nicklas |
341 |
{ |
5021 |
26 Jun 09 |
nicklas |
342 |
write("--Delete stray any-to-any links FAILED"); |
5021 |
26 Jun 09 |
nicklas |
343 |
ex.printStackTrace(); |
5021 |
26 Jun 09 |
nicklas |
344 |
ok = false; |
5021 |
26 Jun 09 |
nicklas |
345 |
} |
5021 |
26 Jun 09 |
nicklas |
346 |
finally |
5021 |
26 Jun 09 |
nicklas |
347 |
{} |
5021 |
26 Jun 09 |
nicklas |
348 |
} |
5021 |
26 Jun 09 |
nicklas |
349 |
|
5021 |
26 Jun 09 |
nicklas |
350 |
|
3454 |
06 Jun 07 |
nicklas |
351 |
static void test_exists(int sampleId, String name, boolean expected) |
3454 |
06 Jun 07 |
nicklas |
352 |
{ |
3454 |
06 Jun 07 |
nicklas |
353 |
if (sampleId == 0) return; |
3454 |
06 Jun 07 |
nicklas |
354 |
DbControl dc = null; |
3454 |
06 Jun 07 |
nicklas |
355 |
try |
3454 |
06 Jun 07 |
nicklas |
356 |
{ |
3454 |
06 Jun 07 |
nicklas |
357 |
dc = TestUtil.getDbControl(); |
3454 |
06 Jun 07 |
nicklas |
358 |
Sample s = Sample.getById(dc, sampleId); |
3454 |
06 Jun 07 |
nicklas |
359 |
if (AnyToAny.exists(dc, s, name) != expected) |
3454 |
06 Jun 07 |
nicklas |
360 |
{ |
3454 |
06 Jun 07 |
nicklas |
361 |
throw new BaseException("Expected exists=" + expected + " for link=" + name); |
3454 |
06 Jun 07 |
nicklas |
362 |
} |
3454 |
06 Jun 07 |
nicklas |
363 |
write("--Exists any-to-any (" + name + "=" + expected + ") OK"); |
3454 |
06 Jun 07 |
nicklas |
364 |
} |
3454 |
06 Jun 07 |
nicklas |
365 |
catch (Throwable ex) |
3454 |
06 Jun 07 |
nicklas |
366 |
{ |
3454 |
06 Jun 07 |
nicklas |
367 |
write("--Exists any-to-any FAILED"); |
3454 |
06 Jun 07 |
nicklas |
368 |
ex.printStackTrace(); |
3454 |
06 Jun 07 |
nicklas |
369 |
ok = false; |
3454 |
06 Jun 07 |
nicklas |
370 |
} |
3454 |
06 Jun 07 |
nicklas |
371 |
finally |
3454 |
06 Jun 07 |
nicklas |
372 |
{ |
3454 |
06 Jun 07 |
nicklas |
373 |
if (dc != null) dc.close(); |
3454 |
06 Jun 07 |
nicklas |
374 |
} |
3454 |
06 Jun 07 |
nicklas |
375 |
} |
2382 |
14 Jun 06 |
nicklas |
376 |
|
2382 |
14 Jun 06 |
nicklas |
377 |
|
2382 |
14 Jun 06 |
nicklas |
378 |
} |