client_parser_json.rb 894 B

1234567891011121314151617181920212223242526272829303132333435
  1. require_relative '../phalapi_client'
  2. require 'test/unit'
  3. class ClientParserJsonTest < Test::Unit::TestCase
  4. def setup
  5. @parser = PhalApi::ClientParserJson.new
  6. end
  7. def test_nil
  8. rs = nil
  9. a_response = @parser.parse(rs)
  10. assert_equal 408, a_response.ret
  11. end
  12. def test_illegal_json
  13. rs = 'i am not a json, as you can see'
  14. a_response = @parser.parse(rs)
  15. assert_equal 500, a_response.ret
  16. end
  17. def test_normal_json
  18. rs = '{"ret":200,"data":{"title":"Hello World","content":"Welcome to use Web Tools!","version":"1.0.0","time":1415982826},"msg":""}'
  19. a_response = @parser.parse(rs)
  20. assert_equal 200, a_response.ret
  21. data = a_response.data
  22. assert_equal 'Hello World', data['title']
  23. assert_equal '1.0.0', data['version']
  24. assert_equal '', a_response.msg
  25. end
  26. end