This repository has been archived by the owner on Dec 17, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
http json converter escaping and valid empty json conversion added #130
Merged
Goala
merged 2 commits into
abap-observability-tools:main
from
JohannesKonings:converter
Jan 31, 2021
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
110 changes: 110 additions & 0 deletions
110
src/zamp_converter/zcl_amp_conv_http_json.clas.testclasses.abap
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 @@ | ||
CLASS ltcl_test DEFINITION FOR TESTING | ||
DURATION SHORT | ||
RISK LEVEL HARMLESS. | ||
|
||
PRIVATE SECTION. | ||
DATA cut TYPE REF TO zcl_amp_conv_http_json. | ||
|
||
METHODS setup. | ||
METHODS test_content_type FOR TESTING. | ||
METHODS test_without_metrics FOR TESTING. | ||
METHODS test_only_allowed_characters FOR TESTING. | ||
"! not allowed characters: https://www.tutorialspoint.com/json_simple/json_simple_escape_characters.htm | ||
METHODS test_special_characters FOR TESTING. | ||
|
||
ENDCLASS. | ||
|
||
CLASS ltcl_test IMPLEMENTATION. | ||
|
||
|
||
METHOD test_only_allowed_characters. | ||
|
||
DATA metric_list TYPE zif_amp_converter=>metric_store. | ||
|
||
metric_list = VALUE #( ( metric_scenario = 's1' metric_group = 'g1' metric_key = 'k1' metric_value = 1 ) | ||
( metric_scenario = 's1' metric_group = 'g1' metric_key = 'k2' metric_value = 2 ) | ||
( metric_scenario = 's1' metric_group = 'g1' metric_key = 'k3' metric_value = 3 ) ). | ||
|
||
DATA(act_converted_metrics) = cut->zif_amp_converter~convert( metric_store = metric_list ). | ||
|
||
DATA(exp_converted_metrics) = |\{"NPL_001_s1_g1": \{"k1": 1, "k2": 2, "k3": 3\}\}|. | ||
|
||
CONDENSE act_converted_metrics NO-GAPS. | ||
CONDENSE exp_converted_metrics NO-GAPS. | ||
|
||
cl_aunit_assert=>assert_equals( EXPORTING | ||
exp = exp_converted_metrics | ||
act = act_converted_metrics | ||
msg = |wrong json with only allowed characters| ). | ||
|
||
ENDMETHOD. | ||
|
||
METHOD test_special_characters. | ||
|
||
DATA metric_list TYPE zif_amp_converter=>metric_store. | ||
|
||
metric_list = VALUE #( ( metric_scenario = 's1' metric_group = 'g1' metric_key = 'k"1"' metric_value = 1 ) | ||
( metric_scenario = 's1' metric_group = 'g1' metric_key = 'k\b2' metric_value = 2 ) | ||
( metric_scenario = 's1' metric_group = 'g1' metric_key = 'k\f3' metric_value = 3 ) | ||
( metric_scenario = 's1' metric_group = 'g1' metric_key = 'k\n4' metric_value = 4 ) | ||
( metric_scenario = 's1' metric_group = 'g1' metric_key = 'k\r5' metric_value = 5 ) | ||
( metric_scenario = 's1' metric_group = 'g1' metric_key = 'k\t6' metric_value = 6 ) | ||
( metric_scenario = 's1' metric_group = 'g1' metric_key = 'k\7' metric_value = 7 ) ). | ||
|
||
DATA(act_converted_metrics) = cut->zif_amp_converter~convert( metric_store = metric_list ). | ||
|
||
DATA(exp_converted_metrics) = |\{"NPL_001_s1_g1": \{"k\\"1\\"": 1,| && | ||
|"k\\\\b2": 2,| && | ||
|"k\\\\f3": 3,| && | ||
|"k\\\\n4": 4,| && | ||
|"k\\\\r5": 5,| && | ||
|"k\\\\t6": 6,| && | ||
|"k\\\\7": 7\}\}|. | ||
|
||
CONDENSE act_converted_metrics NO-GAPS. | ||
CONDENSE exp_converted_metrics NO-GAPS. | ||
|
||
cl_aunit_assert=>assert_equals( EXPORTING | ||
exp = exp_converted_metrics | ||
act = act_converted_metrics | ||
msg = |wrong json with special metrics| ). | ||
|
||
ENDMETHOD. | ||
|
||
METHOD setup. | ||
cut = NEW zcl_amp_conv_http_json( ). | ||
ENDMETHOD. | ||
|
||
METHOD test_content_type. | ||
|
||
DATA(exp_content_type) = |application/json|. | ||
|
||
cut->zif_amp_converter~convert( EXPORTING | ||
metric_store = VALUE #( ( ) ) | ||
IMPORTING | ||
content_type = DATA(act_content_type) ). | ||
|
||
cl_aunit_assert=>assert_equals( EXPORTING | ||
exp = exp_content_type | ||
act = act_content_type | ||
msg = |wrong content type| ). | ||
|
||
ENDMETHOD. | ||
|
||
METHOD test_without_metrics. | ||
|
||
DATA(act_converted_metrics) = cut->zif_amp_converter~convert( metric_store = VALUE #( ) ). | ||
|
||
DATA(exp_converted_metrics) = |\{\}|. | ||
|
||
CONDENSE act_converted_metrics NO-GAPS. | ||
CONDENSE exp_converted_metrics NO-GAPS. | ||
|
||
cl_aunit_assert=>assert_equals( EXPORTING | ||
exp = exp_converted_metrics | ||
act = act_converted_metrics | ||
msg = |wrong empty json| ). | ||
|
||
ENDMETHOD. | ||
|
||
ENDCLASS. |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may use the replace function for this
https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-us/abenreplace_functions.htm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good hint. Maybe we can raise a good first issue to do that afterwards?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue created: #133