ape 1.0.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/LICENSE +1 -1
  2. data/README +22 -8
  3. data/Rakefile +66 -0
  4. data/bin/ape_server +3 -3
  5. data/lib/ape.rb +131 -937
  6. data/lib/ape/atomURI.rb +1 -1
  7. data/lib/ape/authent.rb +11 -17
  8. data/lib/ape/categories.rb +8 -7
  9. data/lib/ape/collection.rb +3 -7
  10. data/lib/ape/crumbs.rb +1 -1
  11. data/lib/ape/entry.rb +1 -1
  12. data/lib/ape/escaper.rb +1 -1
  13. data/lib/ape/feed.rb +26 -14
  14. data/lib/ape/handler.rb +8 -3
  15. data/lib/ape/html.rb +1 -1
  16. data/lib/ape/invoker.rb +1 -1
  17. data/lib/ape/invokers/deleter.rb +1 -1
  18. data/lib/ape/invokers/getter.rb +1 -1
  19. data/lib/ape/invokers/poster.rb +1 -1
  20. data/lib/ape/invokers/putter.rb +1 -1
  21. data/lib/ape/names.rb +1 -1
  22. data/lib/ape/print_writer.rb +4 -6
  23. data/lib/ape/reporter.rb +156 -0
  24. data/lib/ape/reporters/atom_reporter.rb +51 -0
  25. data/lib/ape/reporters/atom_template.eruby +38 -0
  26. data/lib/ape/reporters/html_reporter.rb +53 -0
  27. data/lib/ape/reporters/html_template.eruby +62 -0
  28. data/lib/ape/reporters/text_reporter.rb +37 -0
  29. data/lib/ape/samples.rb +30 -51
  30. data/lib/ape/server.rb +16 -4
  31. data/lib/ape/service.rb +1 -1
  32. data/lib/ape/util.rb +67 -0
  33. data/lib/ape/validator.rb +85 -57
  34. data/lib/ape/validator_dsl.rb +40 -0
  35. data/lib/ape/validators/entry_posts_validator.rb +226 -0
  36. data/lib/ape/validators/media_linkage_validator.rb +78 -0
  37. data/lib/ape/validators/media_posts_validator.rb +104 -0
  38. data/lib/ape/validators/sanitization_validator.rb +57 -0
  39. data/lib/ape/validators/schema_validator.rb +57 -0
  40. data/lib/ape/validators/service_document_validator.rb +64 -0
  41. data/lib/ape/validators/sorting_validator.rb +87 -0
  42. data/lib/ape/version.rb +1 -1
  43. data/{lib/ape/samples → samples}/atom_schema.txt +0 -0
  44. data/{lib/ape/samples → samples}/basic_entry.eruby +4 -4
  45. data/{lib/ape/samples → samples}/categories_schema.txt +0 -0
  46. data/{lib/ape/samples → samples}/mini_entry.eruby +0 -0
  47. data/{lib/ape/samples → samples}/service_schema.txt +0 -0
  48. data/{lib/ape/samples → samples}/unclean_xhtml_entry.eruby +0 -0
  49. data/test/test_helper.rb +33 -1
  50. data/test/unit/ape_test.rb +92 -0
  51. data/test/unit/authent_test.rb +2 -2
  52. data/test/unit/reporter_test.rb +102 -0
  53. data/test/unit/samples_test.rb +2 -2
  54. data/test/unit/validators_test.rb +50 -0
  55. data/{lib/ape/layout → web}/ape.css +5 -1
  56. data/{lib/ape/layout → web}/ape_logo.png +0 -0
  57. data/{lib/ape/layout → web}/index.html +2 -5
  58. data/{lib/ape/layout → web}/info.png +0 -0
  59. metadata +108 -56
  60. data/CHANGELOG +0 -1
  61. data/Manifest +0 -45
  62. data/ape.gemspec +0 -57
  63. data/scripts/go.rb +0 -29
