roadforest 0.0.3 → 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/examples/file-management.rb +7 -9
  3. data/lib/roadforest/application/dispatcher.rb +44 -31
  4. data/lib/roadforest/application/parameters.rb +5 -4
  5. data/lib/roadforest/application/path-provider.rb +14 -1
  6. data/lib/roadforest/application/route-adapter.rb +15 -4
  7. data/lib/roadforest/application/services-host.rb +41 -7
  8. data/lib/roadforest/application.rb +4 -8
  9. data/lib/roadforest/authorization.rb +231 -0
  10. data/lib/roadforest/blob-model.rb +2 -11
  11. data/lib/roadforest/content-handling/engine.rb +12 -6
  12. data/lib/roadforest/content-handling/handler-wrap.rb +45 -0
  13. data/lib/roadforest/content-handling/media-type.rb +20 -12
  14. data/lib/roadforest/content-handling/type-handler.rb +76 -0
  15. data/lib/roadforest/content-handling/type-handlers/jsonld.rb +2 -146
  16. data/lib/roadforest/content-handling/type-handlers/rdf-handler.rb +38 -0
  17. data/lib/roadforest/content-handling/type-handlers/rdfa-writer/document-environment.rb +34 -0
  18. data/lib/roadforest/content-handling/type-handlers/rdfa-writer/object-environment.rb +62 -0
  19. data/lib/roadforest/content-handling/type-handlers/rdfa-writer/property-environment.rb +46 -0
  20. data/lib/roadforest/content-handling/type-handlers/rdfa-writer/render-engine.rb +574 -0
  21. data/lib/roadforest/content-handling/type-handlers/rdfa-writer/render-environment.rb +144 -0
  22. data/lib/roadforest/content-handling/type-handlers/rdfa-writer/subject-environment.rb +80 -0
  23. data/lib/roadforest/content-handling/type-handlers/rdfa-writer.rb +163 -0
  24. data/lib/roadforest/content-handling/type-handlers/rdfa.rb +175 -0
  25. data/lib/roadforest/content-handling/type-handlers/rdfpost.rb +297 -0
  26. data/lib/roadforest/debug.rb +10 -0
  27. data/lib/roadforest/http/graph-response.rb +3 -7
  28. data/lib/roadforest/http/graph-transfer.rb +28 -106
  29. data/lib/roadforest/http/keychain.rb +79 -0
  30. data/lib/roadforest/http/message.rb +9 -1
  31. data/lib/roadforest/http/user-agent.rb +115 -0
  32. data/lib/roadforest/http.rb +8 -0
  33. data/lib/roadforest/model.rb +48 -3
  34. data/lib/roadforest/rdf/graph-focus.rb +5 -3
  35. data/lib/roadforest/rdf/graph-store.rb +4 -2
  36. data/lib/roadforest/rdf/normalization.rb +6 -1
  37. data/lib/roadforest/remote-host.rb +22 -7
  38. data/lib/roadforest/resource/rdf/read-only.rb +15 -1
  39. data/lib/roadforest/templates/base/doc.haml +13 -0
  40. data/lib/roadforest/templates/base/property_value.haml +12 -0
  41. data/lib/roadforest/templates/base/property_values.haml +6 -0
  42. data/lib/roadforest/templates/base/subject.haml +4 -0
  43. data/lib/roadforest/templates/distiller/doc.haml +20 -0
  44. data/lib/roadforest/templates/distiller/nil-object.haml +1 -0
  45. data/lib/roadforest/templates/distiller/property_value.haml +7 -0
  46. data/lib/roadforest/templates/distiller/property_values.haml +7 -0
  47. data/lib/roadforest/templates/distiller/subject.haml +5 -0
  48. data/lib/roadforest/templates/min/doc.haml +10 -0
  49. data/lib/roadforest/templates/min/property_values.haml +7 -0
  50. data/lib/roadforest/templates/min/subject.haml +2 -0
  51. data/lib/roadforest/templates/nil-object.haml +0 -0
  52. data/lib/roadforest/templates/node-object.haml +1 -0
  53. data/lib/roadforest/templates/object.haml +1 -0
  54. data/lib/roadforest/templates/uri-object.haml +1 -0
  55. data/lib/roadforest/templates/xml-literal-object.haml +1 -0
  56. data/lib/roadforest/utility/class-registry.rb +4 -0
  57. data/spec/client.rb +119 -77
  58. data/spec/{excon-adapater.rb → excon-adapter.rb} +4 -0
  59. data/spec/full-integration.rb +6 -2
  60. data/spec/graph-store.rb +1 -1
  61. data/spec/media-types.rb +29 -2
  62. 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 :server do
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
- describe "raw put of file data" do
50
- before :each do
51
- @destination = nil
52
- server.getting do |graph|
53
- items = graph.all(:skos, "hasTopConcept")
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
- unresolved = items.find do |nav_item|
56
- nav_item[:skos, "label"] == "Unresolved"
66
+ @destination = target.first(:lc, "needs").as_list.first[:lc, "contents"]
57
67
  end
