-
Notifications
You must be signed in to change notification settings - Fork 14
/
ParameterValueTest.java
119 lines (103 loc) · 4.4 KB
/
ParameterValueTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* Copyright (C) 2016 Czech Technical University in Prague
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cz.cvut.kbss.jopa.query.parameter;
import org.junit.Test;
import java.net.URI;
import java.net.URL;
import java.util.Date;
import static org.junit.Assert.*;
/**
* Datatype specifications in the assertions are taken from the SPARQL specification.
*/
public class ParameterValueTest {
@Test
public void createStringValueWithoutLanguageTag() {
final ParameterValue value = ParameterValue.create("test");
assertEquals("test", value.getValue());
assertEquals("\"test\"", value.getQueryString());
}
@Test
public void createStringValueWithLanguageTag() {
final ParameterValue value = ParameterValue.create("test", "en");
assertEquals("test", value.getValue());
assertEquals("\"test\"@en", value.getQueryString());
}
@Test
public void createBooleanValue() {
final ParameterValue value = ParameterValue.create(true);
assertEquals(Boolean.TRUE, value.getValue());
assertEquals("\"true\"^^<http://www.w3.org/2001/XMLSchema#boolean>", value.getQueryString());
}
@Test
public void createShortValue() {
final ParameterValue value = ParameterValue.create((short) 117);
assertEquals((short) 117, value.getValue());
assertEquals("\"117\"^^<http://www.w3.org/2001/XMLSchema#short>", value.getQueryString());
}
@Test
public void createIntegerValue() {
final ParameterValue value = ParameterValue.create(117);
assertEquals(117, value.getValue());
assertEquals("\"117\"^^<http://www.w3.org/2001/XMLSchema#int>", value.getQueryString());
}
@Test
public void createLongValue() {
final long v = System.currentTimeMillis();
final ParameterValue value = ParameterValue.create(v);
assertEquals(v, value.getValue());
assertEquals("\"" + v + "\"^^<http://www.w3.org/2001/XMLSchema#long>", value.getQueryString());
}
@Test
public void createFloatValue() {
final ParameterValue value = ParameterValue.create(3.14f);
assertEquals(3.14f, value.getValue());
assertEquals("\"3.14\"^^<http://www.w3.org/2001/XMLSchema#float>", value.getQueryString());
}
@Test
public void createDoubleValue() {
final ParameterValue value = ParameterValue.create(3.14);
assertEquals(3.14, value.getValue());
assertEquals("\"3.14\"^^<http://www.w3.org/2001/XMLSchema#double>", value.getQueryString());
}
@Test
public void createDateValue() {
final Date date = new Date();
final ParameterValue value = ParameterValue.create(date);
assertEquals(date, value.getValue());
assertEquals("\"" + date.toString() + "\"^^<http://www.w3.org/2001/XMLSchema#dateTime>",
value.getQueryString());
}
@Test
public void createUriValue() {
final URI uri = URI.create("http://krizik.felk.cvut.cz/jopa#Individual");
final ParameterValue value = ParameterValue.create(uri);
assertEquals(uri, value.getValue());
assertEquals("<" + uri.toString() + ">", value.getQueryString());
}
@Test
public void createUrlValue() throws Exception {
final URL url = new URL("http://krizik.felk.cvut.cz/jopa#Individual");
final ParameterValue value = ParameterValue.create(url);
assertEquals(url.toURI(), value.getValue()); // URLs are internally transformed to URIs
assertEquals("<" + url.toString() + ">", value.getQueryString());
}
@Test
public void createUntypedValue() {
final Integer integer = 117;
final ParameterValue value = ParameterValue.createUntyped(integer);
assertEquals(integer, value.getValue());
assertEquals(integer.toString(), value.getQueryString());
}
}