@@ -0,0 +1,92 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+
4
+ class ApeTest < Test::Unit::TestCase
5
+ require 'rexml/document'
6
+ def setup
7
+ @ape = Ape::Ape.new
8
+ @ape.media_collections = []
9
+ @ape.entry_collections = []
10
+ end
11
+
12
+ def test_check_manifest_raises_validation_error
13
+ @ape.entry_collections = service { collection('Attachments', ['image/jpg']) }
14
+ assert_raise(Ape::ValidationError) {
15
+ variables = @ape.check_manifest(ValidatorMock.new)
16
+ }
17
+ end
18
+
19
+ def test_check_manifest_assert_first_entry_collection
20
+ @ape.entry_collections = service { collection('Posts') }
21
+ variables = @ape.check_manifest(ValidatorMock.new)
22
+ assert_equal('Posts', variables[:entry_collection].title)
23
+ end
24
+
25
+ def test_check_manifest_assert_first_media_collection
26
+ @ape.media_collections = service { collection('Attachments', ['image/jpg']) }
27
+ variables = stub_manifest([:media_collection])
28
+ assert_equal('Attachments', variables[:media_collection].title)
29
+ end
30
+
31
+ def test_check_manifest_assert_select_last_collection
32
+ @ape.entry_collections = service {
33
+ collection('Posts') +
34
+ collection('Comments')
35
+ }
36
+
37
+ variables = stub_manifest([:entry_collection => :last])
38
+ assert_equal('Comments', variables[:entry_collection].title)
39
+ end
40
+
41
+ def test_select_first_collection_by_type
42
+ @ape.entry_collections = service {
43
+ collection('Posts') +
44
+ collection('Attachments', ['image/jpg']) +
45
+ collection('Attachments2', ['image/png'])
46
+ }
47
+ variables = stub_manifest([:media_collection => {:accept => 'image/png'}])
48
+ assert_equal('Attachments2', variables[:media_collection].title)
49
+ end
50
+
51
+ def test_select_first_collection_by_title
52
+ @ape.entry_collections = service {
53
+ collection('Posts') +
54
+ collection('Attachments', ['image/jpg'])
55
+ }
56
+ variables = stub_manifest([:media_collection => {:title => 'Attachments'}])
57
+ assert_equal('Attachments', variables[:media_collection].title)
58
+ end
59
+
60
+ def test_select_by_name_raises_validation_error
61
+ @ape.entry_collections = service {
62
+ collection('Posts') +
63
+ collection('Attachments', ['image/jpg'])
64
+ }
65
+ assert_raise(Ape::ValidationError) {
66
+ variables = stub_manifest([:media_collection => {:name => 'Attachments'}])
67
+ }
68
+ end
69
+
70
+ def stub_manifest(return_value)
71
+ validator = ValidatorMock.new
72
+ validator.stubs(:manifest).returns(return_value)
73
+ @ape.check_manifest(validator)
74
+ end
75
+
76
+ def collection(title, accept = ['application/atom+xml;type=entry'])
77
+ collection = "<collection href=\"http://localhost\">" +
78
+ "<atom:title>#{title}</atom:title>"
79
+ accept.each do |a|
80
+ collection += "<accept>#{a}</accept>"
81
+ end
82
+ collection += "</collection>"
83
+ end
84
+
85
+ def service(&block)
86
+ service = "<service xmlns=\"http://www.w3.org/2007/app\"" +
87
+ " xmlns:atom=\"http://www.w3.org/2005/Atom\"><workspace>"
88
+ service += yield
89
+ service += "</workspace></service>"
90
+ Ape::Service.collections(REXML::Document.new(service), nil)
91
+ end
92
+ end
@@ -6,7 +6,7 @@ class AuthentTest < Test::Unit::TestCase
6
6
  end
7
7
 
8
8
  def test_assert_raise_auth_error