58
68
 
59
- target = unresolved.first(:foaf, "page")
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
- @destination = target.first(:lc, "needs").as_list.first[:lc, "contents"]
76
+ it "should be able to format traces correctly" do
77
+ RoadForest::TestSupport::FSM.trace_dump.should =~ /Decision/
62
78
  end
63
79
 
64
- unless @destination.nil?
65
- File::open(source_path) do |file|
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
- it "should be able to format traces correctly" do
72
- RoadForest::TestSupport::FSM.trace_dump.should =~ /Decision/
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
- it "should set destination" do
76
- @destination.to_context.to_s.should == "http://localhost:8778/files/one"
77
- end
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
- it "should deliver file to destination path" do
80
- File::read(File::join(destination_dir, "one")).should ==
81
- File::read(source_path)
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
- describe "posting data to server" do
86
- before :each do
87
- begin
88
- server.posting do |graph|
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, "label"] == "Unresolved"
125
+ nav_item[:skos, "prefLabel"] == "Unresolved"
93
126
  end
94
127
 
95
128
  target = unresolved.first(:foaf, "page")
96
129
 
97
- target.post_to do |new_need|
98
- new_need[[:lc, "name"]] = "lawyers/guns/money"
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
- it "should change the server state" do
107
- services.file_records.find do |record|
108
- record.name == "lawyers/guns/money"
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
- target = unresolved.first(:foaf, "page")
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
- needs = target.first(:lc, "needs").as_list
150
+ unresolved = items.find do |nav_item|
151
+ nav_item[:skos, "prefLabel"] == "Unresolved"
152
+ end
125
153
 
126
- needs.each do |need|
127
- need[[:lc, "resolved"]] = true
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
- it "should change the server state" do
133
- services.file_records.each do |record|
134
- record.resolved.should == true
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
- it "should change the server's responses" do
139
- server.getting do |graph|
140
- @correct = 0
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
- unresolved = items.find do |nav_item|
144
- nav_item[:skos, "label"] == "Unresolved"
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
- unresolved.first(:foaf, "page").first(:lc, "needs").as_list.each do |need|
148
- @correct += 1
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
- @correct.should == 0
190
+ let :content_type do
191
+ "application/ld+json"
153
192
  end
154
193
 
155
- it "should extract data from server responses" do
156
- server.should match_query do
157
- pattern(:subject, [:lc, "path"], nil)
158
- pattern(:subject, [:lc, "file"], nil)
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
- it "should return correct content-type" do
163
- #test_server.http_exchanges.each{|ex| puts ex.response.body}
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
@@ -15,6 +15,10 @@ describe RoadForest::HTTP::ExconAdapter do
15
15
  end
16
16
  end
17
17
 
18
+ after :each do
19
+ Excon.stubs.clear
20
+ end
21
+
18
22
  describe "responses to GET requests" do
19
23
  let :request do
20
24
  RoadForest::HTTP::Request.new("GET", "http://test-site.com/test")
@@ -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
- #server.graph_transfer.trace = true
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, "label"] == "Unresolved"
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, :related], "http://lrdesign.com/test-rdf/sub")
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;level=2;q=0.4, */*;q=0.5")
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=true, application/json+ld;q=0.4")
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