1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.model.metadata;
|
10
|
|
11
|
import java.util.List;
|
12
|
import java.util.UUID;
|
13
|
|
14
|
import org.junit.Assert;
|
15
|
import org.junit.Before;
|
16
|
import org.junit.Test;
|
17
|
|
18
|
/**
|
19
|
* @author a.mueller
|
20
|
* @since 2013-07-03
|
21
|
*
|
22
|
*/
|
23
|
public class CdmPreferenceTest {
|
24
|
|
25
|
private String subject;
|
26
|
private String predicate;
|
27
|
private String value;
|
28
|
|
29
|
/**
|
30
|
* @throws java.lang.Exception
|
31
|
*/
|
32
|
@Before
|
33
|
public void setUp() throws Exception {
|
34
|
subject = "/";
|
35
|
predicate = "eu.etaxonomy.cdm.model.name.NomenclaturalCode";
|
36
|
value = "ICZN";
|
37
|
|
38
|
}
|
39
|
|
40
|
/**
|
41
|
* Test method for {@link eu.etaxonomy.cdm.model.metadata.CdmPreference#CdmPreferences(java.lang.String, java.lang.String, java.lang.String)}.
|
42
|
*/
|
43
|
@Test
|
44
|
public void testCdmPreferences() {
|
45
|
CdmPreference prefs = new CdmPreference(subject, predicate, value);
|
46
|
Assert.assertEquals(subject, prefs.getSubject());
|
47
|
Assert.assertEquals(predicate, prefs.getPredicate());
|
48
|
Assert.assertEquals(value, prefs.getValue());
|
49
|
|
50
|
|
51
|
}
|
52
|
|
53
|
|
54
|
@Test
|
55
|
public void testConstraints() {
|
56
|
String veryLongText100 =
|
57
|
"This is a very long text it is even longer then any other long text which is already long. size =100";
|
58
|
String veryLongText200 = veryLongText100 + veryLongText100;
|
59
|
String veryLongText400 = veryLongText200 + veryLongText200;
|
60
|
String veryLongText1200 = veryLongText400 + veryLongText400 + veryLongText400;
|
61
|
|
62
|
CdmPreference prefs = null;
|
63
|
try {
|
64
|
prefs = new CdmPreference(null, predicate, value);
|
65
|
Assert.fail("Subject must not be null");
|
66
|
} catch (Exception e) {
|
67
|
//ok
|
68
|
}
|
69
|
try {
|
70
|
prefs = new CdmPreference(veryLongText400, predicate, value);
|
71
|
Assert.fail("Subject must not be longer then 255");
|
72
|
} catch (Exception e) {
|
73
|
//ok
|
74
|
}
|
75
|
|
76
|
try {
|
77
|
prefs = new CdmPreference(subject, null, value);
|
78
|
Assert.fail("Predicate must not be null");
|
79
|
} catch (Exception e) {
|
80
|
//ok
|
81
|
}
|
82
|
try {
|
83
|
prefs = new CdmPreference(subject, veryLongText400, value);
|
84
|
Assert.fail("Predicate must not be longer then 255");
|
85
|
} catch (Exception e) {
|
86
|
//ok
|
87
|
}
|
88
|
|
89
|
try {
|
90
|
prefs = new CdmPreference(subject, predicate, null);
|
91
|
Assert.assertEquals(subject, prefs.getSubject());
|
92
|
Assert.assertEquals(predicate, prefs.getPredicate());
|
93
|
Assert.assertNull(value, null);
|
94
|
} catch (Exception e) {
|
95
|
Assert.fail("Currently null values are allowed in preferences");
|
96
|
|
97
|
}
|
98
|
try {
|
99
|
prefs = new CdmPreference(subject, predicate, veryLongText1200);
|
100
|
Assert.fail("Value must not be longer then 1023");
|
101
|
} catch (Exception e) {
|
102
|
//ok
|
103
|
}
|
104
|
}
|
105
|
|
106
|
@Test
|
107
|
public void testSubjectSyntax() {
|
108
|
CdmPreference prefs = null;
|
109
|
String subject2 = null;
|
110
|
try {
|
111
|
subject2 = "/TaxonNode[#t1#18681#6392#5358#9#2#]/";
|
112
|
prefs = new CdmPreference(subject2, predicate, value);
|
113
|
Assert.assertEquals(subject2, prefs.getSubject());
|
114
|
Assert.assertEquals(predicate, prefs.getPredicate());
|
115
|
Assert.assertEquals(value, prefs.getValue());
|
116
|
} catch (Exception e) {
|
117
|
Assert.fail("Syntax for " + subject2 + " should be ok");
|
118
|
}
|
119
|
|
120
|
try {
|
121
|
subject2 = "/TaxonNode[#t1#18681#6392#5358#9#2#]x";
|
122
|
prefs = new CdmPreference(subject2, predicate, value);
|
123
|
Assert.fail("Syntax for " + subject2 + " should fail");
|
124
|
} catch (Exception e) {
|
125
|
//ok
|
126
|
}
|
127
|
|
128
|
try {
|
129
|
subject2 = "/Taxon3Node[#t1#18681#6392#5358#9#2#]";
|
130
|
prefs = new CdmPreference(subject2, predicate, value);
|
131
|
Assert.fail("Syntax for " + subject2 + " should fail");
|
132
|
} catch (Exception e) {
|
133
|
//ok
|
134
|
}
|
135
|
|
136
|
try {
|
137
|
prefs = CdmPreference.NewVaadinInstance(PreferencePredicate.AvailableDistributionStatus, value);
|
138
|
} catch (Exception e) {
|
139
|
Assert.fail("Syntax for /Vaadin/ should not fail");
|
140
|
}
|
141
|
|
142
|
}
|
143
|
|
144
|
@Test
|
145
|
public void testGetValueUuidList() {
|
146
|
//null
|
147
|
CdmPreference prefs = new CdmPreference(subject, predicate, null);
|
148
|
List<UUID> list = prefs.getValueUuidList();
|
149
|
Assert.assertTrue(list.isEmpty());
|
150
|
//empty
|
151
|
prefs = new CdmPreference(subject, predicate, " ");
|
152
|
list = prefs.getValueUuidList();
|
153
|
Assert.assertTrue(list.isEmpty());
|
154
|
//singleUuid
|
155
|
prefs = new CdmPreference(subject, predicate, "1ef35078-fb4a-451d-a15a-127235245358");
|
156
|
list = prefs.getValueUuidList();
|
157
|
Assert.assertEquals(1, list.size());
|
158
|
Assert.assertEquals(UUID.fromString("1ef35078-fb4a-451d-a15a-127235245358"), list.get(0));
|
159
|
//mulitple uuids and varying separators
|
160
|
prefs = new CdmPreference(subject, predicate, "1ef35078-fb4a-451d-a15a-127235245358,a1184db8-e476-4410-b085-d8844ada47e8;43b2cd7d-401b-4565-853f-88ae1c43c55a");
|
161
|
list = prefs.getValueUuidList();
|
162
|
Assert.assertEquals(3, list.size());
|
163
|
Assert.assertEquals(UUID.fromString("1ef35078-fb4a-451d-a15a-127235245358"), list.get(0));
|
164
|
Assert.assertEquals(UUID.fromString("43b2cd7d-401b-4565-853f-88ae1c43c55a"), list.get(2));
|
165
|
//trailing and preceding separators and whitespaces
|
166
|
prefs = new CdmPreference(subject, predicate, " ; 1ef35078-fb4a-451d-a15a-127235245358 , a1184db8-e476-4410-b085-d8844ada47e8;43b2cd7d-401b-4565-853f-88ae1c43c55a , ");
|
167
|
list = prefs.getValueUuidList();
|
168
|
Assert.assertEquals(3, list.size());
|
169
|
Assert.assertEquals(UUID.fromString("1ef35078-fb4a-451d-a15a-127235245358"), list.get(0));
|
170
|
Assert.assertEquals(UUID.fromString("43b2cd7d-401b-4565-853f-88ae1c43c55a"), list.get(2));
|
171
|
//non uuids
|
172
|
prefs = new CdmPreference(subject, predicate, "xxx 1ef35078-fb4a-451d-a15a-127235245358");
|
173
|
try {
|
174
|
list = prefs.getValueUuidList();
|
175
|
Assert.fail("Parsing non UUIDs must throw exception");
|
176
|
} catch (IllegalArgumentException e) {
|
177
|
//correct
|
178
|
}
|
179
|
}
|
180
|
|
181
|
|
182
|
}
|