9
- assert_raise(Ape::AuthenticationError) { load_plugin("Oauth") }
9
+ assert_raise(Ape::AuthenticationError) { load_plugin("OAuth") }
10
10
  end
11
11
 
12
12
  def test_assert_load_wsse_plugin
@@ -28,7 +28,7 @@ class AuthentTest < Test::Unit::TestCase
28
28
  end
29
29
 
30
30
  def load_plugin(plugin_name)
31
- @authent.resolve_plugin(plugin_name)
31
+ @authent.load_plugin(plugin_name)
32
32
  end
33
33
 
34
34
 
@@ -0,0 +1,102 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class OutputMock < String
4
+ def puts(str)
5
+ self << str
6
+ end
7
+ end
8
+
9
+ class ReporterTest < Test::Unit::TestCase
10
+ def test_instance_text_reporter_nothing_raised
11
+ assert_nothing_raised(Exception) { Ape::Reporter.instance('text') }
12
+ end
13
+
14
+ def test_instance_html_reporter_nothing_raised
15
+ assert_nothing_raised(Exception) { Ape::Reporter.instance('html') }
16
+ end
17
+
18
+ def test_instance_html_reporter_nothing_raised
19
+ assert_nothing_raised(Exception) { Ape::Reporter.instance('atom') }
20
+ end
21
+
22
+ def test_instance_unknown_reporter_raises_standard_error
23
+ assert_raise(StandardError) { Ape::Reporter.instance('rss') }
24
+ end
25
+
26
+ def test_supported_outputs
27
+ assert_equal("atom, html, text", Ape::Reporter.supported_outputs)
28
+ end
29
+
30
+ def test_errors_nothing_raised
31
+ assert_nothing_raised(Exception) { Ape::Reporter.new.errors }
32
+ end
33
+
34
+ def test_contains_an_error
35
+ reporter = Ape::Reporter.new
36
+ reporter.add(self, :error, 'ape error 1')
37
+ assert_equal(1, reporter.errors.length)
38
+ end
39
+
40
+ def test_contains_two_errors
41
+ reporter = Ape::Reporter.new
42
+ reporter.add(self, :error, 'ape error 2')
43
+ reporter.add(self, :error, 'ape error 3')
44
+ reporter.add(self, :info, 'ape info')
45
+ assert_equal(2, reporter.errors.length)
46
+ end
47
+
48
+ def test_warnings_nothing_raised
49
+ reporter = Ape::Reporter.new
50
+ assert_nothing_raised(Exception) { reporter.warnings }
51
+ end
52
+
53
+ def test_contains_warnings
54
+ reporter = Ape::Reporter.new
55
+ reporter.add(self, :warning, 'ape warning')
56
+ assert_equal(1, reporter.warnings.length)
57
+ end
58
+
59
+ def test_html_stylesheet_exists
60
+ reporter = Ape::Reporter.instance('html')
61
+ assert_equal(true, File.exists?(reporter.stylesheet))
62
+ end
63
+
64
+ def test_mark_error
65
+ reporter = Ape::Reporter.instance('html')
66
+ assert_equal('<span class="error">!</span>', reporter.mark(:error))
67
+ end
68
+
69
+ def test_mark_info
70
+ assert_match(/<img class="info" src="(.+)"\/>/, info)
71
+ end
72
+
73
+ def test_info_image_exists
74
+ assert_equal(true, File.exists?(
75
+ /<img class="info" src="(.+)"\/>/.match(info)[1]))
76
+ end
77
+
78
+ def info
79
+ Ape::Reporter.instance('html').mark(:info)
80
+ end
81
+
82
+ def test_html_report_not_nil
83
+ assert_not_nil(Ape::Reporter.instance('html').report(OutputMock.new("")))
84
+ end
85
+
86
+ def test_hmtl_report_contains_steps
87
+ reporter = Ape::Reporter.instance(:html)
88
+ reporter.add(self, :warning, 'Ape warning')
89
+ assert_nothing_raised(Exception) { reporter.report(OutputMock.new("")) }
90
+ end
91
+
92
+ def test_static_dir_server
93
+ reporter = Ape::Reporter.instance(:html, {:server => true})
94
+ assert_equal("/web", reporter.static_dir)
95
+ end
96
+
97
+ def test_static_dir_script
98
+ reporter = Ape::Reporter.instance(:html)
99
+ assert_match(/.+\/web$/, reporter.static_dir)
100
+ end
101
+
102
+ end
@@ -4,11 +4,11 @@ require 'rexml/document'
4
4
  class SamplesTest < Test::Unit::TestCase
