Skip to content

Commit b8e9651

Browse files
committed
Use URI::NamespaceMap in tests too (Issue #8)
1 parent f4c8e6f commit b8e9651

File tree

3 files changed

+92
-103
lines changed

3 files changed

+92
-103
lines changed

t/16-void.t

+20-25
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use Log::Any::Adapter;
1010
use Module::Load::Conditional qw[check_install];
1111
use Test::RDF;
1212
use RDF::Trine qw[iri literal blank variable statement];
13-
use RDF::Trine::Namespace qw(rdf rdfs);
1413
use RDF::Trine::Store::Hexastore;
1514

1615
unless (defined(check_install( module => 'RDF::Generator::Void', version => 0.02))) {
@@ -28,6 +27,8 @@ my $parser = RDF::Trine::Parser->new( 'turtle' );
2827
my $store = RDF::Trine::Store::Hexastore->temporary_store;
2928
my $model = RDF::Trine::Model->new($store);
3029
my $base_uri = 'http://localhost';
30+
my $ns = URI::NamespaceMap->new(['rdf', 'rdfs', 'void', 'xsd']);
31+
3132
$parser->parse_file_into_model( $base_uri, $file, $model );
3233

3334
ok($model, "We have a model");
@@ -53,18 +54,16 @@ is($ld->count, 3, "There are 3 triples in the model");
5354
has_predicate('http://purl.org/dc/terms/license', $retmodel, "Has license predicate");
5455
has_object_uri('http://example.org/open-data-license', $retmodel, "Has license object");
5556
pattern_target($retmodel);
56-
my $void = RDF::Trine::Namespace->new('http://rdfs.org/ns/void#');
57-
my $xsd = RDF::Trine::Namespace->new('http://www.w3.org/2001/XMLSchema#');
5857
pattern_ok(
5958
statement(
6059
iri($base_uri . '/#dataset-0'),
61-
$void->triples,
62-
literal(3, undef, $xsd->integer)
60+
iri($ns->void->triples),
61+
literal(3, undef, iri($ns->xsd->integer))
6362
),
6463
statement(
6564
iri($base_uri . '/#dataset-0'),
66-
$rdf->type,
67-
$void->Dataset
65+
iri($ns->rdf->type),
66+
iri($ns->void->Dataset)
6867
),
6968
'Common statements are there');
7069
}
@@ -74,7 +73,7 @@ is($ld->count, 3, "There are 3 triples in the model");
7473

7574
is($ld->count, 3, "There are 3 triples in the model");
7675
is($ld->last_etag, $ld->current_etag, 'Etags have not changed');
77-
$ld->model->add_statement(statement(iri($base_uri . '/foo'), $rdfs->label, literal('DAHUT')));
76+
$ld->model->add_statement(statement(iri($base_uri . '/foo'), iri($ns->rdfs->label), literal('DAHUT')));
7877
is($ld->count, 4, "There are 4 triples in the model");
7978
isnt($ld->last_etag, $ld->current_etag, 'Etags have changed');
8079
$ld->type('data');
@@ -92,18 +91,16 @@ is($ld->count, 3, "There are 3 triples in the model");
9291
$parser->parse_into_model( $base_uri, $content, $retmodel );
9392
has_subject($base_uri . '/#dataset-0', $retmodel, "Subject URI in content");
9493
pattern_target($retmodel);
95-
my $void = RDF::Trine::Namespace->new('http://rdfs.org/ns/void#');
96-
my $xsd = RDF::Trine::Namespace->new('http://www.w3.org/2001/XMLSchema#');
9794
pattern_ok(
9895
statement(
9996
iri($base_uri . '/#dataset-0'),
100-
$void->triples,
101-
literal(4, undef, $xsd->integer)
97+
iri($ns->void->triples),
98+
literal(4, undef, iri($ns->xsd->integer))
10299
),
103100
statement(
104101
iri($base_uri . '/#dataset-0'),
105-
$rdf->type,
106-
$void->Dataset
102+
iri($ns->rdf->type),
103+
iri($ns->void->Dataset)
107104
),
108105
'Common statements are there');
109106
}
@@ -124,8 +121,6 @@ is($ld->count, 3, "There are 3 triples in the model");
124121
is($dld->count, 3, "There are 3 triples in the model");
125122
is($dld->last_etag, $dld->current_etag, 'Etags are the same');
126123
is($dld->current_etag, undef, 'Current Etag is undefined');
127-
my $void = RDF::Trine::Namespace->new('http://rdfs.org/ns/void#');
128-
my $xsd = RDF::Trine::Namespace->new('http://www.w3.org/2001/XMLSchema#');
129124
$dld->request(Plack::Request->new({}));
130125
my $response3 = $dld->response($base_uri);
131126
isa_ok($response3, 'Plack::Response');
@@ -138,17 +133,17 @@ is($ld->count, 3, "There are 3 triples in the model");
138133
pattern_ok(
139134
statement(
140135
iri($base_uri . '/#dataset-0'),
141-
$void->triples,
142-
literal(3, undef, $xsd->integer)
136+
iri($ns->void->triples),
137+
literal(3, undef, iri($ns->xsd->integer))
143138
),
144139
statement(
145140
iri($base_uri . '/#dataset-0'),
146-
$rdf->type,
147-
$void->Dataset
141+
iri($ns->rdf->type),
142+
iri($ns->void->Dataset)
148143
),
149144
'Three triples should be counted');
150145

