744 |
10 Jun 05 |
nicklas |
1 |
/* |
744 |
10 Jun 05 |
nicklas |
$Id$ |
744 |
10 Jun 05 |
nicklas |
3 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 Johan Enell, Nicklas Nordborg |
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg |
3675 |
16 Aug 07 |
jari |
Copyright (C) 2007 Nicklas Nordborg |
744 |
10 Jun 05 |
nicklas |
7 |
|
2304 |
22 May 06 |
jari |
This file is part of BASE - BioArray Software Environment. |
2304 |
22 May 06 |
jari |
Available at http://base.thep.lu.se/ |
744 |
10 Jun 05 |
nicklas |
10 |
|
744 |
10 Jun 05 |
nicklas |
BASE is free software; you can redistribute it and/or |
744 |
10 Jun 05 |
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 |
744 |
10 Jun 05 |
nicklas |
of the License, or (at your option) any later version. |
744 |
10 Jun 05 |
nicklas |
15 |
|
744 |
10 Jun 05 |
nicklas |
BASE is distributed in the hope that it will be useful, |
744 |
10 Jun 05 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
744 |
10 Jun 05 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
744 |
10 Jun 05 |
nicklas |
GNU General Public License for more details. |
744 |
10 Jun 05 |
nicklas |
20 |
|
744 |
10 Jun 05 |
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/>. |
744 |
10 Jun 05 |
nicklas |
23 |
*/ |
744 |
10 Jun 05 |
nicklas |
24 |
|
747 |
10 Jun 05 |
nicklas |
25 |
import net.sf.basedb.core.*; |
7670 |
21 Mar 19 |
nicklas |
26 |
import net.sf.basedb.core.Annotation.Source; |
7245 |
01 Dec 16 |
nicklas |
27 |
import net.sf.basedb.core.snapshot.AnnotationSnapshot; |
7245 |
01 Dec 16 |
nicklas |
28 |
import net.sf.basedb.core.snapshot.AnnotationTypeFilter; |
7245 |
01 Dec 16 |
nicklas |
29 |
import net.sf.basedb.core.snapshot.SnapshotManager; |
7245 |
01 Dec 16 |
nicklas |
30 |
import net.sf.basedb.util.EqualsHelper; |
747 |
10 Jun 05 |
nicklas |
31 |
|
5430 |
28 Sep 10 |
nicklas |
32 |
import java.util.Collections; |
744 |
10 Jun 05 |
nicklas |
33 |
import java.util.Date; |
747 |
10 Jun 05 |
nicklas |
34 |
import java.util.List; |
747 |
10 Jun 05 |
nicklas |
35 |
import java.util.ArrayList; |
843 |
29 Jun 05 |
nicklas |
36 |
import java.util.Arrays; |
744 |
10 Jun 05 |
nicklas |
37 |
|
744 |
10 Jun 05 |
nicklas |
38 |
public class TestAnnotation |
744 |
10 Jun 05 |
nicklas |
39 |
{ |
744 |
10 Jun 05 |
nicklas |
40 |
static boolean ok = true; |
744 |
10 Jun 05 |
nicklas |
41 |
|
744 |
10 Jun 05 |
nicklas |
42 |
public static void main(String[] args) |
744 |
10 Jun 05 |
nicklas |
43 |
{ |
744 |
10 Jun 05 |
nicklas |
44 |
TestUtil.checkArgs(args); |
744 |
10 Jun 05 |
nicklas |
45 |
TestUtil.begin(); |
744 |
10 Jun 05 |
nicklas |
46 |
ok = test_all(); |
744 |
10 Jun 05 |
nicklas |
47 |
TestUtil.stop(); |
744 |
10 Jun 05 |
nicklas |
48 |
} |
744 |
10 Jun 05 |
nicklas |
49 |
|
744 |
10 Jun 05 |
nicklas |
50 |
static boolean test_all() |
744 |
10 Jun 05 |
nicklas |
51 |
{ |
744 |
10 Jun 05 |
nicklas |
52 |
write("++Testing annotations"); |
744 |
10 Jun 05 |
nicklas |
53 |
write_header(); |
4544 |
25 Sep 08 |
nicklas |
54 |
|
4544 |
25 Sep 08 |
nicklas |
55 |
int celsiusId = TestUnit.test_load_by_symbol(SystemItems.getId(Quantity.TEMPERATURE), "C"); |
4544 |
25 Sep 08 |
nicklas |
56 |
int fahrenheitId = TestUnit.test_load_by_symbol(SystemItems.getId(Quantity.TEMPERATURE), "F"); |
4544 |
25 Sep 08 |
nicklas |
57 |
int meterId = TestUnit.test_load_by_symbol(SystemItems.getId(Quantity.LENGTH), "m"); |
4544 |
25 Sep 08 |
nicklas |
58 |
int millimeterId = TestUnit.test_load_by_symbol(SystemItems.getId(Quantity.LENGTH), "mm"); |
4544 |
25 Sep 08 |
nicklas |
59 |
|
744 |
10 Jun 05 |
nicklas |
// Create annotation types and array design |
4544 |
25 Sep 08 |
nicklas |
61 |
int intId = TestAnnotationType.test_create(null, Type.INT, 0, 10, null, Item.ARRAYDESIGN, 1, null, true); |
4544 |
25 Sep 08 |
nicklas |
62 |
int longId = TestAnnotationType.test_create(null, Type.LONG, 0, 1056567756767l, null, Item.ARRAYDESIGN, 1, null, true); |
4544 |
25 Sep 08 |
nicklas |
63 |
int floatId = TestAnnotationType.test_create("Temperature", Type.FLOAT, celsiusId, 10.1f, null, Item.ARRAYDESIGN, 1, null, true); |
4544 |
25 Sep 08 |
nicklas |
64 |
int doubleId = TestAnnotationType.test_create("Size", Type.DOUBLE, meterId, 8.13454646d, null, Item.ARRAYDESIGN, 1, null, true); |
4544 |
25 Sep 08 |
nicklas |
65 |
int dateId = TestAnnotationType.test_create(null, Type.DATE, 0, new Date(), null, Item.ARRAYDESIGN, 1, null, true); |
5422 |
22 Sep 10 |
nicklas |
66 |
int timestampId = TestAnnotationType.test_create(null, Type.TIMESTAMP, 0, new Date(), null, Item.ARRAYDESIGN, 1, null, true); |
4544 |
25 Sep 08 |
nicklas |
67 |
int textId = TestAnnotationType.test_create(null, Type.TEXT, 0, "default value", null, Item.ARRAYDESIGN, 1, null, true); |
4544 |
25 Sep 08 |
nicklas |
68 |
int stringId = TestAnnotationType.test_create(null, Type.STRING, 0, "default value", null, Item.ARRAYDESIGN, 1, null, true); |
4544 |
25 Sep 08 |
nicklas |
69 |
int booleanId = TestAnnotationType.test_create(null, Type.BOOLEAN, 0, true, null, Item.ARRAYDESIGN, 1, null, true); |
4544 |
25 Sep 08 |
nicklas |
70 |
int enumId = TestAnnotationType.test_create(null, Type.INT, 0, 3, null, Item.ARRAYDESIGN, 1, new Object[] { 1, 2, 3, 4, 5 }, false); |
3820 |
12 Oct 07 |
nicklas |
71 |
int arrayDesignId = TestArrayDesign.test_create(Platform.GENERIC, true); |
4544 |
25 Sep 08 |
nicklas |
72 |
int arrayDesignId2 = TestArrayDesign.test_create(Platform.AFFYMETRIX, true); |
7296 |
20 Feb 17 |
nicklas |
73 |
int arrayDesignId3 = TestArrayDesign.test_create(Platform.AFFYMETRIX, true); |
744 |
10 Jun 05 |
nicklas |
74 |
|
7245 |
01 Dec 16 |
nicklas |
// Create project and a project-specific annotation |
7245 |
01 Dec 16 |
nicklas |
76 |
int project1 = TestProject.test_create("Project #1", false); |
7245 |
01 Dec 16 |
nicklas |
77 |
int project2 = TestProject.test_create("Project #2", false); |
7245 |
01 Dec 16 |
nicklas |
78 |
int projectSpecificId = TestAnnotationType.test_create("Project data", Type.STRING, 0, null, null, Item.ARRAYDESIGN, 1, null, true); |
7245 |
01 Dec 16 |
nicklas |
79 |
TestAnnotationType.test_set_project_annotations(projectSpecificId, true); |
7245 |
01 Dec 16 |
nicklas |
80 |
|
744 |
10 Jun 05 |
nicklas |
// Annotate the array design and list the annotations |
4544 |
25 Sep 08 |
nicklas |
82 |
int intAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, intId, 0, 10); |
4544 |
25 Sep 08 |
nicklas |
83 |
int longAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, longId, 0, 1023456789012345l); |
4544 |
25 Sep 08 |
nicklas |
84 |
int floatAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, floatId, celsiusId, 11.365789456857f); |
4544 |
25 Sep 08 |
nicklas |
85 |
int doubleAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, doubleId, meterId, 11.365789456857d); |
4544 |
25 Sep 08 |
nicklas |
86 |
int floatAnnotationId2 = test_annotatate(Item.ARRAYDESIGN, arrayDesignId2, floatId, fahrenheitId, 11.365789456857f); |
4544 |
25 Sep 08 |
nicklas |
87 |
int doubleAnnotationId2 = test_annotatate(Item.ARRAYDESIGN, arrayDesignId2, doubleId, millimeterId, 11.365789456857d); |
4544 |
25 Sep 08 |
nicklas |
88 |
int dateAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, dateId, 0, new Date()); |
5422 |
22 Sep 10 |
nicklas |
89 |
int timestampAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, timestampId, 0, new Date()); |
4544 |
25 Sep 08 |
nicklas |
90 |
int textAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, textId, 0, "a text annotation"); |
4544 |
25 Sep 08 |
nicklas |
91 |
int stringAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, stringId, 0, "a string annotation"); |
4544 |
25 Sep 08 |
nicklas |
92 |
int booleanAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, booleanId, 0, false); |
4544 |
25 Sep 08 |
nicklas |
93 |
int enumAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, enumId, 0, 4); |
7106 |
14 Mar 16 |
nicklas |
94 |
|
7106 |
14 Mar 16 |
nicklas |
// Testing 'null' list and 'empty' list |
7106 |
14 Mar 16 |
nicklas |
96 |
int shouldfail1 = test_annotatate(Item.ARRAYDESIGN, arrayDesignId2, stringId, 0, (Object[])null); |
7106 |
14 Mar 16 |
nicklas |
97 |
int shouldfail2 = test_annotatate(Item.ARRAYDESIGN, arrayDesignId2, textId, 0, new Object[0]); |
7106 |
14 Mar 16 |
nicklas |
98 |
|
6921 |
26 May 15 |
nicklas |
99 |
test_list_annotations(Item.ARRAYDESIGN, arrayDesignId, null, 10); |
6921 |
26 May 15 |
nicklas |
100 |
test_list_annotations(Item.ARRAYDESIGN, arrayDesignId2, Annotation.Source.PRIMARY, 2); |
798 |
20 Jun 05 |
nicklas |
101 |
|
6921 |
26 May 15 |
nicklas |
// Test: inherit and clone annotations |
5748 |
19 Sep 11 |
nicklas |
103 |
int rawBioAssayId = TestRawBioAssay.test_create(Platform.GENERIC, "genepix", null, 0, 0, 0, 0, arrayDesignId, false); |
7290 |
31 Jan 17 |
nicklas |
104 |
int rawBioAssayId2 = TestRawBioAssay.test_create(Platform.GENERIC, "genepix", null, 0, 0, 0, 0, arrayDesignId2, false); |
6921 |
26 May 15 |
nicklas |
105 |
test_inherit_annotation(Item.RAWBIOASSAY, rawBioAssayId, intAnnotationId, false); |
6921 |
26 May 15 |
nicklas |
106 |
int clonedId = test_inherit_annotation(Item.RAWBIOASSAY, rawBioAssayId, stringAnnotationId, true); |
6921 |
26 May 15 |
nicklas |
107 |
test_modify_clone(clonedId, 0, "a cloned annotation"); |
6921 |
26 May 15 |
nicklas |
108 |
test_list_annotations(Item.RAWBIOASSAY, rawBioAssayId, null, 2); |
744 |
10 Jun 05 |
nicklas |
109 |
|
6911 |
20 May 15 |
nicklas |
110 |
test_inherit_annotationset(Item.RAWBIOASSAY, rawBioAssayId, Item.ARRAYDESIGN, arrayDesignId, 8); |
6921 |
26 May 15 |
nicklas |
111 |
test_list_annotations(Item.RAWBIOASSAY, rawBioAssayId, Annotation.Source.INHERITED, 9); |
6911 |
20 May 15 |
nicklas |
112 |
|
7245 |
01 Dec 16 |
nicklas |
// Test project specific annotations -- set a default value and a project-specific for "Project #1" |
7260 |
12 Dec 16 |
nicklas |
114 |
int defaultProjectAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId2, projectSpecificId, 0, "default value"); |
7290 |
31 Jan 17 |
nicklas |
115 |
test_inherit_annotation(Item.RAWBIOASSAY, rawBioAssayId2, defaultProjectAnnotationId, false); |
7290 |
31 Jan 17 |
nicklas |
116 |
|
7245 |
01 Dec 16 |
nicklas |
117 |
TestProject.test_activate_project(project1, null); |
7245 |
01 Dec 16 |
nicklas |
118 |
int project1AnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId2, projectSpecificId, 0, "project 1 value"); |
7290 |
31 Jan 17 |
nicklas |
119 |
test_inherit_annotation(Item.RAWBIOASSAY, rawBioAssayId2, project1AnnotationId, false); |
7296 |
20 Feb 17 |
nicklas |
120 |
|
7245 |
01 Dec 16 |
nicklas |
121 |
TestProject.test_noactive_project(); |
7290 |
31 Jan 17 |
nicklas |
122 |
|
7290 |
31 Jan 17 |
nicklas |
123 |
if (defaultProjectAnnotationId == project1AnnotationId) |
7290 |
31 Jan 17 |
nicklas |
124 |
{ |
7290 |
31 Jan 17 |
nicklas |
125 |
write("--Create project-specific annotation value FAILED (test returns the default value"); |
7290 |
31 Jan 17 |
nicklas |
126 |
ok = false; |
7290 |
31 Jan 17 |
nicklas |
127 |
} |
7296 |
20 Feb 17 |
nicklas |
128 |
|
7245 |
01 Dec 16 |
nicklas |
// Check that the annotation values are as expected |
7246 |
01 Dec 16 |
nicklas |
130 |
test_project_annotation(Item.ARRAYDESIGN, arrayDesignId2, projectSpecificId, "default value", "project 1 value"); |
7245 |
01 Dec 16 |
nicklas |
131 |
TestProject.test_activate_project(project1, null); |
7246 |
01 Dec 16 |
nicklas |
132 |
test_project_annotation(Item.ARRAYDESIGN, arrayDesignId2, projectSpecificId, "project 1 value", "default value"); |
7245 |
01 Dec 16 |
nicklas |
133 |
TestProject.test_activate_project(project2, null); |
7246 |
01 Dec 16 |
nicklas |
134 |
test_project_annotation(Item.ARRAYDESIGN, arrayDesignId2, projectSpecificId, "default value", "project 1 value"); |
7296 |
20 Feb 17 |
nicklas |
135 |
TestProject.test_noactive_project(); |
7296 |
20 Feb 17 |
nicklas |
136 |
|
7296 |
20 Feb 17 |
nicklas |
// Test new API for working with project-specific values |
7296 |
20 Feb 17 |
nicklas |
// Create project-specific value when no project is active |
7296 |
20 Feb 17 |
nicklas |
139 |
test_annotatate_forceproject(Item.ARRAYDESIGN, arrayDesignId3, projectSpecificId, project1, "project 1 value (3)"); |
7290 |
31 Jan 17 |
nicklas |
140 |
|
7296 |
20 Feb 17 |
nicklas |
// Create default value when a project is active |
7296 |
20 Feb 17 |
nicklas |
142 |
TestProject.test_activate_project(project1, null); |
7296 |
20 Feb 17 |
nicklas |
143 |
test_annotatate_forceproject(Item.ARRAYDESIGN, arrayDesignId3, projectSpecificId, 0, "default value (3)"); |
7296 |
20 Feb 17 |
nicklas |
144 |
|
7296 |
20 Feb 17 |
nicklas |
// Check the values |
7296 |
20 Feb 17 |
nicklas |
146 |
test_project_annotation(Item.ARRAYDESIGN, arrayDesignId3, projectSpecificId, "project 1 value (3)", "default value (3)"); |
7296 |
20 Feb 17 |
nicklas |
147 |
TestProject.test_activate_project(project2, null); |
7296 |
20 Feb 17 |
nicklas |
148 |
test_project_annotation(Item.ARRAYDESIGN, arrayDesignId3, projectSpecificId, "default value (3)", "project 1 value (3)"); |
7296 |
20 Feb 17 |
nicklas |
149 |
TestProject.test_noactive_project(); |
7296 |
20 Feb 17 |
nicklas |
150 |
test_project_annotation(Item.ARRAYDESIGN, arrayDesignId3, projectSpecificId, "default value (3)", "project 1 value (3)"); |
7290 |
31 Jan 17 |
nicklas |
151 |
|
7296 |
20 Feb 17 |
nicklas |
// Update project-specific value when no project is active |
7296 |
20 Feb 17 |
nicklas |
153 |
test_annotatate_forceproject(Item.ARRAYDESIGN, arrayDesignId3, projectSpecificId, project1, "project 1 value (updated)"); |
7296 |
20 Feb 17 |
nicklas |
// Update default value when a project is active |
7296 |
20 Feb 17 |
nicklas |
155 |
TestProject.test_activate_project(project1, null); |
7296 |
20 Feb 17 |
nicklas |
156 |
test_annotatate_forceproject(Item.ARRAYDESIGN, arrayDesignId3, projectSpecificId, 0, "default value (updated)"); |
7296 |
20 Feb 17 |
nicklas |
157 |
|
7296 |
20 Feb 17 |
nicklas |
// Check the values |
7296 |
20 Feb 17 |
nicklas |
159 |
test_project_annotation(Item.ARRAYDESIGN, arrayDesignId3, projectSpecificId, "project 1 value (updated)", "default value (updated)"); |
7296 |
20 Feb 17 |
nicklas |
160 |
TestProject.test_activate_project(project2, null); |
7296 |
20 Feb 17 |
nicklas |
161 |
test_project_annotation(Item.ARRAYDESIGN, arrayDesignId3, projectSpecificId, "default value (updated)", "project 1 value (updated)"); |
7296 |
20 Feb 17 |
nicklas |
162 |
TestProject.test_noactive_project(); |
7296 |
20 Feb 17 |
nicklas |
163 |
test_project_annotation(Item.ARRAYDESIGN, arrayDesignId3, projectSpecificId, "default value (updated)", "project 1 value (updated)"); |
7296 |
20 Feb 17 |
nicklas |
164 |
|
7290 |
31 Jan 17 |
nicklas |
165 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
7290 |
31 Jan 17 |
nicklas |
166 |
|
7290 |
31 Jan 17 |
nicklas |
// Remove project-specific annotation |
7290 |
31 Jan 17 |
nicklas |
168 |
test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId2, projectSpecificId); |
7245 |
01 Dec 16 |
nicklas |
169 |
TestProject.test_noactive_project(); |
7290 |
31 Jan 17 |
nicklas |
170 |
test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId2, projectSpecificId); |
7245 |
01 Dec 16 |
nicklas |
171 |
|
6918 |
26 May 15 |
nicklas |
// Remove an annotation that is inherited |
6918 |
26 May 15 |
nicklas |
173 |
test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, intId); |
6921 |
26 May 15 |
nicklas |
174 |
test_list_annotations(Item.RAWBIOASSAY, rawBioAssayId, null, 9); |
6918 |
26 May 15 |
nicklas |
175 |
|
6911 |
20 May 15 |
nicklas |
176 |
TestRawBioAssay.test_delete(rawBioAssayId); |
7290 |
31 Jan 17 |
nicklas |
177 |
TestRawBioAssay.test_delete(rawBioAssayId2); |
1529 |
27 Oct 05 |
nicklas |
178 |
|
744 |
10 Jun 05 |
nicklas |
// Remove the annotations |
3973 |
16 Nov 07 |
nicklas |
180 |
test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, intId); |
3973 |
16 Nov 07 |
nicklas |
181 |
test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, longId); |
3973 |
16 Nov 07 |
nicklas |
182 |
test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, floatId); |
3973 |
16 Nov 07 |
nicklas |
183 |
test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, doubleId); |
3973 |
16 Nov 07 |
nicklas |
184 |
test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, dateId); |
5422 |
22 Sep 10 |
nicklas |
185 |
test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, timestampId); |
3973 |
16 Nov 07 |
nicklas |
186 |
test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, textId); |
3973 |
16 Nov 07 |
nicklas |
187 |
test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, stringId); |
3973 |
16 Nov 07 |
nicklas |
188 |
test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, booleanId); |
3973 |
16 Nov 07 |
nicklas |
189 |
test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, enumId); |
6921 |
26 May 15 |
nicklas |
190 |
test_list_annotations(Item.ARRAYDESIGN, arrayDesignId, null, 0); |
744 |
10 Jun 05 |
nicklas |
191 |
|
744 |
10 Jun 05 |
nicklas |
// Delete annotation types and array design |
744 |
10 Jun 05 |
nicklas |
193 |
TestArrayDesign.test_delete(arrayDesignId); |
4544 |
25 Sep 08 |
nicklas |
194 |
TestArrayDesign.test_delete(arrayDesignId2); |
7296 |
20 Feb 17 |
nicklas |
195 |
TestArrayDesign.test_delete(arrayDesignId3); |
7245 |
01 Dec 16 |
nicklas |
196 |
TestAnnotationType.test_delete(projectSpecificId); |
744 |
10 Jun 05 |
nicklas |
197 |
TestAnnotationType.test_delete(intId); |
936 |
14 Jul 05 |
nicklas |
198 |
TestAnnotationType.test_delete(longId); |
744 |
10 Jun 05 |
nicklas |
199 |
TestAnnotationType.test_delete(floatId); |
936 |
14 Jul 05 |
nicklas |
200 |
TestAnnotationType.test_delete(doubleId); |
744 |
10 Jun 05 |
nicklas |
201 |
TestAnnotationType.test_delete(dateId); |
5422 |
22 Sep 10 |
nicklas |
202 |
TestAnnotationType.test_delete(timestampId); |
744 |
10 Jun 05 |
nicklas |
203 |
TestAnnotationType.test_delete(textId); |
843 |
29 Jun 05 |
nicklas |
204 |
TestAnnotationType.test_delete(stringId); |
843 |
29 Jun 05 |
nicklas |
205 |
TestAnnotationType.test_delete(booleanId); |
856 |
01 Jul 05 |
nicklas |
206 |
TestAnnotationType.test_delete(enumId); |
7245 |
01 Dec 16 |
nicklas |
207 |
|
7245 |
01 Dec 16 |
nicklas |
208 |
TestProject.test_delete(project1); |
7245 |
01 Dec 16 |
nicklas |
209 |
TestProject.test_delete(project2); |
744 |
10 Jun 05 |
nicklas |
210 |
|
744 |
10 Jun 05 |
nicklas |
211 |
write("++Testing annotations "+(ok ? "OK" : "Failed")+"\n"); |
744 |
10 Jun 05 |
nicklas |
212 |
return ok; |
744 |
10 Jun 05 |
nicklas |
213 |
} |
744 |
10 Jun 05 |
nicklas |
214 |
|
4544 |
25 Sep 08 |
nicklas |
215 |
static int test_annotatate(Item itemType, int itemId, int annotationTypeId, int unitId, Object... value) |
744 |
10 Jun 05 |
nicklas |
216 |
{ |
3973 |
16 Nov 07 |
nicklas |
217 |
if (itemId == 0 || annotationTypeId == 0) return 0; |
744 |
10 Jun 05 |
nicklas |
218 |
int id = 0; |
7106 |
14 Mar 16 |
nicklas |
219 |
boolean shouldFail = value == null || value.length == 0; |
744 |
10 Jun 05 |
nicklas |
220 |
DbControl dc = null; |
744 |
10 Jun 05 |
nicklas |
221 |
try |
744 |
10 Jun 05 |
nicklas |
222 |
{ |
744 |
10 Jun 05 |
nicklas |
223 |
dc = TestUtil.getDbControl(); |
3973 |
16 Nov 07 |
nicklas |
224 |
Annotatable annotatable = (Annotatable)itemType.getById(dc, itemId); |
744 |
10 Jun 05 |
nicklas |
225 |
AnnotationType at = AnnotationType.getById(dc, annotationTypeId); |
798 |
20 Jun 05 |
nicklas |
226 |
|
3973 |
16 Nov 07 |
nicklas |
227 |
AnnotationSet as = annotatable.getAnnotationSet(); |
7260 |
12 Dec 16 |
nicklas |
228 |
Annotation a = as.getAnnotation(at); |
744 |
10 Jun 05 |
nicklas |
229 |
|
7106 |
14 Mar 16 |
nicklas |
230 |
if (value != null) |
7106 |
14 Mar 16 |
nicklas |
231 |
{ |
7106 |
14 Mar 16 |
nicklas |
232 |
List<Object> l = new ArrayList<Object>(); |
7106 |
14 Mar 16 |
nicklas |
233 |
l.addAll(Arrays.asList(value)); |
7106 |
14 Mar 16 |
nicklas |
234 |
Unit unit = unitId != 0 ? Unit.getById(dc, unitId) : null; |
7290 |
31 Jan 17 |
nicklas |
235 |
boolean changed = a.setValuesIfDifferent(l, unit); |
7290 |
31 Jan 17 |
nicklas |
236 |
if (changed && at.getProjectAnnotations() && dc.getSessionControl().getActiveProjectId() != a.getProjectId()) |
7290 |
31 Jan 17 |
nicklas |
237 |
{ |
7290 |
31 Jan 17 |
nicklas |
// We have created a different (project-specific) annotation |
7290 |
31 Jan 17 |
nicklas |
239 |
a = as.getAnnotation(at); |
7290 |
31 Jan 17 |
nicklas |
240 |
} |
7106 |
14 Mar 16 |
nicklas |
241 |
} |
744 |
10 Jun 05 |
nicklas |
242 |
dc.commit(); |
744 |
10 Jun 05 |
nicklas |
243 |
id = a.getId(); |
806 |
22 Jun 05 |
nicklas |
244 |
dc = TestUtil.getDbControl(); |
5060 |
19 Aug 09 |
nicklas |
245 |
dc.reattachItem(a, false); |
744 |
10 Jun 05 |
nicklas |
246 |
write_item(0, a); |
7106 |
14 Mar 16 |
nicklas |
247 |
if (shouldFail) |
7106 |
14 Mar 16 |
nicklas |
248 |
{ |
7106 |
14 Mar 16 |
nicklas |
249 |
shouldFail = false; |
7106 |
14 Mar 16 |
nicklas |
250 |
throw new RuntimeException("An annotation was created without values: " + value); |
7106 |
14 Mar 16 |
nicklas |
251 |
} |
744 |
10 Jun 05 |
nicklas |
252 |
write("--Create annotation OK"); |
744 |
10 Jun 05 |
nicklas |
253 |
} |
816 |
23 Jun 05 |
nicklas |
254 |
catch (Throwable ex) |
744 |
10 Jun 05 |
nicklas |
255 |
{ |
7106 |
14 Mar 16 |
nicklas |
256 |
if (shouldFail) |
7106 |
14 Mar 16 |
nicklas |
257 |
{ |
7107 |
14 Mar 16 |
nicklas |
258 |
write("--Create annotation OK (not created: "+ex.getMessage()+")"); |
7106 |
14 Mar 16 |
nicklas |
259 |
} |
7106 |
14 Mar 16 |
nicklas |
260 |
else |
7106 |
14 Mar 16 |
nicklas |
261 |
{ |
7106 |
14 Mar 16 |
nicklas |
262 |
write("--Create annotation FAILED"); |
7106 |
14 Mar 16 |
nicklas |
263 |
ex.printStackTrace(); |
7106 |
14 Mar 16 |
nicklas |
264 |
ok = false; |
7106 |
14 Mar 16 |
nicklas |
265 |
} |
744 |
10 Jun 05 |
nicklas |
266 |
} |
744 |
10 Jun 05 |
nicklas |
267 |
finally |
744 |
10 Jun 05 |
nicklas |
268 |
{ |
744 |
10 Jun 05 |
nicklas |
269 |
if (dc != null) dc.close(); |
744 |
10 Jun 05 |
nicklas |
270 |
} |
744 |
10 Jun 05 |
nicklas |
271 |
return id; |
744 |
10 Jun 05 |
nicklas |
272 |
} |
744 |
10 Jun 05 |
nicklas |
273 |
|
7296 |
20 Feb 17 |
nicklas |
274 |
static int test_annotatate_forceproject(Item itemType, int itemId, int annotationTypeId, int projectId, Object... value) |
7296 |
20 Feb 17 |
nicklas |
275 |
{ |
7296 |
20 Feb 17 |
nicklas |
276 |
if (itemId == 0 || annotationTypeId == 0) return 0; |
7296 |
20 Feb 17 |
nicklas |
277 |
int id = 0; |
7296 |
20 Feb 17 |
nicklas |
278 |
DbControl dc = null; |
7296 |
20 Feb 17 |
nicklas |
279 |
try |
7296 |
20 Feb 17 |
nicklas |
280 |
{ |
7296 |
20 Feb 17 |
nicklas |
281 |
dc = TestUtil.getDbControl(); |
7296 |
20 Feb 17 |
nicklas |
282 |
Annotatable annotatable = (Annotatable)itemType.getById(dc, itemId); |
7296 |
20 Feb 17 |
nicklas |
283 |
AnnotationType at = AnnotationType.getById(dc, annotationTypeId); |
7299 |
22 Feb 17 |
nicklas |
284 |
Project project = projectId == 0 ? null : Project.getById(dc, projectId); |
7296 |
20 Feb 17 |
nicklas |
285 |
|
7296 |
20 Feb 17 |
nicklas |
286 |
AnnotationSet as = annotatable.getAnnotationSet(); |
7299 |
22 Feb 17 |
nicklas |
287 |
Annotation a = as.getProjectAnnotation(at, project); |
7296 |
20 Feb 17 |
nicklas |
288 |
|
7296 |
20 Feb 17 |
nicklas |
289 |
if (value != null) |
7296 |
20 Feb 17 |
nicklas |
290 |
{ |
7296 |
20 Feb 17 |
nicklas |
291 |
List<Object> l = new ArrayList<Object>(); |
7296 |
20 Feb 17 |
nicklas |
292 |
l.addAll(Arrays.asList(value)); |
7296 |
20 Feb 17 |
nicklas |
293 |
boolean changed = a.setValuesIfDifferent(l, null); |
7296 |
20 Feb 17 |
nicklas |
294 |
} |
7296 |
20 Feb 17 |
nicklas |
295 |
dc.commit(); |
7296 |
20 Feb 17 |
nicklas |
296 |
id = a.getId(); |
7296 |
20 Feb 17 |
nicklas |
297 |
dc = TestUtil.getDbControl(); |
7296 |
20 Feb 17 |
nicklas |
298 |
dc.reattachItem(a, false); |
7296 |
20 Feb 17 |
nicklas |
299 |
write_item(0, a); |
7296 |
20 Feb 17 |
nicklas |
300 |
write("--Create annotation OK"); |
7296 |
20 Feb 17 |
nicklas |
301 |
} |
7296 |
20 Feb 17 |
nicklas |
302 |
catch (Throwable ex) |
7296 |
20 Feb 17 |
nicklas |
303 |
{ |
7296 |
20 Feb 17 |
nicklas |
304 |
write("--Create annotation FAILED"); |
7296 |
20 Feb 17 |
nicklas |
305 |
ex.printStackTrace(); |
7296 |
20 Feb 17 |
nicklas |
306 |
ok = false; |
7296 |
20 Feb 17 |
nicklas |
307 |
} |
7296 |
20 Feb 17 |
nicklas |
308 |
finally |
7296 |
20 Feb 17 |
nicklas |
309 |
{ |
7296 |
20 Feb 17 |
nicklas |
310 |
if (dc != null) dc.close(); |
7296 |
20 Feb 17 |
nicklas |
311 |
} |
7296 |
20 Feb 17 |
nicklas |
312 |
return id; |
7296 |
20 Feb 17 |
nicklas |
313 |
} |
7296 |
20 Feb 17 |
nicklas |
314 |
|
7296 |
20 Feb 17 |
nicklas |
315 |
|
3973 |
16 Nov 07 |
nicklas |
316 |
static void test_remove_annotation(Item itemType, int itemId, int annotationTypeId) |
744 |
10 Jun 05 |
nicklas |
317 |
{ |
3973 |
16 Nov 07 |
nicklas |
318 |
if (itemId == 0 || annotationTypeId == 0) return; |
744 |
10 Jun 05 |
nicklas |
319 |
DbControl dc = null; |
744 |
10 Jun 05 |
nicklas |
320 |
try |
744 |
10 Jun 05 |
nicklas |
321 |
{ |
744 |
10 Jun 05 |
nicklas |
322 |
dc = TestUtil.getDbControl(); |
3973 |
16 Nov 07 |
nicklas |
323 |
Annotatable annotatable = (Annotatable)itemType.getById(dc, itemId); |
744 |
10 Jun 05 |
nicklas |
324 |
AnnotationType at = AnnotationType.getById(dc, annotationTypeId); |
3973 |
16 Nov 07 |
nicklas |
325 |
AnnotationSet as = annotatable.getAnnotationSet(); |
744 |
10 Jun 05 |
nicklas |
326 |
as.removeAnnotation(at); |
744 |
10 Jun 05 |
nicklas |
327 |
dc.commit(); |
744 |
10 Jun 05 |
nicklas |
328 |
write("--Remove annotation OK"); |
744 |
10 Jun 05 |
nicklas |
329 |
} |
816 |
23 Jun 05 |
nicklas |
330 |
catch (Throwable ex) |
744 |
10 Jun 05 |
nicklas |
331 |
{ |
744 |
10 Jun 05 |
nicklas |
332 |
write("--Remove annotation FAILED"); |
744 |
10 Jun 05 |
nicklas |
333 |
ex.printStackTrace(); |
744 |
10 Jun 05 |
nicklas |
334 |
ok = false; |
744 |
10 Jun 05 |
nicklas |
335 |
} |
744 |
10 Jun 05 |
nicklas |
336 |
finally |
744 |
10 Jun 05 |
nicklas |
337 |
{ |
744 |
10 Jun 05 |
nicklas |
338 |
if (dc != null) dc.close(); |
744 |
10 Jun 05 |
nicklas |
339 |
} |
744 |
10 Jun 05 |
nicklas |
340 |
} |
7670 |
21 Mar 19 |
nicklas |
341 |
|
7670 |
21 Mar 19 |
nicklas |
342 |
static void test_remove_all_annotations(Item itemType, int itemId) |
7670 |
21 Mar 19 |
nicklas |
343 |
{ |
7670 |
21 Mar 19 |
nicklas |
344 |
if (itemId == 0 ) return; |
7670 |
21 Mar 19 |
nicklas |
345 |
DbControl dc = null; |
7670 |
21 Mar 19 |
nicklas |
346 |
try |
7670 |
21 Mar 19 |
nicklas |
347 |
{ |
7670 |
21 Mar 19 |
nicklas |
348 |
dc = TestUtil.getDbControl(); |
7670 |
21 Mar 19 |
nicklas |
349 |
Annotatable annotatable = (Annotatable)itemType.getById(dc, itemId); |
7670 |
21 Mar 19 |
nicklas |
350 |
AnnotationSet as = annotatable.getAnnotationSet(); |
7670 |
21 Mar 19 |
nicklas |
351 |
for (Annotation a : as.getAnnotations(Source.PRIMARY).list(dc)) |
7670 |
21 Mar 19 |
nicklas |
352 |
{ |
7670 |
21 Mar 19 |
nicklas |
353 |
as.removeAnnotation(a.getAnnotationType()); |
7670 |
21 Mar 19 |
nicklas |
354 |
} |
7670 |
21 Mar 19 |
nicklas |
355 |
dc.commit(); |
7670 |
21 Mar 19 |
nicklas |
356 |
write("--Remove all annotations OK"); |
7670 |
21 Mar 19 |
nicklas |
357 |
} |
7670 |
21 Mar 19 |
nicklas |
358 |
catch (Throwable ex) |
7670 |
21 Mar 19 |
nicklas |
359 |
{ |
7670 |
21 Mar 19 |
nicklas |
360 |
write("--Remove all annotations FAILED"); |
7670 |
21 Mar 19 |
nicklas |
361 |
ex.printStackTrace(); |
7670 |
21 Mar 19 |
nicklas |
362 |
ok = false; |
7670 |
21 Mar 19 |
nicklas |
363 |
} |
7670 |
21 Mar 19 |
nicklas |
364 |
finally |
7670 |
21 Mar 19 |
nicklas |
365 |
{ |
7670 |
21 Mar 19 |
nicklas |
366 |
if (dc != null) dc.close(); |
7670 |
21 Mar 19 |
nicklas |
367 |
} |
7670 |
21 Mar 19 |
nicklas |
368 |
} |
744 |
10 Jun 05 |
nicklas |
369 |
|
6921 |
26 May 15 |
nicklas |
370 |
static void test_list_annotations(Item itemType, int itemId, Annotation.Source source, int expectedResults) |
744 |
10 Jun 05 |
nicklas |
371 |
{ |
744 |
10 Jun 05 |
nicklas |
372 |
DbControl dc = null; |
3586 |
20 Jul 07 |
nicklas |
373 |
Annotatable at = null; |
744 |
10 Jun 05 |
nicklas |
374 |
try |
744 |
10 Jun 05 |
nicklas |
375 |
{ |
744 |
10 Jun 05 |
nicklas |
376 |
dc = TestUtil.getDbControl(); |
3586 |
20 Jul 07 |
nicklas |
377 |
at = (Annotatable)itemType.getById(dc, itemId); |
5430 |
28 Sep 10 |
nicklas |
378 |
List<Annotation> l = Collections.emptyList(); |
5430 |
28 Sep 10 |
nicklas |
379 |
if (at.isAnnotated()) |
5430 |
28 Sep 10 |
nicklas |
380 |
{ |
6921 |
26 May 15 |
nicklas |
381 |
l = at.getAnnotationSet().getAnnotations(source).list(dc); |
5430 |
28 Sep 10 |
nicklas |
382 |
} |
744 |
10 Jun 05 |
nicklas |
383 |
for (int i = 0; i<l.size(); i++) |
744 |
10 Jun 05 |
nicklas |
384 |
{ |
744 |
10 Jun 05 |
nicklas |
385 |
write_item(i, l.get(i)); |
744 |
10 Jun 05 |
nicklas |
386 |
} |
744 |
10 Jun 05 |
nicklas |
387 |
if (expectedResults >= 0 && expectedResults != l.size()) |
744 |
10 Jun 05 |
nicklas |
388 |
{ |
744 |
10 Jun 05 |
nicklas |
389 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
744 |
10 Jun 05 |
nicklas |
390 |
} |
6921 |
26 May 15 |
nicklas |
391 |
write("--List " + (source==null ? "ALL":source)+" annotations for " + at + " OK ("+l.size()+")"); |
744 |
10 Jun 05 |
nicklas |
392 |
} |
816 |
23 Jun 05 |
nicklas |
393 |
catch (Throwable ex) |
744 |
10 Jun 05 |
nicklas |
394 |
{ |
6921 |
26 May 15 |
nicklas |
395 |
write("--List " + (source==null ? "ALL":source)+" annotations for " + at + " FAILED"); |
744 |
10 Jun 05 |
nicklas |
396 |
ex.printStackTrace(); |
744 |
10 Jun 05 |
nicklas |
397 |
ok = false; |
744 |
10 Jun 05 |
nicklas |
398 |
} |
744 |
10 Jun 05 |
nicklas |
399 |
finally |
744 |
10 Jun 05 |
nicklas |
400 |
{ |
744 |
10 Jun 05 |
nicklas |
401 |
if (dc != null) dc.close(); |
744 |
10 Jun 05 |
nicklas |
402 |
} |
744 |
10 Jun 05 |
nicklas |
403 |
} |
744 |
10 Jun 05 |
nicklas |
404 |
|
7246 |
01 Dec 16 |
nicklas |
405 |
static void test_project_annotation(Item itemType, int itemId, int annotationTypeId, Object expectedValue, Object noMatchInQuery) |
7245 |
01 Dec 16 |
nicklas |
406 |
{ |
7245 |
01 Dec 16 |
nicklas |
407 |
if (itemId == 0 || annotationTypeId == 0) return; |
7245 |
01 Dec 16 |
nicklas |
408 |
DbControl dc = null; |
7245 |
01 Dec 16 |
nicklas |
409 |
Annotatable item = null; |
7245 |
01 Dec 16 |
nicklas |
410 |
AnnotationType at = null; |
7245 |
01 Dec 16 |
nicklas |
411 |
try |
7245 |
01 Dec 16 |
nicklas |
412 |
{ |
7245 |
01 Dec 16 |
nicklas |
413 |
dc = TestUtil.getDbControl(); |
7245 |
01 Dec 16 |
nicklas |
414 |
item = (Annotatable)itemType.getById(dc, itemId); |
7245 |
01 Dec 16 |
nicklas |
415 |
at = AnnotationType.getById(dc, annotationTypeId); |
7245 |
01 Dec 16 |
nicklas |
416 |
|
7245 |
01 Dec 16 |
nicklas |
// Regular API -- check that value is the expected value |
7245 |
01 Dec 16 |
nicklas |
418 |
Object value = null; |
7245 |
01 Dec 16 |
nicklas |
419 |
if (item.isAnnotated()) |
7245 |
01 Dec 16 |
nicklas |
420 |
{ |
7245 |
01 Dec 16 |
nicklas |
421 |
AnnotationSet as = item.getAnnotationSet(); |
7245 |
01 Dec 16 |
nicklas |
422 |
if (as.hasAnnotation(at, Annotation.Source.PRIMARY)) |
7245 |
01 Dec 16 |
nicklas |
423 |
{ |
7260 |
12 Dec 16 |
nicklas |
424 |
Annotation a = as.getAnnotation(at); |
7245 |
01 Dec 16 |
nicklas |
425 |
write_item(0, a); |
7245 |
01 Dec 16 |
nicklas |
426 |
value = a.getValues().get(0); |
7245 |
01 Dec 16 |
nicklas |
427 |
} |
7245 |
01 Dec 16 |
nicklas |
428 |
} |
7245 |
01 Dec 16 |
nicklas |
429 |
if (!EqualsHelper.equals(value, expectedValue)) |
7245 |
01 Dec 16 |
nicklas |
430 |
{ |
7245 |
01 Dec 16 |
nicklas |
431 |
throw new BaseException("Expected '" + expectedValue + "', got '" + value + "'"); |
7245 |
01 Dec 16 |
nicklas |
432 |
} |
7245 |
01 Dec 16 |
nicklas |
433 |
|
7245 |
01 Dec 16 |
nicklas |
// Query API -- check that the expected item is returned by the query |
7245 |
01 Dec 16 |
nicklas |
435 |
ItemQuery<?> query = itemType.getQuery(); |
7340 |
13 Apr 17 |
nicklas |
436 |
query.restrict(new AnnotationSimpleRestriction(null, at, Operator.EQ, expectedValue, new AnnotationRestriction.Options())); |
7245 |
01 Dec 16 |
nicklas |
437 |
List<?> result = new ArrayList<Object>(query.list(dc)); |
7245 |
01 Dec 16 |
nicklas |
438 |
if (result.size() != 1) |
7245 |
01 Dec 16 |
nicklas |
439 |
{ |
7245 |
01 Dec 16 |
nicklas |
440 |
throw new BaseException("Query returned: " + result); |
7245 |
01 Dec 16 |
nicklas |
441 |
} |
7245 |
01 Dec 16 |
nicklas |
442 |
item = (Annotatable)result.get(0); |
7245 |
01 Dec 16 |
nicklas |
443 |
if (item.getId() != itemId) |
7245 |
01 Dec 16 |
nicklas |
444 |
{ |
7245 |
01 Dec 16 |
nicklas |
445 |
throw new BaseException("Query returned: "+ result); |
7245 |
01 Dec 16 |
nicklas |
446 |
} |
7245 |
01 Dec 16 |
nicklas |
447 |
|
7246 |
01 Dec 16 |
nicklas |
// Query API -- check that the no items are returned by the query |
7246 |
01 Dec 16 |
nicklas |
449 |
if (noMatchInQuery != null) |
7246 |
01 Dec 16 |
nicklas |
450 |
{ |
7246 |
01 Dec 16 |
nicklas |
451 |
query = itemType.getQuery(); |
7340 |
13 Apr 17 |
nicklas |
452 |
query.restrict(new AnnotationSimpleRestriction(null, at, Operator.EQ, noMatchInQuery, new AnnotationRestriction.Options())); |
7246 |
01 Dec 16 |
nicklas |
453 |
result = new ArrayList<Object>(query.list(dc)); |
7246 |
01 Dec 16 |
nicklas |
454 |
if (result.size() != 0) |
7246 |
01 Dec 16 |
nicklas |
455 |
{ |
7246 |
01 Dec 16 |
nicklas |
456 |
throw new BaseException("Query returned: " + result); |
7246 |
01 Dec 16 |
nicklas |
457 |
} |
7246 |
01 Dec 16 |
nicklas |
458 |
} |
7246 |
01 Dec 16 |
nicklas |
459 |
|
7247 |
01 Dec 16 |
nicklas |
// Snapshot manager -- check that value is the expected value |
7247 |
01 Dec 16 |
nicklas |
461 |
value = null; |
7247 |
01 Dec 16 |
nicklas |
462 |
SnapshotManager manager = new SnapshotManager(); |
7247 |
01 Dec 16 |
nicklas |
463 |
List<AnnotationSnapshot> snapshots = manager.findAnnotations(dc, item, new AnnotationTypeFilter(at), true, false); |
7247 |
01 Dec 16 |
nicklas |
464 |
if (snapshots.size() != 1) |
7247 |
01 Dec 16 |
nicklas |
465 |
{ |
7247 |
01 Dec 16 |
nicklas |
466 |
throw new BaseException("SnapshotManager returned " + snapshots.size() + " annotations"); |
7247 |
01 Dec 16 |
nicklas |
467 |
} |
7247 |
01 Dec 16 |
nicklas |
468 |
AnnotationSnapshot snapshot = snapshots.get(0); |
7247 |
01 Dec 16 |
nicklas |
469 |
value = snapshot.getActualValues().get(0); |
7247 |
01 Dec 16 |
nicklas |
470 |
if (!EqualsHelper.equals(value, expectedValue)) |
7247 |
01 Dec 16 |
nicklas |
471 |
{ |
7247 |
01 Dec 16 |
nicklas |
472 |
throw new BaseException("Expected '" + expectedValue + "', got '" + value + "'"); |
7247 |
01 Dec 16 |
nicklas |
473 |
} |
7247 |
01 Dec 16 |
nicklas |
474 |
|
7245 |
01 Dec 16 |
nicklas |
475 |
write("--Project annotation for " + at + " OK ("+expectedValue+")"); |
7245 |
01 Dec 16 |
nicklas |
476 |
} |
7245 |
01 Dec 16 |
nicklas |
477 |
catch (Throwable ex) |
7245 |
01 Dec 16 |
nicklas |
478 |
{ |
7245 |
01 Dec 16 |
nicklas |
479 |
write("--Project annotation for " + at + " FAILED"); |
7245 |
01 Dec 16 |
nicklas |
480 |
ex.printStackTrace(); |
7245 |
01 Dec 16 |
nicklas |
481 |
ok = false; |
7245 |
01 Dec 16 |
nicklas |
482 |
} |
7245 |
01 Dec 16 |
nicklas |
483 |
finally |
7245 |
01 Dec 16 |
nicklas |
484 |
{ |
7245 |
01 Dec 16 |
nicklas |
485 |
if (dc != null) dc.close(); |
7245 |
01 Dec 16 |
nicklas |
486 |
} |
7245 |
01 Dec 16 |
nicklas |
487 |
} |
7245 |
01 Dec 16 |
nicklas |
488 |
|
7245 |
01 Dec 16 |
nicklas |
489 |
|
1156 |
30 Aug 05 |
nicklas |
490 |
static void write_header() |
798 |
20 Jun 05 |
nicklas |
491 |
{ |
1156 |
30 Aug 05 |
nicklas |
492 |
if (!TestUtil.getSilent()) |
1156 |
30 Aug 05 |
nicklas |
493 |
{ |
7290 |
31 Jan 17 |
nicklas |
494 |
write(" \tID \tAnnotation type\tAnnotation set\tSource\tProject\tParent\tValues\tUnit\tRaw values"); |
7290 |
31 Jan 17 |
nicklas |
495 |
write("-- \t-- \t---------------\t--------------\t------\t-------\t------\t------\t----\t----------"); |
1156 |
30 Aug 05 |
nicklas |
496 |
} |
1156 |
30 Aug 05 |
nicklas |
497 |
} |
1156 |
30 Aug 05 |
nicklas |
498 |
static void write_item(int i, Annotation a) |
1156 |
30 Aug 05 |
nicklas |
499 |
throws BaseException |
1156 |
30 Aug 05 |
nicklas |
500 |
{ |
6921 |
26 May 15 |
nicklas |
501 |
if (TestUtil.getSilent()) return; |
6921 |
26 May 15 |
nicklas |
502 |
|
6921 |
26 May 15 |
nicklas |
503 |
List<?> values = null; |
6921 |
26 May 15 |
nicklas |
504 |
if (a.getSource() == Annotation.Source.PRIMARY) |
6921 |
26 May 15 |
nicklas |
505 |
{ |
6921 |
26 May 15 |
nicklas |
506 |
values = a.getValues(null); |
6921 |
26 May 15 |
nicklas |
507 |
} |
6921 |
26 May 15 |
nicklas |
508 |
else |
6921 |
26 May 15 |
nicklas |
509 |
{ |
6921 |
26 May 15 |
nicklas |
510 |
values = a.getInheritedFrom().getValues(null); |
6921 |
26 May 15 |
nicklas |
511 |
} |
6921 |
26 May 15 |
nicklas |
512 |
write(i+":\t"+a.getId()+"\t"+a.getAnnotationType()+"\t"+a.getAnnotationSet()+"\t"+ |
7290 |
31 Jan 17 |
nicklas |
513 |
a.getSource()+"\t"+a.getProjectId()+"\t"+a.getInheritedFrom()+"\t" + |
6921 |
26 May 15 |
nicklas |
514 |
values + "\t" + a.getUnit() + "\t" + a.getValues()); |
1156 |
30 Aug 05 |
nicklas |
515 |
} |
6921 |
26 May 15 |
nicklas |
516 |
|
1156 |
30 Aug 05 |
nicklas |
517 |
static void write_item(int i, AnnotationSet as) |
1156 |
30 Aug 05 |
nicklas |
518 |
throws BaseException |
1156 |
30 Aug 05 |
nicklas |
519 |
{ |
1156 |
30 Aug 05 |
nicklas |
520 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+as.getId()+"\t"+as.getItem()); |
1156 |
30 Aug 05 |
nicklas |
521 |
} |
1156 |
30 Aug 05 |
nicklas |
522 |
|
1156 |
30 Aug 05 |
nicklas |
523 |
static void write(String message) |
1156 |
30 Aug 05 |
nicklas |
524 |
{ |
1156 |
30 Aug 05 |
nicklas |
525 |
System.out.println(message); |
1156 |
30 Aug 05 |
nicklas |
526 |
} |
1156 |
30 Aug 05 |
nicklas |
527 |
|
6921 |
26 May 15 |
nicklas |
528 |
static int test_inherit_annotation(Item itemType, int itemId, int annotationId, boolean clone) |
1156 |
30 Aug 05 |
nicklas |
529 |
{ |
6921 |
26 May 15 |
nicklas |
530 |
if (itemId == 0 || annotationId == 0) return 0; |
798 |
20 Jun 05 |
nicklas |
531 |
DbControl dc = null; |
6921 |
26 May 15 |
nicklas |
532 |
int id = 0; |
798 |
20 Jun 05 |
nicklas |
533 |
try |
798 |
20 Jun 05 |
nicklas |
534 |
{ |
798 |
20 Jun 05 |
nicklas |
535 |
dc = TestUtil.getDbControl(); |
3973 |
16 Nov 07 |
nicklas |
536 |
Annotatable annotatable = (Annotatable)itemType.getById(dc, itemId); |
1156 |
30 Aug 05 |
nicklas |
537 |
Annotation a = Annotation.getById(dc, annotationId); |
3973 |
16 Nov 07 |
nicklas |
538 |
AnnotationSet as = annotatable.getAnnotationSet(); |
6921 |
26 May 15 |
nicklas |
539 |
Annotation inherited = as.inheritAnnotation(a, clone); |
1156 |
30 Aug 05 |
nicklas |
540 |
dc.commit(); |
6921 |
26 May 15 |
nicklas |
541 |
id = inherited.getId(); |
6921 |
26 May 15 |
nicklas |
542 |
dc = TestUtil.getDbControl(); |
6921 |
26 May 15 |
nicklas |
543 |
inherited = Annotation.getById(dc, id); |
6921 |
26 May 15 |
nicklas |
544 |
write_item(0, inherited); |
6921 |
26 May 15 |
nicklas |
545 |
write("--" + (clone ? "Clone" : "Inherit")+ " annotation OK"); |
1156 |
30 Aug 05 |
nicklas |
546 |
} |
1156 |
30 Aug 05 |
nicklas |
547 |
catch (Throwable ex) |
1156 |
30 Aug 05 |
nicklas |
548 |
{ |
6921 |
26 May 15 |
nicklas |
549 |
write("--" + (clone ? "Clone" : "Inherit")+ " annotation FAILED"); |
1156 |
30 Aug 05 |
nicklas |
550 |
ex.printStackTrace(); |
1156 |
30 Aug 05 |
nicklas |
551 |
ok = false; |
1156 |
30 Aug 05 |
nicklas |
552 |
} |
1156 |
30 Aug 05 |
nicklas |
553 |
finally |
1156 |
30 Aug 05 |
nicklas |
554 |
{ |
1156 |
30 Aug 05 |
nicklas |
555 |
if (dc != null) dc.close(); |
1156 |
30 Aug 05 |
nicklas |
556 |
} |
6921 |
26 May 15 |
nicklas |
557 |
return id; |
1156 |
30 Aug 05 |
nicklas |
558 |
} |
1156 |
30 Aug 05 |
nicklas |
559 |
|
6911 |
20 May 15 |
nicklas |
560 |
static void test_inherit_annotationset(Item toItemType, int toItemId, Item fromItemType, int fromItemId, int expectAdded) |
1156 |
30 Aug 05 |
nicklas |
561 |
{ |
3973 |
16 Nov 07 |
nicklas |
562 |
if (toItemId == 0 || fromItemId == 0) return; |
1156 |
30 Aug 05 |
nicklas |
563 |
DbControl dc = null; |
1156 |
30 Aug 05 |
nicklas |
564 |
try |
1156 |
30 Aug 05 |
nicklas |
565 |
{ |
1156 |
30 Aug 05 |
nicklas |
566 |
dc = TestUtil.getDbControl(); |
3973 |
16 Nov 07 |
nicklas |
567 |
Annotatable to = (Annotatable)toItemType.getById(dc, toItemId); |
3973 |
16 Nov 07 |
nicklas |
568 |
Annotatable from = (Annotatable)fromItemType.getById(dc, fromItemId); |
3973 |
16 Nov 07 |
nicklas |
569 |
AnnotationSet as = to.getAnnotationSet(); |
3973 |
16 Nov 07 |
nicklas |
570 |
AnnotationSet inherited = from.getAnnotationSet(); |
6921 |
26 May 15 |
nicklas |
571 |
int added = as.inheritAll(inherited, false); |
6911 |
20 May 15 |
nicklas |
572 |
if (added != expectAdded) |
6911 |
20 May 15 |
nicklas |
573 |
{ |
6911 |
20 May 15 |
nicklas |
574 |
throw new BaseException("Expected "+expectAdded+" results, not "+added); |
6911 |
20 May 15 |
nicklas |
575 |
} |
1156 |
30 Aug 05 |
nicklas |
576 |
dc.commit(); |
6911 |
20 May 15 |
nicklas |
577 |
write("--Inherit annotation set OK (" + added + " added)"); |
1156 |
30 Aug 05 |
nicklas |
578 |
} |
1156 |
30 Aug 05 |
nicklas |
579 |
catch (Throwable ex) |
1156 |
30 Aug 05 |
nicklas |
580 |
{ |
1156 |
30 Aug 05 |
nicklas |
581 |
write("--Inherit annotation set FAILED"); |
1156 |
30 Aug 05 |
nicklas |
582 |
ex.printStackTrace(); |
1156 |
30 Aug 05 |
nicklas |
583 |
ok = false; |
1156 |
30 Aug 05 |
nicklas |
584 |
} |
1156 |
30 Aug 05 |
nicklas |
585 |
finally |
1156 |
30 Aug 05 |
nicklas |
586 |
{ |
1156 |
30 Aug 05 |
nicklas |
587 |
if (dc != null) dc.close(); |
1156 |
30 Aug 05 |
nicklas |
588 |
} |
1156 |
30 Aug 05 |
nicklas |
589 |
} |
1156 |
30 Aug 05 |
nicklas |
590 |
|
6921 |
26 May 15 |
nicklas |
591 |
static void test_modify_clone(int clonedId, int unitId, Object... value) |
1156 |
30 Aug 05 |
nicklas |
592 |
{ |
6921 |
26 May 15 |
nicklas |
593 |
if (clonedId == 0) return; |
1156 |
30 Aug 05 |
nicklas |
594 |
DbControl dc = null; |
1156 |
30 Aug 05 |
nicklas |
595 |
try |
1156 |
30 Aug 05 |
nicklas |
596 |
{ |
1156 |
30 Aug 05 |
nicklas |
597 |
dc = TestUtil.getDbControl(); |
6921 |
26 May 15 |
nicklas |
598 |
Annotation a = Annotation.getById(dc, clonedId); |
6921 |
26 May 15 |
nicklas |
599 |
|
6921 |
26 May 15 |
nicklas |
600 |
List<Object> l = new ArrayList<Object>(); |
6921 |
26 May 15 |
nicklas |
601 |
l.addAll(Arrays.asList(value)); |
6921 |
26 May 15 |
nicklas |
602 |
Unit unit = unitId != 0 ? Unit.getById(dc, unitId) : null; |
7120 |
15 Apr 16 |
nicklas |
603 |
a.setValuesIfDifferent(l, unit); |
6921 |
26 May 15 |
nicklas |
604 |
dc.commit(); |
6921 |
26 May 15 |
nicklas |
605 |
dc = TestUtil.getDbControl(); |
6921 |
26 May 15 |
nicklas |
606 |
a = Annotation.getById(dc, clonedId); |
6921 |
26 May 15 |
nicklas |
607 |
write_item(0, a); |
6921 |
26 May 15 |
nicklas |
608 |
write("--Modify cloned annotation OK"); |
798 |
20 Jun 05 |
nicklas |
609 |
} |
816 |
23 Jun 05 |
nicklas |
610 |
catch (Throwable ex) |
798 |
20 Jun 05 |
nicklas |
611 |
{ |
6921 |
26 May 15 |
nicklas |
612 |
write("--Modify cloned annotation FAILED"); |
798 |
20 Jun 05 |
nicklas |
613 |
ex.printStackTrace(); |
798 |
20 Jun 05 |
nicklas |
614 |
ok = false; |
798 |
20 Jun 05 |
nicklas |
615 |
} |
798 |
20 Jun 05 |
nicklas |
616 |
finally |
798 |
20 Jun 05 |
nicklas |
617 |
{ |
798 |
20 Jun 05 |
nicklas |
618 |
if (dc != null) dc.close(); |
798 |
20 Jun 05 |
nicklas |
619 |
} |
1156 |
30 Aug 05 |
nicklas |
620 |
} |
6921 |
26 May 15 |
nicklas |
621 |
|
744 |
10 Jun 05 |
nicklas |
622 |
} |