5
5
 
6
6
  def test_ape_home
7
- assert_equal('/Users/david/.ape', Ape::Samples.home)
7
+ assert_match(/[.]ape$/, Ape::Ape.home)
8
8
  end
9
9
 
10
10
  def test_load_service_schema
11
- assert_not_nil(Ape::Samples.service_RNC)
11
+ assert_not_nil(Ape::Samples.service_RNC)
12
12
  end
13
13
 
14
14
  def test_load_categories_schema
@@ -0,0 +1,50 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class ValidatorsTest < Test::Unit::TestCase
4
+ def setup
5
+ @reporter = Ape::Reporter.instance('text')
6
+ end
7
+ def test_schema_validate
8
+ assert_equal(true, validate_schema)
9
+ end
10
+
11
+ def test_chema_validate_with_ruby_shows_an_info
12
+ if RUBY_PLATFORM !=~ /java/
13
+ validate_schema
14
+ assert_equal(1, @reporter.infos.size)
15
+ end
16
+ end
17
+
18
+ def validate_schema
19
+ schema = Ape::Validator.instance(:schema, @reporter)
20
+ schema.validate(:schema => Ape::Samples.service_RNC, :title => 'Service doc', :doc => service)
21
+ end
22
+
23
+ def test_validator_is_deterministic
24
+ assert(ValidatorMock.new.deterministic? == true, "Validator mock is nondeterministic")
25
+ end
26
+
27
+ def test_validator_is_enabled
28
+ assert(ValidatorMock.new.enabled? == true, "Validator mock is disabled")
29
+ end
30
+
31
+ def service
32
+ <<END_SERVICE
33
+ <?xml version="1.0" encoding="utf-8"?>
34
+ <service xmlns="http://www.w3.org/2007/app" xmlns:atom="http://www.w3.org/2005/Atom">
35
+ <workspace>
36
+ <atom:title>Verbosemode in wordpress Workspace</atom:title>
37
+ <collection href="http://verbosemode.wordpress.com/wp-app.php/posts">
38
+ <atom:title>Verbosemode in wordpress Posts</atom:title>
39
+ <accept>application/atom+xml;type=entry</accept>
40
+ <categories href="http://verbosemode.wordpress.com/wp-app.php/categories" />
41
+ </collection>
42
+ <collection href="http://verbosemode.wordpress.com/wp-app.php/attachments">
43
+ <atom:title>Verbosemode in wordpress Media</atom:title>
44
+ <accept>image/*</accept><accept>audio/*</accept><accept>video/*</accept>
45
+ </collection>
46
+ </workspace>
47
+ </service>
48
+ END_SERVICE
49
+ end
50
+ end
@@ -30,7 +30,7 @@ a.diaref {
30
30
  color: #086;
31
31
  }
32
32
 
33
- span.good {
33
+ span.success {
34
34
  font-size: 125%;
35
35
  color: green;
36
36
  }
@@ -54,3 +54,7 @@ span.error {
54
54
  border: 1px solid #086;
55
55
  }
56
56
 
57
+ #steps li {
58
+ margin-bottom: 10px;
59
+ }
60
+
File without changes
@@ -5,7 +5,7 @@
5
5
  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>
6
6
  </head>
7
7
  <body>
8
- <img align="right" src="/ape/ape_logo.png" alt="The Ape logo by Greg Borenstein" />
8
+ <img align="right" src="ape_logo.png" alt="The Ape logo by Greg Borenstein" />
9
9
  <div id="main">
10
10
  <h2>Atom Protocol Exerciser</h2>
11
11
 
@@ -40,10 +40,7 @@
40
40
  -->
41
41
  <hr/>
42
42
  <p>The Ape source code may be found at
43
- <a href="http://ape.dev.java.net">ape.dev.java.net</a>. It's a little
44
- tricky to get going;
45
- until I fix that, see this
46
- <a href="http://rollerweblogger.org/roller/entry/atom_protocol_exerciser_ape_setup">discussion by Dave Johnson</a>.</p>
43
+ <a href="http://rubyforge.org/projects/ape">ape.rubyforge.org</a>.
47
44
 
48
45
  <hr/>
49
46
  <p>Ape Logo by <a href="http://www.urbanhonking.com/ideasfordozens">Greg
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ape
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Bray
@@ -9,78 +9,132 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-02-22 00:00:00 +01:00
12
+ date: 2008-07-01 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: builder
16
+ name: rake
17
17
  version_requirement:
18
18
  version_requirements: !ruby/object:Gem::Requirement
19
19
  requirements:
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: "0"
23
- - - "="
22
+ version: "0.8"
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: mongrel
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
24
30
  - !ruby/object:Gem::Version
25
- version: 2.1.2
31
+ version: 1.1.3
26
32
  version:
27
- description: A tool to exercice AtomPub server.
33
+ - !ruby/object:Gem::Dependency
34
+ name: erubis
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.5.0
41
+ version:
42
+ - !ruby/object:Gem::Dependency
43
+ name: rubyforge
44
+ version_requirement:
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0.4"
50
+ version:
51
+ - !ruby/object:Gem::Dependency
52
+ name: mocha
53
+ version_requirement:
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 0.9.0
59
+ version:
60
+ description:
28
61
  email: tim.bray@sun.com
29
62
  executables:
30
63
  - ape_server
31
64
  extensions: []
32
65
 
33
- extra_rdoc_files: []
34
-
66
+ extra_rdoc_files:
67
+ - README
68
+ - LICENSE
35
69
  files:
36
- - bin/ape_server
37
- - CHANGELOG
38
- - lib/ape/atomURI.rb
39
- - lib/ape/auth/google_login_credentials.rb
40
- - lib/ape/auth/wsse_credentials.rb
41
- - lib/ape/authent.rb
70
+ - lib/ape.rb
71
+ - lib/ape
72
+ - lib/ape/feed.rb
42
73
  - lib/ape/categories.rb
43
- - lib/ape/collection.rb
74
+ - lib/ape/names.rb
44
75
  - lib/ape/crumbs.rb
45
- - lib/ape/entry.rb
46
- - lib/ape/escaper.rb
47
- - lib/ape/feed.rb
48
- - lib/ape/handler.rb
49
- - lib/ape/html.rb
50
- - lib/ape/invoker.rb
51
- - lib/ape/invokers/deleter.rb
52
- - lib/ape/invokers/getter.rb
76
+ - lib/ape/server.rb
77
+ - lib/ape/service.rb
78
+ - lib/ape/collection.rb
79
+ - lib/ape/validator_dsl.rb
80
+ - lib/ape/reporter.rb
81
+ - lib/ape/util.rb
82
+ - lib/ape/invokers
53
83
  - lib/ape/invokers/poster.rb
84
+ - lib/ape/invokers/getter.rb
85
+ - lib/ape/invokers/deleter.rb
54
86
  - lib/ape/invokers/putter.rb
55
- - lib/ape/layout/ape.css
56
- - lib/ape/layout/ape_logo.png
57
- - lib/ape/layout/index.html
58
- - lib/ape/layout/info.png
59
- - lib/ape/names.rb
87
+ - lib/ape/atomURI.rb
88
+ - lib/ape/entry.rb
89
+ - lib/ape/validators
90
+ - lib/ape/validators/entry_posts_validator.rb
91
+ - lib/ape/validators/sanitization_validator.rb
92
+ - lib/ape/validators/schema_validator.rb
93
+ - lib/ape/validators/media_linkage_validator.rb
94
+ - lib/ape/validators/service_document_validator.rb
95
+ - lib/ape/validators/media_posts_validator.rb
96
+ - lib/ape/validators/sorting_validator.rb
60
97
  - lib/ape/print_writer.rb
61
- - lib/ape/samples/atom_schema.txt
62
- - lib/ape/samples/basic_entry.eruby
63
- - lib/ape/samples/categories_schema.txt
64
- - lib/ape/samples/mini_entry.eruby
65
- - lib/ape/samples/service_schema.txt
66
- - lib/ape/samples/unclean_xhtml_entry.eruby
67
- - lib/ape/samples.rb
68
- - lib/ape/server.rb
69
- - lib/ape/service.rb
70
- - lib/ape/validator.rb
98
+ - lib/ape/auth
99
+ - lib/ape/auth/wsse_credentials.rb
100
+ - lib/ape/auth/google_login_credentials.rb
101
+ - lib/ape/escaper.rb
102
+ - lib/ape/authent.rb
71
103
  - lib/ape/version.rb
72
- - lib/ape.rb
73
- - LICENSE
74
- - README
75
- - scripts/go.rb
76
- - test/test_helper.rb
77
- - test/unit/authent_test.rb
78
- - test/unit/invoker_test.rb
104
+ - lib/ape/validator.rb
105
+ - lib/ape/reporters
106
+ - lib/ape/reporters/atom_template.eruby
107
+ - lib/ape/reporters/atom_reporter.rb
108
+ - lib/ape/reporters/text_reporter.rb
109
+ - lib/ape/reporters/html_template.eruby
110
+ - lib/ape/reporters/html_reporter.rb
111
+ - lib/ape/samples.rb
112
+ - lib/ape/invoker.rb
113
+ - lib/ape/handler.rb
114
+ - lib/ape/html.rb
115
+ - samples/basic_entry.eruby
116
+ - samples/categories_schema.txt
117
+ - samples/service_schema.txt
118
+ - samples/mini_entry.eruby
119
+ - samples/atom_schema.txt
120
+ - samples/unclean_xhtml_entry.eruby
121
+ - test/unit
79
122
  - test/unit/samples_test.rb
80
- - Manifest
81
- - ape.gemspec
82
- has_rdoc: true
83
- homepage: http://www.tbray.org/ongoing/misc/Software#p-4
123
+ - test/unit/validators_test.rb
124
+ - test/unit/invoker_test.rb
125
+ - test/unit/reporter_test.rb
126
+ - test/unit/ape_test.rb
127
+ - test/unit/authent_test.rb
128
+ - test/test_helper.rb
129
+ - web/info.png
130
+ - web/ape_logo.png
131
+ - web/ape.css
132
+ - web/index.html
133
+ - README
134
+ - LICENSE
135
+ - Rakefile
136
+ has_rdoc: false
137
+ homepage: ape.rubyforge.org
84
138
  post_install_message:
85
139
  rdoc_options: []
86
140
 
@@ -101,11 +155,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
155
  requirements: []
102
156
 
103
157
  rubyforge_project: ape
104
- rubygems_version: 1.0.0
158
+ rubygems_version: 1.1.1
105
159
  signing_key:
106
160
  specification_version: 2
107
- summary: A tool to exercice AtomPub server.
108
- test_files:
109
- - test/unit/authent_test.rb
110
- - test/unit/invoker_test.rb
111
- - test/unit/samples_test.rb
161
+ summary: The Atom Protocol Exerciser
162
+ test_files: []
163
+