testbrookhttpclient.pas 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. unit testbrookhttpclient;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. BrookHTTPClient, BrookFCLHTTPClientBroker, fpcunit, testregistry;
  6. const
  7. URL = 'http://silvioprog.github.io/brookframework/';
  8. LIB = 'fclweb';
  9. OK = 200;
  10. SOK = 'OK';
  11. GET = 'GET';
  12. type
  13. { TTestBrookHTTPClient }
  14. TTestBrookHTTPClient = class(TTestCase)
  15. published
  16. procedure TestClient;
  17. procedure TestHttpDef;
  18. end;
  19. implementation
  20. { TTestBrookHTTPClient }
  21. procedure TTestBrookHTTPClient.TestClient;
  22. var
  23. cl: TBrookHTTPClient;
  24. r: TBrookHTTPResult;
  25. begin
  26. cl := TBrookHTTPClient.Create(LIB);
  27. try
  28. r := cl.Request(URL);
  29. AssertEquals(SOK, r.ReasonPhrase);
  30. AssertEquals(OK, r.StatusCode);
  31. AssertTrue(Length(r.Content) > 0);
  32. finally
  33. cl.Free
  34. end;
  35. end;
  36. { TTestBrookHTTPClient }
  37. procedure TTestBrookHTTPClient.TestHttpDef;
  38. var
  39. cl: TBrookHTTPClient;
  40. ht: TBrookHTTPDef = nil;
  41. r: TBrookHTTPResult;
  42. begin
  43. cl := TBrookHTTPClient.Create(LIB);
  44. try
  45. cl.Prepare(ht);
  46. ht.Method := GET;
  47. ht.Url := URL;
  48. r := cl.Request(ht);
  49. AssertEquals(SOK, r.ReasonPhrase);
  50. AssertEquals(OK, r.StatusCode);
  51. AssertTrue(Length(r.Content) > 0);
  52. AssertTrue(ht.Contents.Count > 0);
  53. AssertTrue(ht.Document.Size > 0);
  54. AssertTrue(ht.Cookies.Count = 0);
  55. finally
  56. ht.Free;
  57. cl.Free
  58. end;
  59. end;
  60. initialization
  61. RegisterTest(TTestBrookHTTPClient);
  62. end.