abap-odata-test
An ABAP client library for calling OData services and chaining assertions on the response, such as assert_http_200, for unit tests, ADT console runs and standalone programs; its examples show GET only.
Testing an OData service from ABAP otherwise means writing the HTTP plumbing by hand. This library wraps it behind a client, zcl_odata_test, that fetches a CSRF token, issues GET requests with URL variables substituted in from a key-value table, and chains assertions such as assert_http_200, assert_json_content_type and assert_json_path_exists onto the response. The maintainer names unit tests, ADT console runs and standalone programs as where to use it; both worked examples in the README are ADT console runs, one a single GET and one a loop over twenty business-partner keys. Every example calls the client's get method, and no assertion against a write is shown.
Facts
Where it sits
Who is behind it
In the atlas: maintains 1@bluefundamaintainerLars HvamContributes to this
In the atlas: maintains 13, contributes to 92, wrote 1@larshpPhani PuttabakulaContributes to this
In the atlas: contributes to 1@phanikumarps2 contributors
What it declares
Every artifact
- Type
- Package
- Origin
- Independently maintained
As a package
- Where it runs
- Inside its host
- Distributed through
- does not say
Connections
Sending a request to an OData service or push channel by hand
Download
README
quoted from bluefunda/abap-odata-test under MIT, readABAP OData Test Library
Where to use
You can use this in writing unit-tests or in ADT for console run or in standalone programs.
Example:
ADT console run (Single GET)
TRY.
DATA(url) = `/sap/opu/odata/IWFND/CATALOGSERVICE;v=2/ServiceCollection?$format=json`.
DATA(odata_test_client) = zcl_odata_test=>new( ).
out->write( odata_test_client->get_csrf_token( ) ).
odata_test_client->get(
url = url
csrf_fetch = abap_true
)->assert_http_200( "HTTP 200 assertion
)->assert_json_content_type( "'application/json; charset=utf-8'
)->assert_csrf_token_not_initial( "'x-csrf-token' fetch
)->assert_json_not_empty( "Empty JSON check
)->assert_json_path_exists( '/d/results/1/Title' "follows AJSON project
).
out->write( |INFO: | & |"GET | & |{ url }| & |"| & | passed | ).
out->write( odata_test_client->get(
url = url
csrf_fetch = abap_true
)->get_json_path_value( '/d/results/5/Title'
) ).
CATCH BEFORE UNWIND zcx_rest_client INTO DATA(exception).
out->write( exception->get_text( ) ).
CATCH cx_aunit_sbx_quit_test_method INTO DATA(uncaught_exception).
out->write( |ERROR: | & |"GET | & |{ url }| & |"| & | failed| ).
ENDTRY.
ADT Console Run (Multiple GETs)
METHOD if_oo_adt_classrun~main.
TRY.
DATA(bp_tab) = test_data( ). "prepare test data = 20 BP numbers
LOOP AT bp_tab ASSIGNING FIELD-SYMBOL(<bp>).
"prepare URL with variables
"v1 = variable value - name can be any as long as it is enclosed with {}
DATA(url) = `/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/BusinessPartnerSet({v1})?$format=json`.
"construct key-value table with variables and their respective values
DATA vars TYPE zif_odata_test=>t_vars.
vars = VALUE #( ( key = `v1` value = <bp> ) ).
"call GET with URL & VARS
DATA(odata_test_client) = zcl_odata_test=>new( ).
DATA(result) =
odata_test_client->get(
url = url
vars = vars ).
"check response body (one can check response time, response status, header etc)
out->write( result->response->body ).
ENDLOOP.
CATCH zcx_odata_client INTO DATA(error).
out->write( error->get_text( ) ).
ENDTRY.
ENDMETHOD.Others providing
Compare all 2 on the Calling a service by hand page →- ODAPUODAPUA UI5 app installed with abapGit that builds and saves test requests for OData services and connects to ABAP Push Channels, on S/4HANA systems.independent, abapUI5 app for OData test requests and ABAP Push Channels
Details
Sources
Sources are graph entities: the same page may back several entries, and an unreachable source flags every row that rests on it.
Compatibility and provenance
abaplint
Contributors
History in the atlas
- First seen.
For your agent
- Ref
artifact:bluefunda-abap-odata-test- JSON
- /artifacts/bluefunda-abap-odata-test.json
- MCP
- Connecting an agent