6739 |
17 Feb 15 |
nicklas |
1 |
/* |
6739 |
17 Feb 15 |
nicklas |
$Id $ |
6739 |
17 Feb 15 |
nicklas |
3 |
|
6739 |
17 Feb 15 |
nicklas |
Copyright (C) 2015 Nicklas Nordborg |
6739 |
17 Feb 15 |
nicklas |
5 |
|
6739 |
17 Feb 15 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
6739 |
17 Feb 15 |
nicklas |
Available at http://base.thep.lu.se/ |
6739 |
17 Feb 15 |
nicklas |
8 |
|
6739 |
17 Feb 15 |
nicklas |
BASE is free software; you can redistribute it and/or |
6739 |
17 Feb 15 |
nicklas |
modify it under the terms of the GNU General Public License |
6739 |
17 Feb 15 |
nicklas |
as published by the Free Software Foundation; either version 3 |
6739 |
17 Feb 15 |
nicklas |
of the License, or (at your option) any later version. |
6739 |
17 Feb 15 |
nicklas |
13 |
|
6739 |
17 Feb 15 |
nicklas |
BASE is distributed in the hope that it will be useful, |
6739 |
17 Feb 15 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
6739 |
17 Feb 15 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6739 |
17 Feb 15 |
nicklas |
GNU General Public License for more details. |
6739 |
17 Feb 15 |
nicklas |
18 |
|
6739 |
17 Feb 15 |
nicklas |
You should have received a copy of the GNU General Public License |
6739 |
17 Feb 15 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
6739 |
17 Feb 15 |
nicklas |
21 |
*/ |
6739 |
17 Feb 15 |
nicklas |
22 |
|
6739 |
17 Feb 15 |
nicklas |
23 |
|
6739 |
17 Feb 15 |
nicklas |
24 |
import java.util.ArrayList; |
6739 |
17 Feb 15 |
nicklas |
25 |
import java.util.Date; |
6739 |
17 Feb 15 |
nicklas |
26 |
import java.util.List; |
6739 |
17 Feb 15 |
nicklas |
27 |
import java.util.Set; |
6739 |
17 Feb 15 |
nicklas |
28 |
|
6739 |
17 Feb 15 |
nicklas |
29 |
import net.sf.basedb.core.BaseException; |
6891 |
29 Apr 15 |
nicklas |
30 |
import net.sf.basedb.core.BioSource; |
6739 |
17 Feb 15 |
nicklas |
31 |
import net.sf.basedb.core.DbControl; |
6739 |
17 Feb 15 |
nicklas |
32 |
import net.sf.basedb.core.Item; |
6739 |
17 Feb 15 |
nicklas |
33 |
import net.sf.basedb.core.ItemList; |
6739 |
17 Feb 15 |
nicklas |
34 |
import net.sf.basedb.core.ItemProxy; |
6739 |
17 Feb 15 |
nicklas |
35 |
import net.sf.basedb.core.ItemQuery; |
6739 |
17 Feb 15 |
nicklas |
36 |
import net.sf.basedb.core.ItemResultList; |
6739 |
17 Feb 15 |
nicklas |
37 |
import net.sf.basedb.core.Listable; |
6739 |
17 Feb 15 |
nicklas |
38 |
import net.sf.basedb.core.Permission; |
7834 |
26 Jun 20 |
nicklas |
39 |
import net.sf.basedb.core.query.Expressions; |
7834 |
26 Jun 20 |
nicklas |
40 |
import net.sf.basedb.core.query.Hql; |
7834 |
26 Jun 20 |
nicklas |
41 |
import net.sf.basedb.core.query.Restrictions; |
6739 |
17 Feb 15 |
nicklas |
42 |
|
6739 |
17 Feb 15 |
nicklas |
43 |
public class TestItemList |
6739 |
17 Feb 15 |
nicklas |
44 |
{ |
6739 |
17 Feb 15 |
nicklas |
45 |
|
6739 |
17 Feb 15 |
nicklas |
46 |
static boolean ok = true; |
6739 |
17 Feb 15 |
nicklas |
47 |
public static void main(String[] args) |
6739 |
17 Feb 15 |
nicklas |
48 |
{ |
6739 |
17 Feb 15 |
nicklas |
49 |
TestUtil.checkArgs(args); |
6739 |
17 Feb 15 |
nicklas |
50 |
TestUtil.begin(); |
6739 |
17 Feb 15 |
nicklas |
51 |
ok = test_all(); |
6739 |
17 Feb 15 |
nicklas |
52 |
TestUtil.stop(); |
6739 |
17 Feb 15 |
nicklas |
53 |
} |
6739 |
17 Feb 15 |
nicklas |
54 |
|
6739 |
17 Feb 15 |
nicklas |
55 |
static boolean test_all() |
6739 |
17 Feb 15 |
nicklas |
56 |
{ |
6739 |
17 Feb 15 |
nicklas |
57 |
write("++Testing item lists"); |
6739 |
17 Feb 15 |
nicklas |
58 |
write_header(); |
6739 |
17 Feb 15 |
nicklas |
// Standard tests: create, load, list |
6739 |
17 Feb 15 |
nicklas |
60 |
int id1 = test_create(Item.BIOSOURCE, "net.sf.basedb.clients.test.bmlist1", true); |
6739 |
17 Feb 15 |
nicklas |
61 |
int id2 = test_create(Item.BIOSOURCE, "net.sf.basedb.clients.test.bmlist2", true); |
6739 |
17 Feb 15 |
nicklas |
62 |
int id3 = test_create(Item.BIOSOURCE, "net.sf.basedb.clients.test.bmlist3", true); |
6739 |
17 Feb 15 |
nicklas |
63 |
int id4 = test_create(Item.BIOSOURCE, "net.sf.basedb.clients.test.bmlist4", true); |
6739 |
17 Feb 15 |
nicklas |
64 |
int id5 = test_create(Item.BIOSOURCE, "net.sf.basedb.clients.test.bmlist5", true); |
6739 |
17 Feb 15 |
nicklas |
65 |
int id6 = test_create(Item.BIOSOURCE, "net.sf.basedb.clients.test.bmlist6", true); |
6891 |
29 Apr 15 |
nicklas |
66 |
int id7 = test_create(Item.BIOSOURCE, "net.sf.basedb.clients.test.bmlist7", true); |
6739 |
17 Feb 15 |
nicklas |
67 |
test_load(id1); |
6739 |
17 Feb 15 |
nicklas |
68 |
test_list(-1); |
6739 |
17 Feb 15 |
nicklas |
69 |
|
6739 |
17 Feb 15 |
nicklas |
// Create items to use in the lists |
6739 |
17 Feb 15 |
nicklas |
71 |
int bs1 = TestBioSource.test_create("bs.1", false); |
6739 |
17 Feb 15 |
nicklas |
72 |
int bs2 = TestBioSource.test_create("bs.2", false); |
6739 |
17 Feb 15 |
nicklas |
73 |
int bs3 = TestBioSource.test_create("bs.3", false); |
6739 |
17 Feb 15 |
nicklas |
74 |
int bs4 = TestBioSource.test_create("bs.4", false); |
6739 |
17 Feb 15 |
nicklas |
75 |
int bs5 = TestBioSource.test_create("bs.5", false); |
6739 |
17 Feb 15 |
nicklas |
76 |
|
6739 |
17 Feb 15 |
nicklas |
77 |
test_add_members(id1, bs1, bs2, bs3); |
6739 |
17 Feb 15 |
nicklas |
78 |
test_list_members(id1, 3); |
6739 |
17 Feb 15 |
nicklas |
79 |
test_add_members(id2, bs3, bs4, bs5); // One in common with 'id1' |
6891 |
29 Apr 15 |
nicklas |
80 |
|
6891 |
29 Apr 15 |
nicklas |
81 |
int bs6 = test_create_and_add_member(id7); |
6891 |
29 Apr 15 |
nicklas |
82 |
test_list_members(id7, 1); |
6739 |
17 Feb 15 |
nicklas |
83 |
|
7834 |
26 Jun 20 |
nicklas |
84 |
test_add_by_query(id7, "bs.%", 6); // 'id7' should now have all bs.* + the original one |
7834 |
26 Jun 20 |
nicklas |
85 |
|
6891 |
29 Apr 15 |
nicklas |
86 |
int bs7 = test_union(id3, 6, id1, id2); // 'id3' is now the union of 'id1' and 'id2' + one new item |
6891 |
29 Apr 15 |
nicklas |
87 |
test_list_members(id3, 6); |
6891 |
29 Apr 15 |
nicklas |
88 |
|
6891 |
29 Apr 15 |
nicklas |
89 |
int bs8 = test_intersect(id4, 3, id1, id2); // 'id4' is now the intersection of 'id1' and 'id2' + one new item |
6891 |
29 Apr 15 |
nicklas |
90 |
test_list_members(id4, 3); |
6891 |
29 Apr 15 |
nicklas |
91 |
|
6739 |
17 Feb 15 |
nicklas |
92 |
test_remove(id5, id3, 4, id4); // 'id5' is now the complement of 'id3' to 'id4' |
6891 |
29 Apr 15 |
nicklas |
93 |
test_retain(id6, id2, 3, id1); // 'id6' is now the intersection on 'id1' and 'id2' |
6739 |
17 Feb 15 |
nicklas |
94 |
|
6739 |
17 Feb 15 |
nicklas |
95 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
6741 |
17 Feb 15 |
nicklas |
96 |
|
6741 |
17 Feb 15 |
nicklas |
// Remove an item and check that the size property is correct |
6819 |
31 Mar 15 |
nicklas |
98 |
TestBioSource.test_delete(bs3); |
6891 |
29 Apr 15 |
nicklas |
99 |
test_list_members(id1, 4); |
6741 |
17 Feb 15 |
nicklas |
100 |
|
6891 |
29 Apr 15 |
nicklas |
101 |
test_remove_members(id1, bs1, bs2, bs7, bs8); |
6819 |
31 Mar 15 |
nicklas |
102 |
test_list_members(id1, 0); |
7834 |
26 Jun 20 |
nicklas |
103 |
|
7834 |
26 Jun 20 |
nicklas |
104 |
test_remove_by_query(id7, "bs.%", 1); // 'id7' should now only the original biosource |
7834 |
26 Jun 20 |
nicklas |
105 |
|
6741 |
17 Feb 15 |
nicklas |
106 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
6739 |
17 Feb 15 |
nicklas |
107 |
|
6739 |
17 Feb 15 |
nicklas |
// Standard test: Delete |
6739 |
17 Feb 15 |
nicklas |
109 |
test_delete(id1); |
6739 |
17 Feb 15 |
nicklas |
110 |
test_delete(id2); |
6739 |
17 Feb 15 |
nicklas |
111 |
test_delete(id3); |
6739 |
17 Feb 15 |
nicklas |
112 |
test_delete(id4); |
6739 |
17 Feb 15 |
nicklas |
113 |
test_delete(id5); |
6739 |
17 Feb 15 |
nicklas |
114 |
test_delete(id6); |
6891 |
29 Apr 15 |
nicklas |
115 |
test_delete(id7); |
6739 |
17 Feb 15 |
nicklas |
116 |
TestBioSource.test_delete(bs1); |
6739 |
17 Feb 15 |
nicklas |
117 |
TestBioSource.test_delete(bs2); |
6739 |
17 Feb 15 |
nicklas |
118 |
TestBioSource.test_delete(bs4); |
6739 |
17 Feb 15 |
nicklas |
119 |
TestBioSource.test_delete(bs5); |
6891 |
29 Apr 15 |
nicklas |
120 |
TestBioSource.test_delete(bs6); |
6891 |
29 Apr 15 |
nicklas |
121 |
TestBioSource.test_delete(bs7); |
6891 |
29 Apr 15 |
nicklas |
122 |
TestBioSource.test_delete(bs8); |
6739 |
17 Feb 15 |
nicklas |
123 |
write("++Testing item lists "+(ok ? "OK" : "Failed")+"\n"); |
6739 |
17 Feb 15 |
nicklas |
124 |
return ok; |
6739 |
17 Feb 15 |
nicklas |
125 |
} |
6739 |
17 Feb 15 |
nicklas |
126 |
|
6739 |
17 Feb 15 |
nicklas |
127 |
static int test_create(Item memberType, String externalId, boolean setAll) |
6739 |
17 Feb 15 |
nicklas |
128 |
{ |
6756 |
20 Feb 15 |
nicklas |
129 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.ITEMLIST)) return 0; |
6739 |
17 Feb 15 |
nicklas |
130 |
int id = 0; |
6739 |
17 Feb 15 |
nicklas |
131 |
DbControl dc = null; |
6739 |
17 Feb 15 |
nicklas |
132 |
try |
6739 |
17 Feb 15 |
nicklas |
133 |
{ |
6739 |
17 Feb 15 |
nicklas |
134 |
dc = TestUtil.getDbControl(); |
6739 |
17 Feb 15 |
nicklas |
135 |
ItemList bl = ItemList.getNew(dc, memberType); |
6739 |
17 Feb 15 |
nicklas |
136 |
bl.setExternalId(externalId); |
6739 |
17 Feb 15 |
nicklas |
137 |
if (setAll) |
6739 |
17 Feb 15 |
nicklas |
138 |
{ |
6739 |
17 Feb 15 |
nicklas |
139 |
bl.setName("Test item list"); |
6739 |
17 Feb 15 |
nicklas |
140 |
bl.setDescription("Added at "+new Date()); |
6739 |
17 Feb 15 |
nicklas |
141 |
} |
6739 |
17 Feb 15 |
nicklas |
142 |
dc.saveItem(bl); |
6739 |
17 Feb 15 |
nicklas |
143 |
dc.commit(); |
6739 |
17 Feb 15 |
nicklas |
144 |
id = bl.getId(); |
6739 |
17 Feb 15 |
nicklas |
145 |
write_item(0, bl); |
6739 |
17 Feb 15 |
nicklas |
146 |
write("--Create item list OK"); |
6739 |
17 Feb 15 |
nicklas |
147 |
} |
6739 |
17 Feb 15 |
nicklas |
148 |
catch (Throwable ex) |
6739 |
17 Feb 15 |
nicklas |
149 |
{ |
6739 |
17 Feb 15 |
nicklas |
150 |
write("--Create item list FAILED"); |
6739 |
17 Feb 15 |
nicklas |
151 |
ex.printStackTrace(); |
6739 |
17 Feb 15 |
nicklas |
152 |
ok = false; |
6739 |
17 Feb 15 |
nicklas |
153 |
} |
6739 |
17 Feb 15 |
nicklas |
154 |
finally |
6739 |
17 Feb 15 |
nicklas |
155 |
{ |
6739 |
17 Feb 15 |
nicklas |
156 |
if (dc != null) dc.close(); |
6739 |
17 Feb 15 |
nicklas |
157 |
} |
6739 |
17 Feb 15 |
nicklas |
158 |
return id; |
6739 |
17 Feb 15 |
nicklas |
159 |
} |
6891 |
29 Apr 15 |
nicklas |
160 |
|
6739 |
17 Feb 15 |
nicklas |
161 |
static void test_load(int id) |
6739 |
17 Feb 15 |
nicklas |
162 |
{ |
6739 |
17 Feb 15 |
nicklas |
163 |
if (id == 0) return; |
6739 |
17 Feb 15 |
nicklas |
164 |
DbControl dc = null; |
6739 |
17 Feb 15 |
nicklas |
165 |
try |
6739 |
17 Feb 15 |
nicklas |
166 |
{ |
6739 |
17 Feb 15 |
nicklas |
167 |
dc = TestUtil.getDbControl(); |
6739 |
17 Feb 15 |
nicklas |
168 |
ItemList bl = ItemList.getById(dc, id); |
6739 |
17 Feb 15 |
nicklas |
169 |
write_item(0, bl); |
6739 |
17 Feb 15 |
nicklas |
170 |
write("--Load item list OK"); |
6739 |
17 Feb 15 |
nicklas |
171 |
} |
6739 |
17 Feb 15 |
nicklas |
172 |
catch (Throwable ex) |
6739 |
17 Feb 15 |
nicklas |
173 |
{ |
6739 |
17 Feb 15 |
nicklas |
174 |
write("--Load item list FAILED"); |
6739 |
17 Feb 15 |
nicklas |
175 |
ex.printStackTrace(); |
6739 |
17 Feb 15 |
nicklas |
176 |
ok = false; |
6739 |
17 Feb 15 |
nicklas |
177 |
} |
6739 |
17 Feb 15 |
nicklas |
178 |
finally |
6739 |
17 Feb 15 |
nicklas |
179 |
{ |
6739 |
17 Feb 15 |
nicklas |
180 |
if (dc != null) dc.close(); |
6739 |
17 Feb 15 |
nicklas |
181 |
} |
6739 |
17 Feb 15 |
nicklas |
182 |
} |
6739 |
17 Feb 15 |
nicklas |
183 |
|
6739 |
17 Feb 15 |
nicklas |
184 |
|
6739 |
17 Feb 15 |
nicklas |
185 |
static void test_list(int expectedResults) |
6739 |
17 Feb 15 |
nicklas |
186 |
{ |
6739 |
17 Feb 15 |
nicklas |
187 |
DbControl dc = null; |
6739 |
17 Feb 15 |
nicklas |
188 |
try |
6739 |
17 Feb 15 |
nicklas |
189 |
{ |
6739 |
17 Feb 15 |
nicklas |
190 |
dc = TestUtil.getDbControl(); |
6739 |
17 Feb 15 |
nicklas |
191 |
ItemQuery<ItemList> q = ItemList.getQuery(); |
6739 |
17 Feb 15 |
nicklas |
192 |
ItemResultList<ItemList> l = q.list(dc); |
6739 |
17 Feb 15 |
nicklas |
193 |
for (int i = 0; i<l.size(); i++) |
6739 |
17 Feb 15 |
nicklas |
194 |
{ |
6739 |
17 Feb 15 |
nicklas |
195 |
write_item(i, l.get(i)); |
6739 |
17 Feb 15 |
nicklas |
196 |
} |
6739 |
17 Feb 15 |
nicklas |
197 |
if (expectedResults >= 0 && expectedResults != l.size()) |
6739 |
17 Feb 15 |
nicklas |
198 |
{ |
6739 |
17 Feb 15 |
nicklas |
199 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
6739 |
17 Feb 15 |
nicklas |
200 |
} |
6739 |
17 Feb 15 |
nicklas |
201 |
write("--List item lists OK ("+l.size()+")"); |
6739 |
17 Feb 15 |
nicklas |
202 |
} |
6739 |
17 Feb 15 |
nicklas |
203 |
catch (Throwable ex) |
6739 |
17 Feb 15 |
nicklas |
204 |
{ |
6739 |
17 Feb 15 |
nicklas |
205 |
write("--List item lists FAILED"); |
6739 |
17 Feb 15 |
nicklas |
206 |
ex.printStackTrace(); |
6739 |
17 Feb 15 |
nicklas |
207 |
ok = false; |
6739 |
17 Feb 15 |
nicklas |
208 |
} |
6739 |
17 Feb 15 |
nicklas |
209 |
finally |
6739 |
17 Feb 15 |
nicklas |
210 |
{ |
6739 |
17 Feb 15 |
nicklas |
211 |
if (dc != null) dc.close(); |
6739 |
17 Feb 15 |
nicklas |
212 |
} |
6739 |
17 Feb 15 |
nicklas |
213 |
} |
6739 |
17 Feb 15 |
nicklas |
214 |
|
6739 |
17 Feb 15 |
nicklas |
215 |
static void test_delete(int id) |
6739 |
17 Feb 15 |
nicklas |
216 |
{ |
6739 |
17 Feb 15 |
nicklas |
217 |
if (id == 0) return; |
6739 |
17 Feb 15 |
nicklas |
218 |
DbControl dc = null; |
6739 |
17 Feb 15 |
nicklas |
219 |
try |
6739 |
17 Feb 15 |
nicklas |
220 |
{ |
6739 |
17 Feb 15 |
nicklas |
221 |
dc = TestUtil.getDbControl(); |
6739 |
17 Feb 15 |
nicklas |
222 |
ItemList bl = ItemList.getById(dc, id); |
6739 |
17 Feb 15 |
nicklas |
223 |
dc.deleteItem(bl); |
6739 |
17 Feb 15 |
nicklas |
224 |
Set<ItemProxy> using = bl.getUsingItems(); |
6739 |
17 Feb 15 |
nicklas |
225 |
if (using.size() > 0) |
6739 |
17 Feb 15 |
nicklas |
226 |
{ |
6739 |
17 Feb 15 |
nicklas |
227 |
throw new BaseException(bl + " is used by " + using); |
6739 |
17 Feb 15 |
nicklas |
228 |
} |
6739 |
17 Feb 15 |
nicklas |
229 |
dc.commit(); |
6739 |
17 Feb 15 |
nicklas |
230 |
write("--Delete item list OK"); |
6739 |
17 Feb 15 |
nicklas |
231 |
} |
6739 |
17 Feb 15 |
nicklas |
232 |
catch (Throwable ex) |
6739 |
17 Feb 15 |
nicklas |
233 |
{ |
6739 |
17 Feb 15 |
nicklas |
234 |
write("--Delete item list FAILED"); |
6739 |
17 Feb 15 |
nicklas |
235 |
ex.printStackTrace(); |
6739 |
17 Feb 15 |
nicklas |
236 |
ok = false; |
6739 |
17 Feb 15 |
nicklas |
237 |
} |
6739 |
17 Feb 15 |
nicklas |
238 |
finally |
6739 |
17 Feb 15 |
nicklas |
239 |
{ |
6739 |
17 Feb 15 |
nicklas |
240 |
if (dc != null) dc.close(); |
6739 |
17 Feb 15 |
nicklas |
241 |
} |
6739 |
17 Feb 15 |
nicklas |
242 |
} |
6739 |
17 Feb 15 |
nicklas |
243 |
|
6739 |
17 Feb 15 |
nicklas |
244 |
static void write_header() |
6739 |
17 Feb 15 |
nicklas |
245 |
{ |
6739 |
17 Feb 15 |
nicklas |
246 |
if (!TestUtil.getSilent()) |
6739 |
17 Feb 15 |
nicklas |
247 |
{ |
6739 |
17 Feb 15 |
nicklas |
248 |
write(" \tID \tName \tDescription\tExternal ID\tSize"); |
6739 |
17 Feb 15 |
nicklas |
249 |
write("-- \t-- \t--------- \t-----------\t-----------\t----"); |
6739 |
17 Feb 15 |
nicklas |
250 |
} |
6739 |
17 Feb 15 |
nicklas |
251 |
} |
6739 |
17 Feb 15 |
nicklas |
252 |
static void write_item(int i, ItemList bl) |
6739 |
17 Feb 15 |
nicklas |
253 |
throws BaseException |
6739 |
17 Feb 15 |
nicklas |
254 |
{ |
6739 |
17 Feb 15 |
nicklas |
255 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+bl.getId()+"\t"+bl.getName()+"\t"+ |
6739 |
17 Feb 15 |
nicklas |
256 |
bl.getDescription()+"\t"+bl.getExternalId()+"\t"+bl.getSize()); |
6739 |
17 Feb 15 |
nicklas |
257 |
} |
6741 |
17 Feb 15 |
nicklas |
258 |
static void write_item(int i, Listable bm) |
6739 |
17 Feb 15 |
nicklas |
259 |
throws BaseException |
6739 |
17 Feb 15 |
nicklas |
260 |
{ |
6739 |
17 Feb 15 |
nicklas |
261 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+bm.getId()+"\t"+bm.getName()+"\t"+ |
6739 |
17 Feb 15 |
nicklas |
262 |
bm.getType()); |
6739 |
17 Feb 15 |
nicklas |
263 |
} |
6739 |
17 Feb 15 |
nicklas |
264 |
static void write(String message) |
6739 |
17 Feb 15 |
nicklas |
265 |
{ |
6739 |
17 Feb 15 |
nicklas |
266 |
System.out.println(message); |
6739 |
17 Feb 15 |
nicklas |
267 |
} |
6739 |
17 Feb 15 |
nicklas |
268 |
|
6739 |
17 Feb 15 |
nicklas |
269 |
static void test_add_members(int id, int... itemIds) |
6739 |
17 Feb 15 |
nicklas |
270 |
{ |
6739 |
17 Feb 15 |
nicklas |
271 |
if (id == 0 || itemIds == null || itemIds.length == 0) return; |
6739 |
17 Feb 15 |
nicklas |
272 |
DbControl dc = null; |
6739 |
17 Feb 15 |
nicklas |
273 |
try |
6739 |
17 Feb 15 |
nicklas |
274 |
{ |
6739 |
17 Feb 15 |
nicklas |
275 |
dc = TestUtil.getDbControl(); |
6739 |
17 Feb 15 |
nicklas |
276 |
ItemList bl = ItemList.getById(dc, id); |
6739 |
17 Feb 15 |
nicklas |
277 |
int oldSize = bl.getSize(); |
6739 |
17 Feb 15 |
nicklas |
278 |
for (int iid : itemIds) |
6739 |
17 Feb 15 |
nicklas |
279 |
{ |
6739 |
17 Feb 15 |
nicklas |
280 |
Listable bm = (Listable)bl.getMemberType().getById(dc, iid); |
6739 |
17 Feb 15 |
nicklas |
281 |
bl.add(bm); |
6739 |
17 Feb 15 |
nicklas |
282 |
} |
6739 |
17 Feb 15 |
nicklas |
283 |
dc.commit(); |
6739 |
17 Feb 15 |
nicklas |
284 |
|
6739 |
17 Feb 15 |
nicklas |
285 |
dc = TestUtil.getDbControl(); |
6739 |
17 Feb 15 |
nicklas |
286 |
bl = ItemList.getById(dc, id); |
6739 |
17 Feb 15 |
nicklas |
287 |
int newSize = bl.getSize(); |
6739 |
17 Feb 15 |
nicklas |
288 |
if (newSize != oldSize + itemIds.length) |
6739 |
17 Feb 15 |
nicklas |
289 |
{ |
6739 |
17 Feb 15 |
nicklas |
290 |
throw new BaseException("new size=" + newSize + "; old size="+oldSize); |
6739 |
17 Feb 15 |
nicklas |
291 |
} |
6739 |
17 Feb 15 |
nicklas |
292 |
write("--Add items to list OK (new size=" + newSize + ")"); |
6739 |
17 Feb 15 |
nicklas |
293 |
} |
6739 |
17 Feb 15 |
nicklas |
294 |
catch (Throwable ex) |
6739 |
17 Feb 15 |
nicklas |
295 |
{ |
6739 |
17 Feb 15 |
nicklas |
296 |
write("--Add items to list FAILED"); |
6739 |
17 Feb 15 |
nicklas |
297 |
ex.printStackTrace(); |
6739 |
17 Feb 15 |
nicklas |
298 |
ok = false; |
6739 |
17 Feb 15 |
nicklas |
299 |
} |
6739 |
17 Feb 15 |
nicklas |
300 |
finally |
6739 |
17 Feb 15 |
nicklas |
301 |
{ |
6739 |
17 Feb 15 |
nicklas |
302 |
if (dc != null) dc.close(); |
6739 |
17 Feb 15 |
nicklas |
303 |
} |
6739 |
17 Feb 15 |
nicklas |
304 |
} |
7834 |
26 Jun 20 |
nicklas |
305 |
|
7834 |
26 Jun 20 |
nicklas |
306 |
static void test_add_by_query(int id, String nameFilter, int expectedSize) |
7834 |
26 Jun 20 |
nicklas |
307 |
{ |
7834 |
26 Jun 20 |
nicklas |
308 |
if (id == 0 ) return; |
7834 |
26 Jun 20 |
nicklas |
309 |
DbControl dc = null; |
7834 |
26 Jun 20 |
nicklas |
310 |
try |
7834 |
26 Jun 20 |
nicklas |
311 |
{ |
7834 |
26 Jun 20 |
nicklas |
312 |
dc = TestUtil.getDbControl(); |
7834 |
26 Jun 20 |
nicklas |
313 |
ItemList bl = ItemList.getById(dc, id); |
7834 |
26 Jun 20 |
nicklas |
314 |
|
7834 |
26 Jun 20 |
nicklas |
315 |
ItemQuery<BioSource> query = BioSource.getQuery(); |
7834 |
26 Jun 20 |
nicklas |
316 |
query.restrict(Restrictions.like(Hql.property("name"), Expressions.string(nameFilter))); |
7834 |
26 Jun 20 |
nicklas |
317 |
bl.add(query); |
7834 |
26 Jun 20 |
nicklas |
318 |
dc.commit(); |
7834 |
26 Jun 20 |
nicklas |
319 |
|
7834 |
26 Jun 20 |
nicklas |
320 |
dc = TestUtil.getDbControl(); |
7834 |
26 Jun 20 |
nicklas |
321 |
bl = ItemList.getById(dc, id); |
7834 |
26 Jun 20 |
nicklas |
322 |
if (bl.getSize() != expectedSize) |
7834 |
26 Jun 20 |
nicklas |
323 |
{ |
7834 |
26 Jun 20 |
nicklas |
324 |
throw new BaseException("Incorrect size; expected=" + expectedSize + "; actual=" + bl.getSize()); |
7834 |
26 Jun 20 |
nicklas |
325 |
} |
7834 |
26 Jun 20 |
nicklas |
326 |
write("--Add items to list by query OK (new size=" + expectedSize + ")"); |
7834 |
26 Jun 20 |
nicklas |
327 |
} |
7834 |
26 Jun 20 |
nicklas |
328 |
catch (Throwable ex) |
7834 |
26 Jun 20 |
nicklas |
329 |
{ |
7834 |
26 Jun 20 |
nicklas |
330 |
write("--Add items to list by query FAILED"); |
7834 |
26 Jun 20 |
nicklas |
331 |
ex.printStackTrace(); |
7834 |
26 Jun 20 |
nicklas |
332 |
ok = false; |
7834 |
26 Jun 20 |
nicklas |
333 |
} |
7834 |
26 Jun 20 |
nicklas |
334 |
finally |
7834 |
26 Jun 20 |
nicklas |
335 |
{ |
7834 |
26 Jun 20 |
nicklas |
336 |
if (dc != null) dc.close(); |
7834 |
26 Jun 20 |
nicklas |
337 |
} |
7834 |
26 Jun 20 |
nicklas |
338 |
} |
7834 |
26 Jun 20 |
nicklas |
339 |
|
7834 |
26 Jun 20 |
nicklas |
340 |
static void test_remove_by_query(int id, String nameFilter, int expectedSize) |
7834 |
26 Jun 20 |
nicklas |
341 |
{ |
7834 |
26 Jun 20 |
nicklas |
342 |
if (id == 0 ) return; |
7834 |
26 Jun 20 |
nicklas |
343 |
DbControl dc = null; |
7834 |
26 Jun 20 |
nicklas |
344 |
try |
7834 |
26 Jun 20 |
nicklas |
345 |
{ |
7834 |
26 Jun 20 |
nicklas |
346 |
dc = TestUtil.getDbControl(); |
7834 |
26 Jun 20 |
nicklas |
347 |
ItemList bl = ItemList.getById(dc, id); |
7834 |
26 Jun 20 |
nicklas |
348 |
|
7834 |
26 Jun 20 |
nicklas |
349 |
ItemQuery<BioSource> query = BioSource.getQuery(); |
7834 |
26 Jun 20 |
nicklas |
350 |
query.restrict(Restrictions.like(Hql.property("name"), Expressions.string(nameFilter))); |
7834 |
26 Jun 20 |
nicklas |
351 |
bl.removeItems(query); |
7834 |
26 Jun 20 |
nicklas |
352 |
dc.commit(); |
7834 |
26 Jun 20 |
nicklas |
353 |
|
7834 |
26 Jun 20 |
nicklas |
354 |
dc = TestUtil.getDbControl(); |
7834 |
26 Jun 20 |
nicklas |
355 |
bl = ItemList.getById(dc, id); |
7834 |
26 Jun 20 |
nicklas |
356 |
if (bl.getSize() != expectedSize) |
7834 |
26 Jun 20 |
nicklas |
357 |
{ |
7834 |
26 Jun 20 |
nicklas |
358 |
throw new BaseException("Incorrect size; expected=" + expectedSize + "; actual=" + bl.getSize()); |
7834 |
26 Jun 20 |
nicklas |
359 |
} |
7834 |
26 Jun 20 |
nicklas |
360 |
write("--Remove items from list by query OK (new size=" + expectedSize + ")"); |
7834 |
26 Jun 20 |
nicklas |
361 |
} |
7834 |
26 Jun 20 |
nicklas |
362 |
catch (Throwable ex) |
7834 |
26 Jun 20 |
nicklas |
363 |
{ |
7834 |
26 Jun 20 |
nicklas |
364 |
write("--Remove items from list by query FAILED"); |
7834 |
26 Jun 20 |
nicklas |
365 |
ex.printStackTrace(); |
7834 |
26 Jun 20 |
nicklas |
366 |
ok = false; |
7834 |
26 Jun 20 |
nicklas |
367 |
} |
7834 |
26 Jun 20 |
nicklas |
368 |
finally |
7834 |
26 Jun 20 |
nicklas |
369 |
{ |
7834 |
26 Jun 20 |
nicklas |
370 |
if (dc != null) dc.close(); |
7834 |
26 Jun 20 |
nicklas |
371 |
} |
7834 |
26 Jun 20 |
nicklas |
372 |
} |
6739 |
17 Feb 15 |
nicklas |
373 |
|
6891 |
29 Apr 15 |
nicklas |
374 |
static int test_create_and_add_member(int id) |
6739 |
17 Feb 15 |
nicklas |
375 |
{ |
6891 |
29 Apr 15 |
nicklas |
376 |
if (id == 0) return 0; |
6739 |
17 Feb 15 |
nicklas |
377 |
DbControl dc = null; |
6739 |
17 Feb 15 |
nicklas |
378 |
try |
6739 |
17 Feb 15 |
nicklas |
379 |
{ |
6739 |
17 Feb 15 |
nicklas |
380 |
dc = TestUtil.getDbControl(); |
6891 |
29 Apr 15 |
nicklas |
381 |
|
6891 |
29 Apr 15 |
nicklas |
382 |
BioSource bs = BioSource.getNew(dc); |
6891 |
29 Apr 15 |
nicklas |
383 |
dc.saveItem(bs); |
6891 |
29 Apr 15 |
nicklas |
384 |
|
6739 |
17 Feb 15 |
nicklas |
385 |
ItemList bl = ItemList.getById(dc, id); |
6891 |
29 Apr 15 |
nicklas |
386 |
bl.add(bs); |
6891 |
29 Apr 15 |
nicklas |
387 |
|
6891 |
29 Apr 15 |
nicklas |
388 |
dc.commit(); |
6891 |
29 Apr 15 |
nicklas |
389 |
id = bs.getId(); |
6891 |
29 Apr 15 |
nicklas |
390 |
write_item(0, bs); |
6891 |
29 Apr 15 |
nicklas |
391 |
write("--Create and add member to list OK"); |
6891 |
29 Apr 15 |
nicklas |
392 |
} |
6891 |
29 Apr 15 |
nicklas |
393 |
catch (Throwable ex) |
6891 |
29 Apr 15 |
nicklas |
394 |
{ |
6891 |
29 Apr 15 |
nicklas |
395 |
write("--Create and add member to list FAILED"); |
6891 |
29 Apr 15 |
nicklas |
396 |
ex.printStackTrace(); |
6891 |
29 Apr 15 |
nicklas |
397 |
ok = false; |
6891 |
29 Apr 15 |
nicklas |
398 |
} |
6891 |
29 Apr 15 |
nicklas |
399 |
finally |
6891 |
29 Apr 15 |
nicklas |
400 |
{ |
6891 |
29 Apr 15 |
nicklas |
401 |
if (dc != null) dc.close(); |
6891 |
29 Apr 15 |
nicklas |
402 |
} |
6891 |
29 Apr 15 |
nicklas |
403 |
return id; |
6891 |
29 Apr 15 |
nicklas |
404 |
} |
6891 |
29 Apr 15 |
nicklas |
405 |
|
6891 |
29 Apr 15 |
nicklas |
406 |
|
6891 |
29 Apr 15 |
nicklas |
407 |
static void test_remove_members(int id, int... items) |
6891 |
29 Apr 15 |
nicklas |
408 |
{ |
6891 |
29 Apr 15 |
nicklas |
409 |
if (id == 0) return; |
6891 |
29 Apr 15 |
nicklas |
410 |
DbControl dc = null; |
6891 |
29 Apr 15 |
nicklas |
411 |
try |
6891 |
29 Apr 15 |
nicklas |
412 |
{ |
6891 |
29 Apr 15 |
nicklas |
413 |
dc = TestUtil.getDbControl(); |
6891 |
29 Apr 15 |
nicklas |
414 |
ItemList bl = ItemList.getById(dc, id); |
6739 |
17 Feb 15 |
nicklas |
415 |
int oldSize = bl.getSize(); |
6891 |
29 Apr 15 |
nicklas |
416 |
for (int itemId : items) |
6891 |
29 Apr 15 |
nicklas |
417 |
{ |
6891 |
29 Apr 15 |
nicklas |
418 |
Listable bm = (Listable)bl.getMemberType().getById(dc, itemId); |
7599 |
22 Feb 19 |
nicklas |
419 |
bl.removeItem(bm); |
6891 |
29 Apr 15 |
nicklas |
420 |
} |
6739 |
17 Feb 15 |
nicklas |
421 |
dc.commit(); |
6739 |
17 Feb 15 |
nicklas |
422 |
dc = TestUtil.getDbControl(); |
6739 |
17 Feb 15 |
nicklas |
423 |
bl = ItemList.getById(dc, id); |
6739 |
17 Feb 15 |
nicklas |
424 |
int newSize = bl.getSize(); |
6891 |
29 Apr 15 |
nicklas |
425 |
if (newSize != oldSize - items.length) |
6739 |
17 Feb 15 |
nicklas |
426 |
{ |
6739 |
17 Feb 15 |
nicklas |
427 |
throw new BaseException("new size=" + newSize + "; old size="+oldSize); |
6739 |
17 Feb 15 |
nicklas |
428 |
} |
6739 |
17 Feb 15 |
nicklas |
429 |
write("--Remove items from list OK (new size=" + newSize + ")"); |
6739 |
17 Feb 15 |
nicklas |
430 |
} |
6739 |
17 Feb 15 |
nicklas |
431 |
catch (Throwable ex) |
6739 |
17 Feb 15 |
nicklas |
432 |
{ |
6739 |
17 Feb 15 |
nicklas |
433 |
write("--Remove items from list FAILED"); |
6739 |
17 Feb 15 |
nicklas |
434 |
ex.printStackTrace(); |
6739 |
17 Feb 15 |
nicklas |
435 |
ok = false; |
6739 |
17 Feb 15 |
nicklas |
436 |
} |
6739 |
17 Feb 15 |
nicklas |
437 |
finally |
6739 |
17 Feb 15 |
nicklas |
438 |
{ |
6739 |
17 Feb 15 |
nicklas |
439 |
if (dc != null) dc.close(); |
6739 |
17 Feb 15 |
nicklas |
440 |
} |
6739 |
17 Feb 15 |
nicklas |
441 |
} |
6739 |
17 Feb 15 |
nicklas |
442 |
|
6739 |
17 Feb 15 |
nicklas |
443 |
static void test_list_members(int id, int expectedResults) |
6739 |
17 Feb 15 |
nicklas |
444 |
{ |
6739 |
17 Feb 15 |
nicklas |
445 |
if (id == 0) return; |
6739 |
17 Feb 15 |
nicklas |
446 |
DbControl dc = null; |
6739 |
17 Feb 15 |
nicklas |
447 |
try |
6739 |
17 Feb 15 |
nicklas |
448 |
{ |
6739 |
17 Feb 15 |
nicklas |
449 |
dc = TestUtil.getDbControl(); |
6739 |
17 Feb 15 |
nicklas |
450 |
ItemList bl = ItemList.getById(dc, id); |
6739 |
17 Feb 15 |
nicklas |
451 |
ItemQuery<? extends Listable> query = bl.getMembers(); |
6739 |
17 Feb 15 |
nicklas |
452 |
ItemResultList<? extends Listable> l = query.list(dc); |
6739 |
17 Feb 15 |
nicklas |
453 |
for (int i = 0; i<l.size(); i++) |
6739 |
17 Feb 15 |
nicklas |
454 |
{ |
6741 |
17 Feb 15 |
nicklas |
455 |
write_item(i, l.get(i)); |
6739 |
17 Feb 15 |
nicklas |
456 |
} |
6741 |
17 Feb 15 |
nicklas |
457 |
if (bl.getSize() != l.size()) |
6741 |
17 Feb 15 |
nicklas |
458 |
{ |
6741 |
17 Feb 15 |
nicklas |
459 |
String msg = "List size is " + bl.getSize() + " but query returned " + l.size() + " members"; |
6741 |
17 Feb 15 |
nicklas |
460 |
if (expectedResults >= 0) |
6741 |
17 Feb 15 |
nicklas |
461 |
{ |
6741 |
17 Feb 15 |
nicklas |
462 |
msg += " (expected " + expectedResults +")"; |
6741 |
17 Feb 15 |
nicklas |
463 |
} |
6741 |
17 Feb 15 |
nicklas |
464 |
throw new BaseException(msg); |
6741 |
17 Feb 15 |
nicklas |
465 |
} |
6739 |
17 Feb 15 |
nicklas |
466 |
if (expectedResults >= 0 && expectedResults != l.size()) |
6739 |
17 Feb 15 |
nicklas |
467 |
{ |
6739 |
17 Feb 15 |
nicklas |
468 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
6739 |
17 Feb 15 |
nicklas |
469 |
} |
6739 |
17 Feb 15 |
nicklas |
470 |
write("--List members in item list OK (" + l.size() + ")"); |
6739 |
17 Feb 15 |
nicklas |
471 |
} |
6739 |
17 Feb 15 |
nicklas |
472 |
catch (Throwable ex) |
6739 |
17 Feb 15 |
nicklas |
473 |
{ |
6739 |
17 Feb 15 |
nicklas |
474 |
write("--List members in item list FAILED"); |
6739 |
17 Feb 15 |
nicklas |
475 |
ex.printStackTrace(); |
6739 |
17 Feb 15 |
nicklas |
476 |
ok = false; |
6739 |
17 Feb 15 |
nicklas |
477 |
} |
6739 |
17 Feb 15 |
nicklas |
478 |
finally |
6739 |
17 Feb 15 |
nicklas |
479 |
{ |
6739 |
17 Feb 15 |
nicklas |
480 |
if (dc != null) dc.close(); |
6739 |
17 Feb 15 |
nicklas |
481 |
} |
6739 |
17 Feb 15 |
nicklas |
482 |
} |
6739 |
17 Feb 15 |
nicklas |
483 |
|
6891 |
29 Apr 15 |
nicklas |
484 |
static int test_union(int toId, int expectedSize, int... fromId) |
6739 |
17 Feb 15 |
nicklas |
485 |
{ |
6891 |
29 Apr 15 |
nicklas |
486 |
if (toId == 0) return 0; |
6739 |
17 Feb 15 |
nicklas |
487 |
DbControl dc = null; |
6891 |
29 Apr 15 |
nicklas |
488 |
int id = 0; |
6739 |
17 Feb 15 |
nicklas |
489 |
try |
6739 |
17 Feb 15 |
nicklas |
490 |
{ |
6739 |
17 Feb 15 |
nicklas |
491 |
dc = TestUtil.getDbControl(); |
6891 |
29 Apr 15 |
nicklas |
492 |
|
6891 |
29 Apr 15 |
nicklas |
493 |
BioSource bs = BioSource.getNew(dc); |
6891 |
29 Apr 15 |
nicklas |
494 |
dc.saveItem(bs); |
6891 |
29 Apr 15 |
nicklas |
495 |
|
6739 |
17 Feb 15 |
nicklas |
496 |
ItemList to = ItemList.getById(dc, toId); |
6739 |
17 Feb 15 |
nicklas |
497 |
List<ItemList> from = new ArrayList<ItemList>(fromId.length); |
6739 |
17 Feb 15 |
nicklas |
498 |
for (int rlId : fromId) |
6739 |
17 Feb 15 |
nicklas |
499 |
{ |
6891 |
29 Apr 15 |
nicklas |
500 |
ItemList list = ItemList.getById(dc, rlId); |
6891 |
29 Apr 15 |
nicklas |
501 |
list.add(bs); |
6891 |
29 Apr 15 |
nicklas |
502 |
from.add(list); |
6739 |
17 Feb 15 |
nicklas |
503 |
} |
6739 |
17 Feb 15 |
nicklas |
504 |
to.addUnion(from); |
6739 |
17 Feb 15 |
nicklas |
505 |
dc.commit(); |
6891 |
29 Apr 15 |
nicklas |
506 |
id = bs.getId(); |
6739 |
17 Feb 15 |
nicklas |
507 |
if (expectedSize != to.getSize()) |
6739 |
17 Feb 15 |
nicklas |
508 |
{ |
6739 |
17 Feb 15 |
nicklas |
509 |
throw new BaseException("Incorrect size; expected=" + expectedSize + "; actual=" + to.getSize()); |
6739 |
17 Feb 15 |
nicklas |
510 |
} |
6739 |
17 Feb 15 |
nicklas |
511 |
write("--Create union OK (size=" + expectedSize + ")"); |
6739 |
17 Feb 15 |
nicklas |
512 |
} |
6739 |
17 Feb 15 |
nicklas |
513 |
catch (Throwable ex) |
6739 |
17 Feb 15 |
nicklas |
514 |
{ |
6739 |
17 Feb 15 |
nicklas |
515 |
write ("--Create union FAILED"); |
6739 |
17 Feb 15 |
nicklas |
516 |
ex.printStackTrace(); |
6739 |
17 Feb 15 |
nicklas |
517 |
ok = false; |
6739 |
17 Feb 15 |
nicklas |
518 |
} |
6739 |
17 Feb 15 |
nicklas |
519 |
finally |
6739 |
17 Feb 15 |
nicklas |
520 |
{ |
6739 |
17 Feb 15 |
nicklas |
521 |
if (dc != null) dc.close(); |
6739 |
17 Feb 15 |
nicklas |
522 |
} |
6891 |
29 Apr 15 |
nicklas |
523 |
return id; |
6739 |
17 Feb 15 |
nicklas |
524 |
} |
6739 |
17 Feb 15 |
nicklas |
525 |
|
6891 |
29 Apr 15 |
nicklas |
526 |
static int test_intersect(int toId, int expectedSize, int... fromId) |
6739 |
17 Feb 15 |
nicklas |
527 |
{ |
6891 |
29 Apr 15 |
nicklas |
528 |
if (toId == 0) return 0; |
6739 |
17 Feb 15 |
nicklas |
529 |
DbControl dc = null; |
6891 |
29 Apr 15 |
nicklas |
530 |
int id = 0; |
6739 |
17 Feb 15 |
nicklas |
531 |
try |
6739 |
17 Feb 15 |
nicklas |
532 |
{ |
6739 |
17 Feb 15 |
nicklas |
533 |
dc = TestUtil.getDbControl(); |
6891 |
29 Apr 15 |
nicklas |
534 |
|
6891 |
29 Apr 15 |
nicklas |
535 |
BioSource bs = BioSource.getNew(dc); |
6891 |
29 Apr 15 |
nicklas |
536 |
dc.saveItem(bs); |
6891 |
29 Apr 15 |
nicklas |
537 |
|
6739 |
17 Feb 15 |
nicklas |
538 |
ItemList to = ItemList.getById(dc, toId); |
6739 |
17 Feb 15 |
nicklas |
539 |
List<ItemList> from = new ArrayList<ItemList>(fromId.length); |
6739 |
17 Feb 15 |
nicklas |
540 |
for (int rlId : fromId) |
6739 |
17 Feb 15 |
nicklas |
541 |
{ |
6891 |
29 Apr 15 |
nicklas |
542 |
ItemList list = ItemList.getById(dc, rlId); |
6891 |
29 Apr 15 |
nicklas |
543 |
list.add(bs); |
6891 |
29 Apr 15 |
nicklas |
544 |
from.add(list); |
6739 |
17 Feb 15 |
nicklas |
545 |
} |
6739 |
17 Feb 15 |
nicklas |
546 |
to.addIntersection(from); |
6739 |
17 Feb 15 |
nicklas |
547 |
dc.commit(); |
6891 |
29 Apr 15 |
nicklas |
548 |
id = bs.getId(); |
6739 |
17 Feb 15 |
nicklas |
549 |
if (expectedSize != to.getSize()) |
6739 |
17 Feb 15 |
nicklas |
550 |
{ |
6739 |
17 Feb 15 |
nicklas |
551 |
throw new BaseException("Incorrect size; expected=" + expectedSize + "; actual=" + to.getSize()); |
6739 |
17 Feb 15 |
nicklas |
552 |
} |
6739 |
17 Feb 15 |
nicklas |
553 |
write("--Create intersection OK (size=" + expectedSize + ")"); |
6739 |
17 Feb 15 |
nicklas |
554 |
} |
6739 |
17 Feb 15 |
nicklas |
555 |
catch (Throwable ex) |
6739 |
17 Feb 15 |
nicklas |
556 |
{ |
6739 |
17 Feb 15 |
nicklas |
557 |
write ("--Create intersection FAILED"); |
6739 |
17 Feb 15 |
nicklas |
558 |
ex.printStackTrace(); |
6739 |
17 Feb 15 |
nicklas |
559 |
ok = false; |
6739 |
17 Feb 15 |
nicklas |
560 |
} |
6739 |
17 Feb 15 |
nicklas |
561 |
finally |
6739 |
17 Feb 15 |
nicklas |
562 |
{ |
6739 |
17 Feb 15 |
nicklas |
563 |
if (dc != null) dc.close(); |
6739 |
17 Feb 15 |
nicklas |
564 |
} |
6891 |
29 Apr 15 |
nicklas |
565 |
return id; |
6739 |
17 Feb 15 |
nicklas |
566 |
} |
6739 |
17 Feb 15 |
nicklas |
567 |
|
6739 |
17 Feb 15 |
nicklas |
568 |
static void test_remove(int toId, int baseId, int expectedSize, int... complementId) |
6739 |
17 Feb 15 |
nicklas |
569 |
{ |
6739 |
17 Feb 15 |
nicklas |
570 |
if (toId == 0) return; |
6739 |
17 Feb 15 |
nicklas |
571 |
DbControl dc = null; |
6739 |
17 Feb 15 |
nicklas |
572 |
try |
6739 |
17 Feb 15 |
nicklas |
573 |
{ |
6739 |
17 Feb 15 |
nicklas |
574 |
dc = TestUtil.getDbControl(); |
6739 |
17 Feb 15 |
nicklas |
575 |
ItemList to = ItemList.getById(dc, toId); |
6739 |
17 Feb 15 |
nicklas |
576 |
to.addAll(ItemList.getById(dc, baseId)); |
6739 |
17 Feb 15 |
nicklas |
577 |
List<ItemList> from = new ArrayList<ItemList>(complementId.length); |
6739 |
17 Feb 15 |
nicklas |
578 |
for (int rlId : complementId) |
6739 |
17 Feb 15 |
nicklas |
579 |
{ |
6739 |
17 Feb 15 |
nicklas |
580 |
from.add(ItemList.getById(dc, rlId)); |
6739 |
17 Feb 15 |
nicklas |
581 |
} |
6739 |
17 Feb 15 |
nicklas |
582 |
to.removeUnion(from); |
6739 |
17 Feb 15 |
nicklas |
583 |
dc.commit(); |
6739 |
17 Feb 15 |
nicklas |
584 |
if (expectedSize != to.getSize()) |
6739 |
17 Feb 15 |
nicklas |
585 |
{ |
6739 |
17 Feb 15 |
nicklas |
586 |
throw new BaseException("Incorrect size; expected=" + expectedSize + "; actual=" + to.getSize()); |
6739 |
17 Feb 15 |
nicklas |
587 |
} |
6739 |
17 Feb 15 |
nicklas |
588 |
write("--Remove items OK (size=" + expectedSize + ")"); |
6739 |
17 Feb 15 |
nicklas |
589 |
} |
6739 |
17 Feb 15 |
nicklas |
590 |
catch (Throwable ex) |
6739 |
17 Feb 15 |
nicklas |
591 |
{ |
6739 |
17 Feb 15 |
nicklas |
592 |
write ("--Remove items FAILED"); |
6739 |
17 Feb 15 |
nicklas |
593 |
ex.printStackTrace(); |
6739 |
17 Feb 15 |
nicklas |
594 |
ok = false; |
6739 |
17 Feb 15 |
nicklas |
595 |
} |
6739 |
17 Feb 15 |
nicklas |
596 |
finally |
6739 |
17 Feb 15 |
nicklas |
597 |
{ |
6739 |
17 Feb 15 |
nicklas |
598 |
if (dc != null) dc.close(); |
6739 |
17 Feb 15 |
nicklas |
599 |
} |
6739 |
17 Feb 15 |
nicklas |
600 |
} |
6739 |
17 Feb 15 |
nicklas |
601 |
|
6739 |
17 Feb 15 |
nicklas |
602 |
static void test_retain(int toId, int baseId, int expectedSize, int... complementId) |
6739 |
17 Feb 15 |
nicklas |
603 |
{ |
6739 |
17 Feb 15 |
nicklas |
604 |
if (toId == 0) return; |
6739 |
17 Feb 15 |
nicklas |
605 |
DbControl dc = null; |
6739 |
17 Feb 15 |
nicklas |
606 |
try |
6739 |
17 Feb 15 |
nicklas |
607 |
{ |
6739 |
17 Feb 15 |
nicklas |
608 |
dc = TestUtil.getDbControl(); |
6739 |
17 Feb 15 |
nicklas |
609 |
ItemList to = ItemList.getById(dc, toId); |
6739 |
17 Feb 15 |
nicklas |
610 |
to.addAll(ItemList.getById(dc, baseId)); |
6739 |
17 Feb 15 |
nicklas |
611 |
List<ItemList> from = new ArrayList<ItemList>(complementId.length); |
6739 |
17 Feb 15 |
nicklas |
612 |
for (int rlId : complementId) |
6739 |
17 Feb 15 |
nicklas |
613 |
{ |
6739 |
17 Feb 15 |
nicklas |
614 |
from.add(ItemList.getById(dc, rlId)); |
6739 |
17 Feb 15 |
nicklas |
615 |
} |
6739 |
17 Feb 15 |
nicklas |
616 |
to.retainUnion(from); |
6739 |
17 Feb 15 |
nicklas |
617 |
dc.commit(); |
6739 |
17 Feb 15 |
nicklas |
618 |
if (expectedSize != to.getSize()) |
6739 |
17 Feb 15 |
nicklas |
619 |
{ |
6739 |
17 Feb 15 |
nicklas |
620 |
throw new BaseException("Incorrect size; expected=" + expectedSize + "; actual=" + to.getSize()); |
6739 |
17 Feb 15 |
nicklas |
621 |
} |
6739 |
17 Feb 15 |
nicklas |
622 |
write("--Retain items OK (size=" + expectedSize + ")"); |
6739 |
17 Feb 15 |
nicklas |
623 |
} |
6739 |
17 Feb 15 |
nicklas |
624 |
catch (Throwable ex) |
6739 |
17 Feb 15 |
nicklas |
625 |
{ |
6739 |
17 Feb 15 |
nicklas |
626 |
write ("--Retain items FAILED"); |
6739 |
17 Feb 15 |
nicklas |
627 |
ex.printStackTrace(); |
6739 |
17 Feb 15 |
nicklas |
628 |
ok = false; |
6739 |
17 Feb 15 |
nicklas |
629 |
} |
6739 |
17 Feb 15 |
nicklas |
630 |
finally |
6739 |
17 Feb 15 |
nicklas |
631 |
{ |
6739 |
17 Feb 15 |
nicklas |
632 |
if (dc != null) dc.close(); |
6739 |
17 Feb 15 |
nicklas |
633 |
} |
6739 |
17 Feb 15 |
nicklas |
634 |
} |
6739 |
17 Feb 15 |
nicklas |
635 |
|
6739 |
17 Feb 15 |
nicklas |
636 |
|
6739 |
17 Feb 15 |
nicklas |
637 |
} |
6739 |
17 Feb 15 |
nicklas |
638 |
|