151-
$dld->model->add_statement(statement(iri($base_uri . '/foo'), $rdfs->label, literal('DAHUT')));
146+
$dld->model->add_statement(statement(iri($base_uri . '/foo'), iri($ns->rdfs->label), literal('DAHUT')));
152147
is($dld->count, 4, "There are 4 triples in the model");
153148
is($dld->last_etag, $dld->current_etag, 'Etags are still the same');
154149
is($dld->current_etag, undef, 'Current Etag is still undefined');
@@ -170,13 +165,13 @@ is($ld->count, 3, "There are 3 triples in the model");
170165
pattern_ok(
171166
statement(
172167
iri($base_uri . '/#dataset-0'),
173-
$void->triples,
174-
literal(4, undef, $xsd->integer)
168+
iri($ns->void->triples),
169+
literal(4, undef, iri($ns->xsd->integer))
175170
),
176171
statement(
177172
iri($base_uri . '/#dataset-0'),
178-
$rdf->type,
179-
$void->Dataset
173+
iri($ns->rdf->type),
174+
iri($ns->void->Dataset)
180175
),
181176
'4 statements should be counted');
182177
}

t/18-fragments.t

+55-58
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use Test::More;# tests => 37;
88
use Test::RDF;
99
use RDF::Trine qw[iri literal blank variable statement];
1010
use Log::Any::Adapter;
11-
use RDF::Trine::Namespace qw(rdf rdfs foaf);
11+
use URI::NamespaceMap;
1212
use Module::Load::Conditional qw[check_install];
1313
use URI::Escape;
1414

@@ -23,11 +23,8 @@ my $file = $Bin . '/data/fragments.ttl';
2323
use_ok('RDF::LinkedData');
2424
use_ok('RDF::Generator::Void');
2525

26-
27-
my $void = RDF::Trine::Namespace->new('http://rdfs.org/ns/void#');
28-
my $xsd = RDF::Trine::Namespace->new('http://www.w3.org/2001/XMLSchema#');
29-
my $hydra = RDF::Trine::Namespace->new('http://www.w3.org/ns/hydra/core#');
30-
my $dcterms = RDF::Trine::Namespace->new('http://purl.org/dc/terms/');
26+
my $ns = URI::NamespaceMap->new(['rdf', 'rdfs', 'foaf', 'void', 'dct', 'xsd']);
27+
$ns->add_mapping('hydra' => 'http://www.w3.org/ns/hydra/core#');
3128

3229
my $parser = RDF::Trine::Parser->new( 'turtle' );
3330
my $rxparser = RDF::Trine::Parser->new( 'rdfxml' );
@@ -65,26 +62,26 @@ my $void_subject = iri($base_uri . '/#dataset-0');
6562
pattern_target($retmodel);
6663
pattern_ok(
6764
statement(iri($base_uri . '/foo'),
68-
$rdfs->label,
65+
iri($ns->rdfs->label),
6966
literal("This is a test", 'en')),
7067
statement(iri($base_uri . '/foo'),
71-
$foaf->page,
68+
iri($ns->foaf->page),
7269
iri('http://en.wikipedia.org/wiki/Foo'))
7370
, 'Both triples present',
7471
);
7572

7673
pattern_ok(
7774
statement(iri($base_uri . '/fragments?subject=' . uri_escape_utf8('http://localhost/foo')),
78-
$void->triples,
79-
literal("2", undef, $xsd->integer)),
75+
iri($ns->void->triples),
76+
literal("2", undef, iri($ns->xsd->integer))),
8077
statement(iri($base_uri . '/fragments?subject=' . uri_escape_utf8('http://localhost/foo')),
81-
$hydra->totalItems,
82-
literal("2", undef, $xsd->integer)),
78+
iri($ns->hydra->totalItems),
79+
literal("2", undef, iri($ns->xsd->integer))),
8380
, 'Triple count is correct',
8481
);
8582

