forked from austvik/wadlgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it possible to parse a WADL file
- Loading branch information
Showing
6 changed files
with
192 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ Echoe.new('wadlgen', '0.1.0') do |p| | |
p.author = 'Jorgen Austvik' | ||
p.email = '[email protected]' | ||
p.ignore_pattern = ['tmp/*', 'nbproject/**/*'] | ||
p.runtime_dependencies = ['builder'] | ||
p.runtime_dependencies = ['builder', 'nokogiri'] | ||
p.development_dependencies = ['test-unit'] | ||
p.require_paths = ['lib'] | ||
p.retain_gemspec = true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
require 'test/unit' | ||
require 'wadlgen' | ||
|
||
class Testparser < Test::Unit::TestCase | ||
|
||
def test_parse_simple_wadl | ||
document = <<HERE | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://wadl.dev.java.net/2009/02 wadl.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://wadl.dev.java.net/2009/02"> | ||
<resources base="http://example.com/application/"> | ||
<resource path="accounts"> | ||
<method name="GET" id="GET_accounts"> | ||
<request> | ||
<param name="format" style="query"> | ||
<option value="html" mediaType="application/html"/> | ||
<option value="xml" mediaType="application/xml"/> | ||
<option value="json" mediaType="application/json"/> | ||
</param> | ||
</request> | ||
<response status="200"> | ||
<representation mediaType="application/html" element="html"/> | ||
<representation mediaType="application/xml" element="accounts"/> | ||
<representation mediaType="application/json"/> | ||
</response> | ||
<response status="400"> | ||
<representation mediaType="application/xml" element="Error"/> | ||
</response> | ||
</method> | ||
</resource> | ||
</resources> | ||
</application> | ||
HERE | ||
|
||
wadl = Wadlgen::Wadl.parse(document) | ||
assert_equal "http://example.com/application/", wadl.base | ||
assert_equal 1, wadl.resources.length | ||
resource = wadl.resources.first | ||
assert_equal 'accounts', resource.path | ||
assert_equal 1, resource.methods.length | ||
method = resource.methods.first | ||
assert_equal 'GET', method.verb | ||
assert_equal 1, method.requests.length | ||
request = method.requests.first | ||
assert_equal 1, request.parameters.length | ||
param = request.parameters.first | ||
assert_equal 'format', param.name | ||
assert_equal 'query', param.style | ||
assert_equal 3, param.options.length | ||
assert_equal 'html', param.options[0].value | ||
assert_equal 'application/html', param.options[0].media_type | ||
assert_equal 'xml', param.options[1].value | ||
assert_equal 'application/xml', param.options[1].media_type | ||
assert_equal 'json', param.options[2].value | ||
assert_equal 'application/json', param.options[2].media_type | ||
assert_equal 2, method.responses.length | ||
|
||
response = method.responses.first | ||
assert_equal 200, response.status | ||
assert_equal 3, response.representations.length | ||
assert_equal 'html', response.representations[0].element | ||
assert_equal 'application/html', response.representations[0].media_type | ||
assert_equal 'accounts', response.representations[1].element | ||
assert_equal 'application/xml', response.representations[1].media_type | ||
assert_nil response.representations[2].element | ||
assert_equal 'application/json', response.representations[2].media_type | ||
|
||
response = method.responses.last | ||
assert_equal 400, response.status | ||
assert_equal 1, response.representations.length | ||
assert_equal 'Error', response.representations[0].element | ||
assert_equal 'application/xml', response.representations[0].media_type | ||
end | ||
|
||
def test_roundtrip | ||
document = <<HERE | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://wadl.dev.java.net/2009/02 wadl.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://wadl.dev.java.net/2009/02"> | ||
<resources base="http://example.com/application/"> | ||
<resource path="accounts"> | ||
<method name="GET" id="GET_accounts"> | ||
<request> | ||
<param name="format" style="query"> | ||
<option value="html" mediaType="application/html"/> | ||
<option value="xml" mediaType="application/xml"/> | ||
<option value="json" mediaType="application/json"/> | ||
</param> | ||
</request> | ||
<response status="200"> | ||
<representation mediaType="application/html" element="html"/> | ||
<representation mediaType="application/xml" element="accounts"/> | ||
<representation mediaType="application/json"/> | ||
</response> | ||
<response status="400"> | ||
<representation mediaType="application/xml" element="Error"/> | ||
</response> | ||
</method> | ||
</resource> | ||
</resources> | ||
</application> | ||
HERE | ||
|
||
wadl = Wadlgen::Wadl.parse document | ||
document2 = Wadlgen::Wadl.generate_wadl(wadl) | ||
assert_equal document, document2 | ||
wadl2 = Wadlgen::Wadl.parse document2 | ||
document3 = Wadlgen::Wadl.generate_wadl(wadl2) | ||
assert_equal document, document3 | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,27 +10,30 @@ Gem::Specification.new do |s| | |
s.description = %q{Generate WADL from rails routes} | ||
s.email = %q{[email protected]} | ||
s.extra_rdoc_files = ["README", "lib/rake/wadlgen.rb", "lib/wadlgen.rb", "lib/wadlgen/classes.rb", "lib/wadlgen/railtie.rb"] | ||
s.files = ["MIT-LICENSE", "README", "Rakefile", "lib/rake/wadlgen.rb", "lib/wadlgen.rb", "lib/wadlgen/classes.rb", "lib/wadlgen/railtie.rb", "test/test_classes.rb", "test/test_generate.rb", "wadlgen.gemspec", "Manifest"] | ||
s.files = ["MIT-LICENSE", "README", "Rakefile", "lib/rake/wadlgen.rb", "lib/wadlgen.rb", "lib/wadlgen/classes.rb", "lib/wadlgen/railtie.rb", "test/test_classes.rb", "test/test_generate.rb", "test/test_parser.rb", "wadlgen.gemspec", "Manifest"] | ||
s.homepage = %q{https://github.com/austvik/wadlgen} | ||
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Wadlgen", "--main", "README"] | ||
s.require_paths = ["lib"] | ||
s.rubyforge_project = %q{wadlgen} | ||
s.rubygems_version = %q{1.5.0} | ||
s.summary = %q{Generate WADL from rails routes} | ||
s.test_files = ["test/test_classes.rb", "test/test_generate.rb"] | ||
s.test_files = ["test/test_classes.rb", "test/test_parser.rb", "test/test_generate.rb"] | ||
|
||
if s.respond_to? :specification_version then | ||
s.specification_version = 3 | ||
|
||
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then | ||
s.add_runtime_dependency(%q<builder>, [">= 0"]) | ||
s.add_runtime_dependency(%q<nokogiri>, [">= 0"]) | ||
s.add_development_dependency(%q<test-unit>, [">= 0"]) | ||
else | ||
s.add_dependency(%q<builder>, [">= 0"]) | ||
s.add_dependency(%q<nokogiri>, [">= 0"]) | ||
s.add_dependency(%q<test-unit>, [">= 0"]) | ||
end | ||
else | ||
s.add_dependency(%q<builder>, [">= 0"]) | ||
s.add_dependency(%q<nokogiri>, [">= 0"]) | ||
s.add_dependency(%q<test-unit>, [">= 0"]) | ||
end | ||
end |