ld4l-ore_rdf 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +25 -0
- data/.travis.yml +12 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +14 -0
- data/README.md +171 -0
- data/Rakefile +2 -0
- data/ld4l-ore_rdf.gemspec +45 -0
- data/lib/ld4l/ore_rdf/configuration.rb +41 -0
- data/lib/ld4l/ore_rdf/models/aggregation.rb +50 -0
- data/lib/ld4l/ore_rdf/models/aggregation_resource.rb +98 -0
- data/lib/ld4l/ore_rdf/models/proxy_resource.rb +54 -0
- data/lib/ld4l/ore_rdf/services/aggregation/add_aggregated_resource.rb +49 -0
- data/lib/ld4l/ore_rdf/services/aggregation/add_aggregated_resources.rb +28 -0
- data/lib/ld4l/ore_rdf/services/aggregation/create.rb +39 -0
- data/lib/ld4l/ore_rdf/services/aggregation/destroy.rb +47 -0
- data/lib/ld4l/ore_rdf/services/aggregation/destroy_with_id.rb +22 -0
- data/lib/ld4l/ore_rdf/services/aggregation/find.rb +72 -0
- data/lib/ld4l/ore_rdf/services/aggregation/persist.rb +34 -0
- data/lib/ld4l/ore_rdf/services/aggregation/resume.rb +30 -0
- data/lib/ld4l/ore_rdf/services/proxy/create.rb +64 -0
- data/lib/ld4l/ore_rdf/services/proxy/find.rb +93 -0
- data/lib/ld4l/ore_rdf/version.rb +5 -0
- data/lib/ld4l/ore_rdf/vocab/co.rb +27 -0
- data/lib/ld4l/ore_rdf/vocab/dcterms.rb +6 -0
- data/lib/ld4l/ore_rdf/vocab/iana.rb +9 -0
- data/lib/ld4l/ore_rdf/vocab/ore.rb +16 -0
- data/lib/ld4l/ore_rdf.rb +76 -0
- data/spec/ld4l/ore_rdf/configuration_spec.rb +174 -0
- data/spec/ld4l/ore_rdf/models/aggregation_resource_spec.rb +830 -0
- data/spec/ld4l/ore_rdf/models/aggregation_spec.rb +9 -0
- data/spec/ld4l/ore_rdf/models/proxy_resource_spec.rb +690 -0
- data/spec/ld4l/ore_rdf/services/aggregation/add_aggregated_resource_spec.rb +36 -0
- data/spec/ld4l/ore_rdf/services/aggregation/add_aggregated_resources_spec.rb +78 -0
- data/spec/ld4l/ore_rdf/services/aggregation/create_spec.rb +62 -0
- data/spec/ld4l/ore_rdf/services/aggregation/destroy_spec.rb +169 -0
- data/spec/ld4l/ore_rdf/services/aggregation/find_spec.rb +198 -0
- data/spec/ld4l/ore_rdf/services/aggregation/persist_spec.rb +13 -0
- data/spec/ld4l/ore_rdf/services/aggregation/resume_spec.rb +46 -0
- data/spec/ld4l/ore_rdf/services/proxy/create_spec.rb +143 -0
- data/spec/ld4l/ore_rdf/services/proxy/find_spec.rb +138 -0
- data/spec/ld4l/ore_rdf_spec.rb +53 -0
- data/spec/spec_helper.rb +23 -0
- metadata +259 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'LD4L::OreRDF::AggregationResource::AddAggregatedResource' do
|
4
|
+
|
5
|
+
subject { LD4L::OreRDF::CreateAggregation.call(
|
6
|
+
title: "Test Title",
|
7
|
+
description: "Test description of aggregation.",
|
8
|
+
owner: LD4L::FoafRDF::Person.new("http://vivo.cornell.edu/individual/JohnSmith")) }
|
9
|
+
|
10
|
+
describe "#call" do
|
11
|
+
it "should return a LD4L::OreRDF::ProxyResource instance" do
|
12
|
+
proxy = LD4L::OreRDF::AddAggregatedResource.call( subject, RDF::URI("http://example.org/individual/b1") )
|
13
|
+
expect(proxy).to be_a(LD4L::OreRDF::ProxyResource)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should add a single resource to an empty set" do
|
17
|
+
subject.aggregates = []
|
18
|
+
LD4L::OreRDF::AddAggregatedResource.call( subject, RDF::URI("http://example.org/individual/b1") )
|
19
|
+
expect(subject.aggregates.first.rdf_subject).to eq RDF::URI("http://example.org/individual/b1")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should add a single resource to an existing set" do
|
23
|
+
subject.aggregates = RDF::URI("http://example.org/individual/b1" )
|
24
|
+
LD4L::OreRDF::AddAggregatedResource.call( subject, RDF::URI("http://example.org/individual/b2") )
|
25
|
+
expect(subject.aggregates[0].rdf_subject).to eq RDF::URI("http://example.org/individual/b1")
|
26
|
+
expect(subject.aggregates[1].rdf_subject).to eq RDF::URI("http://example.org/individual/b2")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should generate the resource instance for a single resource" do
|
30
|
+
proxy = LD4L::OreRDF::AddAggregatedResource.call( subject, RDF::URI("http://example.org/individual/b1" ))
|
31
|
+
expect(proxy.proxy_for.first.rdf_subject).to eq RDF::URI("http://example.org/individual/b1")
|
32
|
+
expect(proxy.proxy_in.first).to eq subject.aggregation_resource
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'LD4L::OreRDF::AddAggregatedResources' do
|
4
|
+
|
5
|
+
subject { LD4L::OreRDF::CreateAggregation.call(
|
6
|
+
title: "Test Title",
|
7
|
+
description: "Test description of aggregation.",
|
8
|
+
owner: LD4L::FoafRDF::Person.new("http://vivo.cornell.edu/individual/JohnSmith")) }
|
9
|
+
|
10
|
+
describe "#call" do
|
11
|
+
it "should return an array" do
|
12
|
+
proxy_array = LD4L::OreRDF::AddAggregatedResources.call(
|
13
|
+
subject,
|
14
|
+
[RDF::URI("http://example.org/individual/b1"),
|
15
|
+
RDF::URI("http://example.org/individual/b2"),
|
16
|
+
RDF::URI("http://example.org/individual/b3")])
|
17
|
+
expect(proxy_array).to be_a(Array)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return an array of LD4L::OreRDF::ProxyResource instances" do
|
21
|
+
proxy_array = LD4L::OreRDF::AddAggregatedResources.call(
|
22
|
+
subject,
|
23
|
+
[RDF::URI("http://example.org/individual/b1"),
|
24
|
+
RDF::URI("http://example.org/individual/b2"),
|
25
|
+
RDF::URI("http://example.org/individual/b3")])
|
26
|
+
proxy_array.each do |proxy|
|
27
|
+
expect(proxy).to be_a(LD4L::OreRDF::ProxyResource)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should add multiple resources to an empty set" do
|
32
|
+
subject.aggregates = []
|
33
|
+
LD4L::OreRDF::AddAggregatedResources.call(
|
34
|
+
subject,
|
35
|
+
[RDF::URI("http://example.org/individual/b1"),
|
36
|
+
RDF::URI("http://example.org/individual/b2"),
|
37
|
+
RDF::URI("http://example.org/individual/b3")])
|
38
|
+
aggregates = subject.aggregates
|
39
|
+
expect(aggregates).to include ActiveTriples::Resource.new(RDF::URI("http://example.org/individual/b1"))
|
40
|
+
expect(aggregates).to include ActiveTriples::Resource.new(RDF::URI("http://example.org/individual/b2"))
|
41
|
+
expect(aggregates).to include ActiveTriples::Resource.new(RDF::URI("http://example.org/individual/b3"))
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should add multiple resources to an existing set" do
|
45
|
+
subject.aggregates = RDF::URI("http://example.org/individual/b1")
|
46
|
+
LD4L::OreRDF::AddAggregatedResources.call(
|
47
|
+
subject,
|
48
|
+
[RDF::URI("http://example.org/individual/b2"),
|
49
|
+
RDF::URI("http://example.org/individual/b3"),
|
50
|
+
RDF::URI("http://example.org/individual/b4")])
|
51
|
+
aggregates = subject.aggregates
|
52
|
+
expect(aggregates).to include ActiveTriples::Resource.new(RDF::URI("http://example.org/individual/b1"))
|
53
|
+
expect(aggregates).to include ActiveTriples::Resource.new(RDF::URI("http://example.org/individual/b2"))
|
54
|
+
expect(aggregates).to include ActiveTriples::Resource.new(RDF::URI("http://example.org/individual/b3"))
|
55
|
+
expect(aggregates).to include ActiveTriples::Resource.new(RDF::URI("http://example.org/individual/b4"))
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should return an array of resource instances for each of the multiple resources" do
|
59
|
+
proxy_array = LD4L::OreRDF::AddAggregatedResources.call(
|
60
|
+
subject,
|
61
|
+
[RDF::URI("http://example.org/individual/b1"),
|
62
|
+
RDF::URI("http://example.org/individual/b2"),
|
63
|
+
RDF::URI("http://example.org/individual/b3")])
|
64
|
+
proxy_array.each do |proxy|
|
65
|
+
expect(proxy).to be_a(LD4L::OreRDF::ProxyResource)
|
66
|
+
expect(proxy.proxy_in.first).to eq subject.aggregation_resource
|
67
|
+
end
|
68
|
+
results = []
|
69
|
+
proxy_array.each do |proxy|
|
70
|
+
results << proxy.proxy_for.first
|
71
|
+
end
|
72
|
+
expect(results).to include ActiveTriples::Resource.new(RDF::URI("http://example.org/individual/b1"))
|
73
|
+
expect(results).to include ActiveTriples::Resource.new(RDF::URI("http://example.org/individual/b2"))
|
74
|
+
expect(results).to include ActiveTriples::Resource.new(RDF::URI("http://example.org/individual/b3"))
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'LD4L::OreRDF::CreateAggregation' do
|
4
|
+
|
5
|
+
describe "#call" do
|
6
|
+
it "should create a LD4L::OreRDF::AggregationResource instance" do
|
7
|
+
aggregation = LD4L::OreRDF::CreateAggregation.call(
|
8
|
+
title: "Test Title",
|
9
|
+
description: "Test description of aggregation.",
|
10
|
+
owner: LD4L::FoafRDF::Person.new("http://vivo.cornell.edu/individual/JohnSmith"))
|
11
|
+
expect(aggregation).to be_a(LD4L::OreRDF::Aggregation)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should create a aggregation with passed in properties excluding an id" do
|
15
|
+
aggregation = LD4L::OreRDF::CreateAggregation.call(
|
16
|
+
title: "Test Title",
|
17
|
+
description: "Test description of aggregation.",
|
18
|
+
owner: LD4L::FoafRDF::Person.new("http://vivo.cornell.edu/individual/JohnSmith"))
|
19
|
+
expect(aggregation.rdf_subject.to_s).to start_with(
|
20
|
+
"#{LD4L::OreRDF::AggregationResource.base_uri}#{LD4L::OreRDF::AggregationResource.localname_prefix}")
|
21
|
+
expect(aggregation.title).to eq "Test Title"
|
22
|
+
expect(aggregation.description).to eq "Test description of aggregation."
|
23
|
+
expect(aggregation.owner.first.rdf_subject).to eq RDF::URI("http://vivo.cornell.edu/individual/JohnSmith")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should create a aggregation with partial id" do
|
27
|
+
aggregation = LD4L::OreRDF::CreateAggregation.call(
|
28
|
+
id: "123",
|
29
|
+
title: "Test Title",
|
30
|
+
description: "Test description of aggregation.",
|
31
|
+
owner: LD4L::FoafRDF::Person.new("http://vivo.cornell.edu/individual/JohnSmith"))
|
32
|
+
expect(aggregation.rdf_subject.to_s).to eq "#{LD4L::OreRDF::AggregationResource.base_uri}123"
|
33
|
+
expect(aggregation.title).to eq "Test Title"
|
34
|
+
expect(aggregation.description).to eq "Test description of aggregation."
|
35
|
+
expect(aggregation.owner.first.rdf_subject).to eq RDF::URI("http://vivo.cornell.edu/individual/JohnSmith")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should create a aggregation with string uri id" do
|
39
|
+
aggregation = LD4L::OreRDF::CreateAggregation.call(
|
40
|
+
id: "http://example.org/individual/vc123",
|
41
|
+
title: "Test Title",
|
42
|
+
description: "Test description of aggregation.",
|
43
|
+
owner: LD4L::FoafRDF::Person.new("http://vivo.cornell.edu/individual/JohnSmith"))
|
44
|
+
expect(aggregation.rdf_subject.to_s).to eq "http://example.org/individual/vc123"
|
45
|
+
expect(aggregation.title).to eq "Test Title"
|
46
|
+
expect(aggregation.description).to eq "Test description of aggregation."
|
47
|
+
expect(aggregation.owner.first.rdf_subject).to eq RDF::URI("http://vivo.cornell.edu/individual/JohnSmith")
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should create a aggregation with URI id" do
|
51
|
+
aggregation = LD4L::OreRDF::CreateAggregation.call(
|
52
|
+
id: RDF::URI("http://example.org/individual/vc123"),
|
53
|
+
title: "Test Title",
|
54
|
+
description: "Test description of aggregation.",
|
55
|
+
owner: LD4L::FoafRDF::Person.new("http://vivo.cornell.edu/individual/JohnSmith"))
|
56
|
+
expect(aggregation.rdf_subject.to_s).to eq "http://example.org/individual/vc123"
|
57
|
+
expect(aggregation.title).to eq "Test Title"
|
58
|
+
expect(aggregation.description).to eq "Test description of aggregation."
|
59
|
+
expect(aggregation.owner.first.rdf_subject).to eq RDF::URI("http://vivo.cornell.edu/individual/JohnSmith")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'LD4L::OreRDF::DestroyAggregation' do
|
4
|
+
|
5
|
+
describe "#call" do
|
6
|
+
|
7
|
+
context "when aggregation hasn't been persisted" do
|
8
|
+
before do
|
9
|
+
ActiveTriples::Repositories.add_repository :default, RDF::Repository.new
|
10
|
+
end
|
11
|
+
after do
|
12
|
+
ActiveTriples::Repositories.add_repository :default, RDF::Repository.new
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return true if never persisted" do
|
16
|
+
id = "http::/example.org/NOT_PERSISTED"
|
17
|
+
aggregation = LD4L::OreRDF::CreateAggregation.call(
|
18
|
+
id: id,
|
19
|
+
title: "Unpersisted Aggregation",
|
20
|
+
description: "Test aggregation that isn't persisted." )
|
21
|
+
expect( LD4L::OreRDF::DestroyAggregation.call(aggregation) ).to be true
|
22
|
+
expect( LD4L::OreRDF::ResumeAggregation.call(id) ).to be nil
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when aggregation doesn't have proxies" do
|
28
|
+
before do
|
29
|
+
ActiveTriples::Repositories.add_repository :default, RDF::Repository.new
|
30
|
+
@id = "http::/example.org/NO_PROXIES"
|
31
|
+
@aggregation = LD4L::OreRDF::CreateAggregation.call(
|
32
|
+
id: @id,
|
33
|
+
title: "No Proxy Aggregation",
|
34
|
+
description: "Test aggregation with no proxies." )
|
35
|
+
LD4L::OreRDF::PersistAggregation.call(@aggregation)
|
36
|
+
expect( LD4L::OreRDF::ResumeAggregation.call(@id).rdf_subject.to_s ).to eq @id
|
37
|
+
end
|
38
|
+
after do
|
39
|
+
ActiveTriples::Repositories.add_repository :default, RDF::Repository.new
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should destroy aggregation resource and return true" do
|
43
|
+
expect( LD4L::OreRDF::DestroyAggregation.call(@aggregation) ).to be true
|
44
|
+
expect( LD4L::OreRDF::ResumeAggregation.call(@id) ).to eq nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when aggregation has proxies" do
|
49
|
+
before do
|
50
|
+
ActiveTriples::Repositories.add_repository :default, RDF::Repository.new
|
51
|
+
@id1 = "http::/example.org/ag1"
|
52
|
+
@ag1 = LD4L::OreRDF::CreateAggregation.call(
|
53
|
+
id: @id1,
|
54
|
+
title: "Aggregation 1",
|
55
|
+
description: "Test aggregation with proxies." )
|
56
|
+
LD4L::OreRDF::AddAggregatedResources.call(
|
57
|
+
@ag1,
|
58
|
+
[RDF::URI("http://example.org/individual/b11"),
|
59
|
+
RDF::URI("http://example.org/individual/b12"),
|
60
|
+
RDF::URI("http://example.org/individual/b13")])
|
61
|
+
LD4L::OreRDF::PersistAggregation.call(@ag1)
|
62
|
+
a1 = LD4L::OreRDF::ResumeAggregation.call(@id1)
|
63
|
+
expect( a1.aggregation_resource.rdf_subject.to_s ).to eq @id1
|
64
|
+
expect( a1.proxy_resources.length).to eq 3
|
65
|
+
|
66
|
+
@id2 = "http::/example.org/ag2"
|
67
|
+
@ag2 = LD4L::OreRDF::CreateAggregation.call(
|
68
|
+
id: @id2,
|
69
|
+
title: "Aggregation 2",
|
70
|
+
description: "Test description of aggregation 2.",
|
71
|
+
owner: p )
|
72
|
+
LD4L::OreRDF::AddAggregatedResources.call(
|
73
|
+
@ag2,
|
74
|
+
[RDF::URI("http://example.org/individual/b21"),
|
75
|
+
RDF::URI("http://example.org/individual/b22"),
|
76
|
+
RDF::URI("http://example.org/individual/b23")])
|
77
|
+
LD4L::OreRDF::PersistAggregation.call(@ag2)
|
78
|
+
a2 = LD4L::OreRDF::ResumeAggregation.call(@id2)
|
79
|
+
expect( a2.aggregation_resource.rdf_subject.to_s ).to eq @id2
|
80
|
+
expect( a2.proxy_resources.length).to eq 3
|
81
|
+
|
82
|
+
@id3 = "http::/example.org/ag3"
|
83
|
+
@ag3 = LD4L::OreRDF::CreateAggregation.call(
|
84
|
+
id: @id3,
|
85
|
+
title: "Aggregation 3",
|
86
|
+
description: "Test description of aggregation 3.",
|
87
|
+
owner: p )
|
88
|
+
LD4L::OreRDF::PersistAggregation.call(@ag3)
|
89
|
+
a3 = LD4L::OreRDF::ResumeAggregation.call(@id3)
|
90
|
+
expect( a3.aggregation_resource.rdf_subject.to_s ).to eq @id3
|
91
|
+
expect( a3.proxy_resources.length).to eq 0
|
92
|
+
end
|
93
|
+
after do
|
94
|
+
ActiveTriples::Repositories.add_repository :default, RDF::Repository.new
|
95
|
+
end
|
96
|
+
|
97
|
+
context "and all parts are persisted" do
|
98
|
+
it "should destroy aggregation resource and all proxy resources and return true" do
|
99
|
+
expect( LD4L::OreRDF::DestroyAggregation.call(@ag1) ).to be true
|
100
|
+
expect( LD4L::OreRDF::ResumeAggregation.call(@id1) ).to eq nil
|
101
|
+
|
102
|
+
# verify other objects are unchanged
|
103
|
+
ag2 = LD4L::OreRDF::ResumeAggregation.call(@id2)
|
104
|
+
expect( ag2.rdf_subject.to_s ).to eq @id2
|
105
|
+
expect( ag2.proxy_resources.length).to eq 3
|
106
|
+
|
107
|
+
ag3 = LD4L::OreRDF::ResumeAggregation.call(@id3)
|
108
|
+
expect( ag3.rdf_subject.to_s ).to eq @id3
|
109
|
+
expect( ag3.proxy_resources.length).to eq 0
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "and some proxies are persisted" do
|
114
|
+
it "should destroy aggregation resource and persisted proxy resources and return true" do
|
115
|
+
LD4L::OreRDF::AddAggregatedResources.call(
|
116
|
+
@ag2,
|
117
|
+
[RDF::URI("http://example.org/individual/b24"),
|
118
|
+
RDF::URI("http://example.org/individual/b25")])
|
119
|
+
expect( @ag2.rdf_subject.to_s ).to eq @id2
|
120
|
+
expect( @ag2.proxy_resources.length).to eq 5
|
121
|
+
|
122
|
+
expect( LD4L::OreRDF::DestroyAggregation.call(@ag2) ).to be true
|
123
|
+
expect( LD4L::OreRDF::ResumeAggregation.call(@id2) ).to eq nil
|
124
|
+
|
125
|
+
# verify other objects are unchanged
|
126
|
+
ag1 = LD4L::OreRDF::ResumeAggregation.call(@id1)
|
127
|
+
expect( ag1.rdf_subject.to_s ).to eq @id1
|
128
|
+
expect( ag1.proxy_resources.length).to eq 3
|
129
|
+
|
130
|
+
ag3 = LD4L::OreRDF::ResumeAggregation.call(@id3)
|
131
|
+
expect( ag3.rdf_subject.to_s ).to eq @id3
|
132
|
+
expect( ag3.proxy_resources.length).to eq 0
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context "and no proxies are persisted" do
|
137
|
+
it "should destroy aggregation resource and return true" do
|
138
|
+
LD4L::OreRDF::AddAggregatedResources.call(
|
139
|
+
@ag3,
|
140
|
+
[RDF::URI("http://example.org/individual/b31"),
|
141
|
+
RDF::URI("http://example.org/individual/b32")])
|
142
|
+
expect( @ag3.rdf_subject.to_s ).to eq @id3
|
143
|
+
expect( @ag3.proxy_resources.length).to eq 2
|
144
|
+
|
145
|
+
expect( LD4L::OreRDF::DestroyAggregation.call(@ag3) ).to be true
|
146
|
+
expect( LD4L::OreRDF::ResumeAggregation.call(@id3) ).to eq nil
|
147
|
+
|
148
|
+
# verify other objects are unchanged
|
149
|
+
ag1 = LD4L::OreRDF::ResumeAggregation.call(@id1)
|
150
|
+
expect( ag1.rdf_subject.to_s ).to eq @id1
|
151
|
+
expect( ag1.proxy_resources.length).to eq 3
|
152
|
+
|
153
|
+
ag2 = LD4L::OreRDF::ResumeAggregation.call(@id2)
|
154
|
+
expect( ag2.rdf_subject.to_s ).to eq @id2
|
155
|
+
expect( ag2.proxy_resources.length).to eq 3
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context "when invalid parameters" do
|
161
|
+
it "should raise error if aggregation isn't LD4L::OreRDF::Aggregation" do
|
162
|
+
expect{ LD4L::OreRDF::DestroyAggregation.call('BAD VALUE') }.to raise_error(
|
163
|
+
ArgumentError,'aggregation must be an LD4L::OreRDF::Aggregation')
|
164
|
+
expect{ LD4L::OreRDF::DestroyAggregation.call(nil) }.to raise_error(
|
165
|
+
ArgumentError,'aggregation must be an LD4L::OreRDF::Aggregation')
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,198 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'LD4L::OreRDF::FindAggregations' do
|
4
|
+
|
5
|
+
describe "#call" do
|
6
|
+
|
7
|
+
context "when repository is empty" do
|
8
|
+
before do
|
9
|
+
ActiveTriples::Repositories.add_repository :default, RDF::Repository.new
|
10
|
+
end
|
11
|
+
it "should return an empty array" do
|
12
|
+
aggregations = LD4L::OreRDF::FindAggregations.call
|
13
|
+
expect(aggregations).to eq []
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when repository has one aggregation" do
|
18
|
+
before do
|
19
|
+
p = LD4L::FoafRDF::Person.new("http://vivo.cornell.edu/individual/JohnSmith")
|
20
|
+
p.persist!
|
21
|
+
|
22
|
+
ag1 = LD4L::OreRDF::CreateAggregation.call(
|
23
|
+
id: "http::/example.org/ag1",
|
24
|
+
title: "Aggregation 1",
|
25
|
+
description: "Test description of aggregation 1.",
|
26
|
+
owner: p )
|
27
|
+
LD4L::OreRDF::AddAggregatedResources.call(
|
28
|
+
ag1,
|
29
|
+
[RDF::URI("http://example.org/individual/b11"),
|
30
|
+
RDF::URI("http://example.org/individual/b12"),
|
31
|
+
RDF::URI("http://example.org/individual/b13")])
|
32
|
+
LD4L::OreRDF::PersistAggregation.call(ag1)
|
33
|
+
end
|
34
|
+
after do
|
35
|
+
ActiveTriples::Repositories.add_repository :default, RDF::Repository.new
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return an array with 1 value" do
|
39
|
+
aggregations = LD4L::OreRDF::FindAggregations.call
|
40
|
+
expect(aggregations).to eq [ RDF::URI("http::/example.org/ag1") ]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when repository has multiple aggregations" do
|
45
|
+
before do
|
46
|
+
p = LD4L::FoafRDF::Person.new("http://vivo.cornell.edu/individual/JohnSmith")
|
47
|
+
p.persist!
|
48
|
+
|
49
|
+
ag1 = LD4L::OreRDF::CreateAggregation.call(
|
50
|
+
id: "http::/example.org/ag1",
|
51
|
+
title: "Aggregation 1",
|
52
|
+
description: "Test description of aggregation 1.",
|
53
|
+
owner: p )
|
54
|
+
LD4L::OreRDF::AddAggregatedResources.call(
|
55
|
+
ag1,
|
56
|
+
[RDF::URI("http://example.org/individual/b11"),
|
57
|
+
RDF::URI("http://example.org/individual/b12"),
|
58
|
+
RDF::URI("http://example.org/individual/b13")])
|
59
|
+
LD4L::OreRDF::PersistAggregation.call(ag1)
|
60
|
+
|
61
|
+
ag2 = LD4L::OreRDF::CreateAggregation.call(
|
62
|
+
id: "http::/example.org/ag2",
|
63
|
+
title: "Aggregation 2",
|
64
|
+
description: "Test description of aggregation 2.",
|
65
|
+
owner: p )
|
66
|
+
LD4L::OreRDF::AddAggregatedResources.call(
|
67
|
+
ag2,
|
68
|
+
[RDF::URI("http://example.org/individual/b21"),
|
69
|
+
RDF::URI("http://example.org/individual/b22"),
|
70
|
+
RDF::URI("http://example.org/individual/b23")])
|
71
|
+
LD4L::OreRDF::PersistAggregation.call(ag2)
|
72
|
+
|
73
|
+
ag3 = LD4L::OreRDF::CreateAggregation.call(
|
74
|
+
id: "http::/example.org/ag3",
|
75
|
+
title: "Aggregation 3",
|
76
|
+
description: "Test description of aggregation 3.",
|
77
|
+
owner: p )
|
78
|
+
LD4L::OreRDF::AddAggregatedResources.call(
|
79
|
+
ag3,
|
80
|
+
[RDF::URI("http://example.org/individual/b31"),
|
81
|
+
RDF::URI("http://example.org/individual/b32"),
|
82
|
+
RDF::URI("http://example.org/individual/b33")])
|
83
|
+
LD4L::OreRDF::PersistAggregation.call(ag3)
|
84
|
+
end
|
85
|
+
after do
|
86
|
+
ActiveTriples::Repositories.add_repository :default, RDF::Repository.new
|
87
|
+
end
|
88
|
+
|
89
|
+
xit "should find aggregation by rdf_subject" do
|
90
|
+
|
91
|
+
|
92
|
+
# TODO not sure how to write the criteria for this test
|
93
|
+
|
94
|
+
|
95
|
+
aggregations = LD4L::OreRDF::FindAggregations.call(:criteria => { :subject => "http::/example.org/ag3"})
|
96
|
+
expect(aggregations).not_to include "http::/example.org/ag1"
|
97
|
+
expect(aggregations).not_to include "http::/example.org/ag2"
|
98
|
+
expect(aggregations).to include "http::/example.org/ag3"
|
99
|
+
expect(aggregations.size).to eq 1
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should find aggregation by literal criteria (aka title)" do
|
103
|
+
aggregations = LD4L::OreRDF::FindAggregations.call(:criteria => { RDF::DC.title => "Aggregation 2"})
|
104
|
+
expect(aggregations).not_to include "http::/example.org/ag1"
|
105
|
+
expect(aggregations).to include "http::/example.org/ag2"
|
106
|
+
expect(aggregations).not_to include "http::/example.org/ag3"
|
107
|
+
expect(aggregations.size).to eq 1
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should find aggregation by rdf uri criteria (aka aggregates)" do
|
111
|
+
aggregations = LD4L::OreRDF::FindAggregations.call(
|
112
|
+
:criteria => { RDFVocabularies::ORE.aggregates => RDF::URI("http://example.org/individual/b32")})
|
113
|
+
expect(aggregations).not_to include "http::/example.org/ag1"
|
114
|
+
expect(aggregations).not_to include "http::/example.org/ag2"
|
115
|
+
expect(aggregations).to include "http::/example.org/ag3"
|
116
|
+
expect(aggregations.size).to eq 1
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should return empty array when criteria (aka title) doesn't match any aggregations" do
|
120
|
+
aggregations = LD4L::OreRDF::FindAggregations.call(:criteria => { RDF::DC.title => "NON-EXISTENT TITLE"})
|
121
|
+
expect(aggregations).to eq []
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should find all aggregations" do
|
125
|
+
aggregations = LD4L::OreRDF::FindAggregations.call
|
126
|
+
expect(aggregations).to include "http::/example.org/ag1"
|
127
|
+
expect(aggregations).to include "http::/example.org/ag2"
|
128
|
+
expect(aggregations).to include "http::/example.org/ag3"
|
129
|
+
expect(aggregations.size).to eq 3
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should resume all aggregation & proxies when resume = true" do
|
133
|
+
aggregations = LD4L::OreRDF::FindAggregations.call(:resume => true)
|
134
|
+
ag_uris = ["http::/example.org/ag1","http::/example.org/ag2","http::/example.org/ag3"]
|
135
|
+
aggregations.each_key do |a|
|
136
|
+
expect(a).to be_kind_of(RDF::URI)
|
137
|
+
expect(aggregations[a]).to be_kind_of(LD4L::OreRDF::Aggregation)
|
138
|
+
expect(ag_uris).to include aggregations[a].aggregation_resource.rdf_subject.to_str
|
139
|
+
end
|
140
|
+
expect(aggregations.size).to eq 3
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should return values for specified literal property in results when criteria specified" do
|
144
|
+
aggregations = LD4L::OreRDF::FindAggregations.call(
|
145
|
+
:criteria => { RDF::DC.title => "Aggregation 2" },
|
146
|
+
:properties => { :description => RDF::DC.description } )
|
147
|
+
expect(aggregations).to eq ( { RDF::URI("http::/example.org/ag2") => {
|
148
|
+
:description => RDF::Literal("Test description of aggregation 2.") } } )
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should return values for specified properties in results when criteria not specified" do
|
152
|
+
aggregations = LD4L::OreRDF::FindAggregations.call(
|
153
|
+
:properties => { :title => RDF::DC.title, :description => RDF::DC.description } )
|
154
|
+
expect(aggregations.size).to eq 3
|
155
|
+
expect(aggregations).to have_key RDF::URI("http::/example.org/ag1")
|
156
|
+
expect(aggregations).to have_key RDF::URI("http::/example.org/ag2")
|
157
|
+
expect(aggregations).to have_key RDF::URI("http::/example.org/ag3")
|
158
|
+
expect(aggregations[RDF::URI("http::/example.org/ag1")]).to eq( {
|
159
|
+
:title => RDF::Literal("Aggregation 1"),
|
160
|
+
:description => RDF::Literal("Test description of aggregation 1.") } )
|
161
|
+
expect(aggregations[RDF::URI("http::/example.org/ag2")]).to eq( {
|
162
|
+
:title => RDF::Literal("Aggregation 2"),
|
163
|
+
:description => RDF::Literal("Test description of aggregation 2.") } )
|
164
|
+
expect(aggregations[RDF::URI("http::/example.org/ag3")]).to eq( {
|
165
|
+
:title => RDF::Literal("Aggregation 3"),
|
166
|
+
:description => RDF::Literal("Test description of aggregation 3.") } )
|
167
|
+
end
|
168
|
+
|
169
|
+
|
170
|
+
xit "should search another repository if specified" do
|
171
|
+
# TODO WRITE TEST
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
context "when arguments are invalid" do
|
176
|
+
it "should raise error when repository isn't a symbol" do
|
177
|
+
expect{ LD4L::OreRDF::FindAggregations.call(:repository => 'BAD VALUE') }.to raise_error(
|
178
|
+
ArgumentError,'repository must be a symbol')
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should raise error when repository is a symbol, but isn't a registered repository" do
|
182
|
+
expect{ LD4L::OreRDF::FindAggregations.call(:repository => :nonexistent_repo) }.to raise_error(
|
183
|
+
ArgumentError,'repository must be a registered repository')
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should raise error when resume is other than true or false" do
|
187
|
+
expect{ LD4L::OreRDF::FindAggregations.call(:resume => 'BAD VALUE') }.to raise_error(
|
188
|
+
ArgumentError,'resume must be true or false' )
|
189
|
+
end
|
190
|
+
|
191
|
+
xit "should raise error when criteria is other than nil or a Hash" do
|
192
|
+
expect{ LD4L::OreRDF::FindAggregations.call(:criteria => 'BAD VALUE') }.to raise_error(
|
193
|
+
ArgumentError,'criteria must be a hash of attribute-value pairs for searching for aggregations' )
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
198
|
+
end
|