roadforest 0.0.3 → 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/examples/file-management.rb +7 -9
- data/lib/roadforest/application/dispatcher.rb +44 -31
- data/lib/roadforest/application/parameters.rb +5 -4
- data/lib/roadforest/application/path-provider.rb +14 -1
- data/lib/roadforest/application/route-adapter.rb +15 -4
- data/lib/roadforest/application/services-host.rb +41 -7
- data/lib/roadforest/application.rb +4 -8
- data/lib/roadforest/authorization.rb +231 -0
- data/lib/roadforest/blob-model.rb +2 -11
- data/lib/roadforest/content-handling/engine.rb +12 -6
- data/lib/roadforest/content-handling/handler-wrap.rb +45 -0
- data/lib/roadforest/content-handling/media-type.rb +20 -12
- data/lib/roadforest/content-handling/type-handler.rb +76 -0
- data/lib/roadforest/content-handling/type-handlers/jsonld.rb +2 -146
- data/lib/roadforest/content-handling/type-handlers/rdf-handler.rb +38 -0
- data/lib/roadforest/content-handling/type-handlers/rdfa-writer/document-environment.rb +34 -0
- data/lib/roadforest/content-handling/type-handlers/rdfa-writer/object-environment.rb +62 -0
- data/lib/roadforest/content-handling/type-handlers/rdfa-writer/property-environment.rb +46 -0
- data/lib/roadforest/content-handling/type-handlers/rdfa-writer/render-engine.rb +574 -0
- data/lib/roadforest/content-handling/type-handlers/rdfa-writer/render-environment.rb +144 -0
- data/lib/roadforest/content-handling/type-handlers/rdfa-writer/subject-environment.rb +80 -0
- data/lib/roadforest/content-handling/type-handlers/rdfa-writer.rb +163 -0
- data/lib/roadforest/content-handling/type-handlers/rdfa.rb +175 -0
- data/lib/roadforest/content-handling/type-handlers/rdfpost.rb +297 -0
- data/lib/roadforest/debug.rb +10 -0
- data/lib/roadforest/http/graph-response.rb +3 -7
- data/lib/roadforest/http/graph-transfer.rb +28 -106
- data/lib/roadforest/http/keychain.rb +79 -0
- data/lib/roadforest/http/message.rb +9 -1
- data/lib/roadforest/http/user-agent.rb +115 -0
- data/lib/roadforest/http.rb +8 -0
- data/lib/roadforest/model.rb +48 -3
- data/lib/roadforest/rdf/graph-focus.rb +5 -3
- data/lib/roadforest/rdf/graph-store.rb +4 -2
- data/lib/roadforest/rdf/normalization.rb +6 -1
- data/lib/roadforest/remote-host.rb +22 -7
- data/lib/roadforest/resource/rdf/read-only.rb +15 -1
- data/lib/roadforest/templates/base/doc.haml +13 -0
- data/lib/roadforest/templates/base/property_value.haml +12 -0
- data/lib/roadforest/templates/base/property_values.haml +6 -0
- data/lib/roadforest/templates/base/subject.haml +4 -0
- data/lib/roadforest/templates/distiller/doc.haml +20 -0
- data/lib/roadforest/templates/distiller/nil-object.haml +1 -0
- data/lib/roadforest/templates/distiller/property_value.haml +7 -0
- data/lib/roadforest/templates/distiller/property_values.haml +7 -0
- data/lib/roadforest/templates/distiller/subject.haml +5 -0
- data/lib/roadforest/templates/min/doc.haml +10 -0
- data/lib/roadforest/templates/min/property_values.haml +7 -0
- data/lib/roadforest/templates/min/subject.haml +2 -0
- data/lib/roadforest/templates/nil-object.haml +0 -0
- data/lib/roadforest/templates/node-object.haml +1 -0
- data/lib/roadforest/templates/object.haml +1 -0
- data/lib/roadforest/templates/uri-object.haml +1 -0
- data/lib/roadforest/templates/xml-literal-object.haml +1 -0
- data/lib/roadforest/utility/class-registry.rb +4 -0
- data/spec/client.rb +119 -77
- data/spec/{excon-adapater.rb → excon-adapter.rb} +4 -0
- data/spec/full-integration.rb +6 -2
- data/spec/graph-store.rb +1 -1
- data/spec/media-types.rb +29 -2
- metadata +102 -125
data/spec/client.rb
CHANGED
@@ -21,11 +21,15 @@ describe RoadForest::RemoteHost do
|
|
21
21
|
FileManagementExample::FileRecord.new("three", false)
|
22
22
|
]
|
23
23
|
host.destination_dir = destination_dir
|
24
|
+
host.authz.authenticator.add_account("user", "secret", "token")
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
|
-
let :
|
28
|
-
RoadForest::TestSupport::RemoteHost.new(FileManagementExample::Application.new("http://localhost:8778", services))
|
28
|
+
let :base_server do
|
29
|
+
RoadForest::TestSupport::RemoteHost.new(FileManagementExample::Application.new("http://localhost:8778", services)).tap do |server|
|
30
|
+
server.add_credentials("user", "secret")
|
31
|
+
#server.trace = true
|
32
|
+
end
|
29
33
|
end
|
30
34
|
|
31
35
|
def dump_trace
|
@@ -46,125 +50,163 @@ describe RoadForest::RemoteHost do
|
|
46
50
|
FileUtils.mkdir_p(destination_dir)
|
47
51
|
end
|
48
52
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
53
|
+
shared_examples_for "client-server interaction" do
|
54
|
+
describe "raw put of file data" do
|
55
|
+
before :each do
|
56
|
+
@destination = nil
|
57
|
+
server.getting do |graph|
|
58
|
+
items = graph.all(:skos, "hasTopConcept")
|
59
|
+
|
60
|
+
unresolved = items.find do |nav_item|
|
61
|
+
nav_item[:skos, "prefLabel"] == "Unresolved"
|
62
|
+
end
|
63
|
+
|
64
|
+
target = unresolved.first(:foaf, "page")
|
54
65
|
|
55
|
-
|
56
|
-
nav_item[:skos, "label"] == "Unresolved"
|
66
|
+
@destination = target.first(:lc, "needs").as_list.first[:lc, "contents"]
|
57
67
|
end
|
58
68
|
|
59
|
-
|
69
|
+
unless @destination.nil?
|
70
|
+
File::open(source_path) do |file|
|
71
|
+
server.put_file(@destination, "text/plain", file)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
60
75
|
|
61
|
-
|
76
|
+
it "should be able to format traces correctly" do
|
77
|
+
RoadForest::TestSupport::FSM.trace_dump.should =~ /Decision/
|
62
78
|
end
|
63
79
|
|
64
|
-
|
65
|
-
|
66
|
-
server.put_file(@destination, "text/plain", file)
|
67
|
-
end
|
80
|
+
it "should set destination" do
|
81
|
+
@destination.to_context.to_s.should == "http://localhost:8778/files/one"
|
68
82
|
end
|
69
|
-
end
|
70
83
|
|
71
|
-
|
72
|
-
|
84
|
+
it "should deliver file to destination path" do
|
85
|
+
File::read(File::join(destination_dir, "one")).should ==
|
86
|
+
File::read(source_path)
|
87
|
+
end
|
73
88
|
end
|
74
89
|
|
75
|
-
|
76
|
-
|
77
|
-
|
90
|
+
describe "posting data to server" do
|
91
|
+
before :each do
|
92
|
+
begin
|
93
|
+
server.posting do |graph|
|
94
|
+
items = graph.all(:skos, "hasTopConcept")
|
95
|
+
|
96
|
+
unresolved = items.find do |nav_item|
|
97
|
+
nav_item[:skos, "prefLabel"] == "Unresolved"
|
98
|
+
end
|
99
|
+
|
100
|
+
target = unresolved.first(:foaf, "page")
|
101
|
+
|
102
|
+
target.post_to do |new_need|
|
103
|
+
new_need[[:lc, "name"]] = "lawyers/guns/money"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
ensure
|
107
|
+
dump_trace
|
108
|
+
end
|
109
|
+
end
|
78
110
|
|
79
|
-
|
80
|
-
|
81
|
-
|
111
|
+
it "should change the server state" do
|
112
|
+
services.file_records.find do |record|
|
113
|
+
record.name == "lawyers/guns/money"
|
114
|
+
end.should be_an_instance_of FileManagementExample::FileRecord
|
115
|
+
end
|
82
116
|
end
|
83
|
-
end
|
84
117
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
118
|
+
describe "putting data to server" do
|
119
|
+
before :each do
|
120
|
+
server.putting do |graph|
|
121
|
+
require 'rdf/turtle'
|
89
122
|
items = graph.all(:skos, "hasTopConcept")
|
90
123
|
|
91
124
|
unresolved = items.find do |nav_item|
|
92
|
-
nav_item[:skos, "
|
125
|
+
nav_item[:skos, "prefLabel"] == "Unresolved"
|
93
126
|
end
|
94
127
|
|
95
128
|
target = unresolved.first(:foaf, "page")
|
96
129
|
|
97
|
-
target.
|
98
|
-
|
130
|
+
needs = target.first(:lc, "needs")
|
131
|
+
needs = needs.as_list
|
132
|
+
|
133
|
+
needs.each do |need|
|
134
|
+
need[[:lc, "resolved"]] = true
|
99
135
|
end
|
100
136
|
end
|
101
|
-
ensure
|
102
|
-
dump_trace
|
103
137
|
end
|
104
|
-
end
|
105
138
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
end.should be_an_instance_of FileManagementExample::FileRecord
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
describe "putting data to server" do
|
114
|
-
before :each do
|
115
|
-
server.putting do |graph|
|
116
|
-
items = graph.all(:skos, "hasTopConcept")
|
117
|
-
|
118
|
-
unresolved = items.find do |nav_item|
|
119
|
-
nav_item[:skos, "label"] == "Unresolved"
|
139
|
+
it "should change the server state" do
|
140
|
+
services.file_records.each do |record|
|
141
|
+
record.resolved.should == true
|
120
142
|
end
|
143
|
+
end
|
121
144
|
|
122
|
-
|
145
|
+
it "should change the server's responses" do
|
146
|
+
server.getting do |graph|
|
147
|
+
@correct = 0
|
148
|
+
items = graph.all(:skos, "hasTopConcept")
|
123
149
|
|
124
|
-
|
150
|
+
unresolved = items.find do |nav_item|
|
151
|
+
nav_item[:skos, "prefLabel"] == "Unresolved"
|
152
|
+
end
|
125
153
|
|
126
|
-
|
127
|
-
|
154
|
+
unresolved.first(:foaf, "page").first(:lc, "needs").as_list.each do |need|
|
155
|
+
@correct += 1
|
156
|
+
end
|
128
157
|
end
|
158
|
+
|
159
|
+
@correct.should == 0
|
129
160
|
end
|
130
|
-
end
|
131
161
|
|
132
|
-
|
133
|
-
|
134
|
-
|
162
|
+
it "should extract data from server responses" do
|
163
|
+
server.should match_query do
|
164
|
+
pattern(:subject, [:lc, "path"], nil)
|
165
|
+
pattern(:subject, [:lc, "file"], nil)
|
166
|
+
end
|
135
167
|
end
|
136
|
-
end
|
137
168
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
items = graph.all(:skos, "hasTopConcept")
|
169
|
+
it "should have transmitted data" do
|
170
|
+
server.http_exchanges.should_not be_empty
|
171
|
+
end
|
142
172
|
|
143
|
-
|
144
|
-
|
173
|
+
it "should return correct content-type" do
|
174
|
+
server.http_exchanges.each do |exchange|
|
175
|
+
exchange.response.headers["Content-Type"].should == content_type
|
145
176
|
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
146
180
|
|
147
|
-
|
148
|
-
|
181
|
+
describe "using JSON-LD" do
|
182
|
+
let :server do
|
183
|
+
base_server.tap do |server|
|
184
|
+
server.graph_transfer.type_handling = RoadForest::ContentHandling::Engine.new.tap do |engine|
|
185
|
+
engine.add RoadForest::MediaType::Handlers::JSONLD.new, "application/ld+json"
|
149
186
|
end
|
150
187
|
end
|
188
|
+
end
|
151
189
|
|
152
|
-
|
190
|
+
let :content_type do
|
191
|
+
"application/ld+json"
|
153
192
|
end
|
154
193
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
194
|
+
include_examples "client-server interaction"
|
195
|
+
end
|
196
|
+
|
197
|
+
describe "using RDFa" do
|
198
|
+
let :server do
|
199
|
+
base_server.tap do |server|
|
200
|
+
server.graph_transfer.type_handling = RoadForest::ContentHandling::Engine.new.tap do |engine|
|
201
|
+
engine.add RoadForest::MediaType::Handlers::RDFa.new, "text/html;q=1;rdfa=1"
|
202
|
+
end
|
159
203
|
end
|
160
204
|
end
|
161
205
|
|
162
|
-
|
163
|
-
|
164
|
-
server.http_exchanges.should_not be_empty
|
165
|
-
server.http_exchanges.each do |exchange|
|
166
|
-
exchange.response.headers["Content-Type"].should == "application/ld+json"
|
167
|
-
end
|
206
|
+
let :content_type do
|
207
|
+
"text/html;rdfa=1"
|
168
208
|
end
|
209
|
+
|
210
|
+
include_examples "client-server interaction"
|
169
211
|
end
|
170
212
|
end
|
data/spec/full-integration.rb
CHANGED
@@ -41,6 +41,7 @@ describe "RoadForest integration", :integration => true do
|
|
41
41
|
host.destination_dir = @destination_dir
|
42
42
|
host.logger = Logger.new("integration-test.log")
|
43
43
|
host.logger.level = Logger::DEBUG
|
44
|
+
host.authz.authenticator.add_account("admin", "passwerd", "toktok")
|
44
45
|
end
|
45
46
|
) do |config|
|
46
47
|
config.port = @server_port
|
@@ -55,6 +56,8 @@ describe "RoadForest integration", :integration => true do
|
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
59
|
+
Excon.defaults[:mock] = false
|
60
|
+
|
58
61
|
begin_time = Time.now
|
59
62
|
begin
|
60
63
|
test_conn = TCPSocket.new 'localhost', @server_port
|
@@ -84,7 +87,8 @@ describe "RoadForest integration", :integration => true do
|
|
84
87
|
|
85
88
|
let :server do
|
86
89
|
server = RoadForest::RemoteHost.new(server_url)
|
87
|
-
|
90
|
+
server.add_credentials("admin","passwerd")
|
91
|
+
#server.trace = true
|
88
92
|
server
|
89
93
|
end
|
90
94
|
|
@@ -98,7 +102,7 @@ describe "RoadForest integration", :integration => true do
|
|
98
102
|
items = graph.all(:skos, "hasTopConcept")
|
99
103
|
|
100
104
|
unresolved = items.find do |nav_item|
|
101
|
-
nav_item[:skos, "
|
105
|
+
nav_item[:skos, "prefLabel"] == "Unresolved"
|
102
106
|
end
|
103
107
|
|
104
108
|
return unresolved.first(:foaf, "page")
|
data/spec/graph-store.rb
CHANGED
@@ -29,7 +29,7 @@ describe RoadForest::RDF do
|
|
29
29
|
|
30
30
|
step[[:foaf, :givenname]] = "Lester"
|
31
31
|
step[[:dc, :date]] = Time.now
|
32
|
-
step = step.node_at([:dc, :
|
32
|
+
step = step.node_at([:dc, :relation], "http://lrdesign.com/test-rdf/sub")
|
33
33
|
step[[:dc, :date]] = Time.now
|
34
34
|
|
35
35
|
store.graph_dump(:rdfa)
|
data/spec/media-types.rb
CHANGED
@@ -1,11 +1,38 @@
|
|
1
1
|
require 'roadforest/content-handling/media-type'
|
2
|
+
|
2
3
|
describe RoadForest::ContentHandling::MediaType do
|
4
|
+
let :type_string do
|
5
|
+
"text/html;q=0.42;rdfa;sublevel=3"
|
6
|
+
end
|
7
|
+
|
8
|
+
let :type do
|
9
|
+
RoadForest::ContentHandling::MediaType.parse(type_string)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should parse accept_params" do
|
13
|
+
type.params.should_not have_key(:q)
|
14
|
+
type.quality.should == 0.42
|
15
|
+
type.params.should have_key("rdfa")
|
16
|
+
type.params.should have_key("sublevel")
|
17
|
+
type.params["sublevel"].should == "3"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should produce a matching accept header" do
|
21
|
+
type.accept_header.should == type_string
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should produce a correct content-type header" do
|
25
|
+
type.content_type_header.should == "text/html;rdfa;sublevel=3"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe RoadForest::ContentHandling::MediaTypeList do
|
3
30
|
let :accepted_list do
|
4
|
-
RoadForest::ContentHandling::MediaTypeList.build("text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;
|
31
|
+
RoadForest::ContentHandling::MediaTypeList.build("text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;q=0.4;level=2, */*;q=0.5")
|
5
32
|
end
|
6
33
|
|
7
34
|
let :provided_list do
|
8
|
-
RoadForest::ContentHandling::MediaTypeList.build("text/html;q=0.9;rdfa
|
35
|
+
RoadForest::ContentHandling::MediaTypeList.build("text/html;q=0.9;rdfa, application/json+ld;q=0.4")
|
9
36
|
end
|
10
37
|
|
11
38
|
it "should find best match" do
|