8683
pattern_ok( statement(iri($base_uri . '/fragments?subject=' . uri_escape_utf8('http://localhost/foo')),
87-
$dcterms->source,
84+
iri($ns->dct->source),
8885
$void_subject),
8986
, 'Void Subject in dct:source'
9087
);
@@ -93,43 +90,43 @@ my $void_subject = iri($base_uri . '/#dataset-0');
9390

9491
pattern_ok(
9592
statement($void_subject,
96-
$rdf->type,
97-
$hydra->Collection),
93+
iri($ns->rdf->type),
94+
iri($ns->hydra->Collection)),
9895
statement($void_subject,
99-
$hydra->search,
96+
iri($ns->hydra->search),
10097
blank('template')),
10198
statement(blank('template'),
102-
$hydra->template,
99+
iri($ns->hydra->template),
103100
literal($base_uri . '/fragments{?subject,predicate,object}')),
104101
statement(blank('template'),
105-
$hydra->mapping,
102+
iri($ns->hydra->mapping),
106103
blank('subject')),
107104
statement(blank('template'),
108-
$hydra->mapping,
105+
iri($ns->hydra->mapping),
109106
blank('predicate')),
110107
statement(blank('template'),
111-
$hydra->mapping,
108+
iri($ns->hydra->mapping),
112109
blank('predicate')),
113110
statement(blank('template'),
114-
$hydra->mapping,
111+
iri($ns->hydra->mapping),
115112
blank('object')),
116113
statement(blank('subject'),
117-
$hydra->property,
118-
$rdf->subject),
114+
iri($ns->hydra->property),
115+
iri($ns->rdf->subject)),
119116
statement(blank('subject'),
120-
$hydra->variable,
117+
iri($ns->hydra->variable),
121118
literal('subject')),
122119
statement(blank('predicate'),
123-
$hydra->property,
124-
$rdf->predicate),
120+
iri($ns->hydra->property),
121+
iri($ns->rdf->predicate)),
125122
statement(blank('predicate'),
126-
$hydra->variable,
123+
iri($ns->hydra->variable),
127124
literal('predicate')),
128125
statement(blank('object'),
129-
$hydra->property,
130-
$rdf->object),
126+
iri($ns->hydra->property),
127+
iri($ns->rdf->object)),
131128
statement(blank('object'),
132-
$hydra->variable,
129+
iri($ns->hydra->variable),
133130
literal('object')),
134131
"Control statements OK");
135132
}
@@ -140,16 +137,16 @@ my $void_subject = iri($base_uri . '/#dataset-0');
140137
is($response->status, 200, "Returns 200");
141138
my $retmodel = return_model($response->content, $parser);
142139
has_literal('Testing with longer URI.', 'en', undef, $retmodel, "Longer test phrase is in content");
143-
has_literal("1", undef, $xsd->integer, $retmodel, 'Triple count is correct');
140+
has_literal("1", undef, $ns->xsd->integer->as_string, $retmodel, 'Triple count is correct');
144141
hasnt_literal('This is a test', 'en', undef, $retmodel, "Test phrase isn't in content");
145142
}
146143
{
147144
my $response = $ld->response($base_uri . '/fragments?object=' . uri_escape_utf8('"42"^^http://www.w3.org/2001/XMLSchema#integer'));
148145
isa_ok($response, 'Plack::Response');
149146
is($response->status, 200, "Returns 200");
150147
my $retmodel = return_model($response->content, $parser);
151-
has_literal('42', undef, $xsd->integer, $retmodel, "The Answer is in the content");
152-
has_literal("1", undef, $xsd->integer, $retmodel, 'Triple count is correct');
148+
has_literal('42', undef, $ns->xsd->integer->as_string, $retmodel, "The Answer is in the content");
149+
has_literal("1", undef, $ns->xsd->integer->as_string, $retmodel, 'Triple count is correct');
153150
hasnt_literal('This is a test', 'en', undef, $retmodel, "Test phrase isn't in content");
154151
}
155152
{
@@ -158,7 +155,7 @@ my $void_subject = iri($base_uri . '/#dataset-0');
158155
is($response->status, 200, "Returns 200");
159156
my $retmodel = return_model($response->content, $parser);
160157
hasnt_literal('Testing with longer URI.', 'en', undef, $retmodel, "Longer test phrase is in content");
161-
has_literal("0", undef, $xsd->integer, $retmodel, 'Triple count is correct');
158+
has_literal("0", undef, $ns->xsd->integer->as_string, $retmodel, 'Triple count is correct');
162159
}
163160
{
164161
my $response = $ld->response($base_uri . '/fragments?predicate=' . uri_escape_utf8('http://www.w3.org/2000/01/rdf-schema#label') . '&subject=');
@@ -167,7 +164,7 @@ my $void_subject = iri($base_uri . '/#dataset-0');
167164
my $retmodel = return_model($response->content, $parser);
168165
has_subject($base_uri . '/foo', $retmodel, 'Subject 1 is correct');
169166
has_subject($base_uri . '/bar/baz/bing', $retmodel, 'Subject 2 is correct');
170-
has_literal("2", undef, $xsd->integer, $retmodel, 'Triple count is correct');
167+
has_literal("2", undef, $ns->xsd->integer->as_string, $retmodel, 'Triple count is correct');
171168
has_literal('This is a test', 'en', undef, $retmodel, "Test phrase is in content");
172169
}
173170
{
@@ -202,59 +199,59 @@ my $void_subject = iri($base_uri . '/#dataset-0');
202199
is($response->status, 200, "Returns 200");
203200
my $retmodel = return_model($response->content, $parser);
204201
has_subject($void_subject->uri_value, $retmodel, "Subject URI in content");
205-
has_predicate($hydra->search->uri_value, $retmodel, 'Hydra search predicate');
202+
has_predicate($ns->hydra->search->as_string, $retmodel, 'Hydra search predicate');
206203
pattern_target($retmodel);
207204
pattern_ok(
208205
statement(
209206
$void_subject,
210-
$void->triples,
211-
literal(4, undef, $xsd->integer)
207+
iri($ns->void->triples),
208+
literal(4, undef, iri($ns->xsd->integer))
212209
),
213210
statement(
214211
$void_subject,
215-
$rdf->type,
216-
$void->Dataset
212+
iri($ns->rdf->type),
213+
iri($ns->void->Dataset)
217214
),
218215
'VoID-specific statements');
219216
pattern_ok(
220217
statement($void_subject,
221-
$rdf->type,
222-
$hydra->Collection),
218+
iri($ns->rdf->type),
219+
iri($ns->hydra->Collection)),
223220
statement($void_subject,
224-
$hydra->search,
221+
iri($ns->hydra->search),
225222
blank('template')),
226223
statement(blank('template'),
227-
$hydra->template,
224+
iri($ns->hydra->template),
228225
literal($base_uri . '/fragments{?subject,predicate,object}')),
229226
statement(blank('template'),
230-
$hydra->mapping,
227+
iri($ns->hydra->mapping),
231228
blank('subject')),
232229
statement(blank('template'),
233-
$hydra->mapping,
230+
iri($ns->hydra->mapping),
234231
blank('predicate')),
235232
statement(blank('template'),
236-
$hydra->mapping,
233+
iri($ns->hydra->mapping),
237234
blank('predicate')),
238235
statement(blank('template'),
239-
$hydra->mapping,
236+
iri($ns->hydra->mapping),
240237
blank('object')),
241238
statement(blank('subject'),
242-
$hydra->property,
243-
$rdf->subject),
239+
iri($ns->hydra->property),
240+
iri($ns->rdf->subject)),
244241
statement(blank('subject'),
245-
$hydra->variable,
242+
iri($ns->hydra->variable),
246243
literal('subject')),
247244
statement(blank('predicate'),
248-
$hydra->property,
249-
$rdf->predicate),
245+
iri($ns->hydra->property),
246+
iri($ns->rdf->predicate)),
250247
statement(blank('predicate'),
251-
$hydra->variable,
248+
iri($ns->hydra->variable),
252249
literal('predicate')),
253250
statement(blank('object'),
254-
$hydra->property,
255-
$rdf->object),
251+
iri($ns->hydra->property),
252+
iri($ns->rdf->object)),
256253
statement(blank('object'),
257-
$hydra->variable,
254+
iri($ns->hydra->variable),
258255
literal('object')),
259256
"Control statements OK");
260257
}
@@ -278,7 +275,7 @@ my $void_subject = iri($base_uri . '/#dataset-0');
278275
isa_ok($response, 'Plack::Response');
279276
is($response->status, 200, "Returns 200 with all parameters empty");
280277
my $retmodel = return_model($response->content, $parser);
281-
has_literal("4", undef, $xsd->integer, $retmodel, 'Triple count is correct got all 4 triples');
278+
has_literal("4", undef, $ns->xsd->integer->as_string, $retmodel, 'Triple count is correct got all 4 triples');
282279
}
283280
}
284281

0 commit comments

Comments
 (0)