Testing HTTP requests
ODABA provides a little test framework for testing OHTTP requests. Tests may be prepared in a test script containing any number of tests. The test script consists of any number of test blocks, where each test block has the following structure:
- line 1: test header (fix text 'TEST:' followed by test title)
- line 2: request type (GET, PUT, PATCH, POST, DELETE)
- line 3: user name
- line 4: password (in the example, user name and password must have same length)
- line 5: URL without server:port (e.g. /Persons::Person/0/children )
- line 6 and following (until end of file or next empty line or next test header): body
Empty lines or comment lines (beginning with //) between test blocks and block lines will be ignored.
In order to run the test script, a command line server or server daemon has to be started and an OSI scrip as shown below has to be called:
- OShell.exe OShell.ini TestHTTP.osh
Since the function OHTTPExecute(testscript,server,port) for running the test script is implemented in ode.dev, the database has to be defined as RESOURCES database in the data source (here Sample).
While running the script, Test case head line, HTTP return code and result string are written to console.
// test block in Test.txt
TEST: Create instance with pid P1001
PUT
user
upwd
/Person::Persons/P1001
{ name:"Hops0", first_name: [ "Sala0", "Tralala0"], married: true, location: {zip: 1000, city: City1000, street: "Short Lane", number: 1000}, notes: "temporary notes", birth_date: "2000-10-31" }
// TestHTTP.osh (run with OShell)
cd Sample // open data source (see OShell.ini)
osi 'dictionary.loadOSILibraries' // load login function when not defined in .dev
osi begin
Option("HTTP.timeout").assign("300"); // increase timeout
OHTTPExecute("Test.txt","localhost","8888"); // run test script
end
// OShell.ini for running OShell
[SYSTEM]
DICTIONARY=ode.sys
[OShell]
DSC_Language=English
[OSI]
Library=./*.osi
[Sample]
DICTIONARY=Sample.dev
RESOURCES=ode.dev
DATABASE=Sample.dat
PLATFORM_INDEPENDENT=YES
SHARE=YES
ACCESS_MODE=Write
ONLINE_VERSION=YES