Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

How to bypass the default validation on value type

chaieh1015
chaieh1015 Posts: 6

I'm testing an API passing a string value(e.g. "ABC") to a numeric field. The input value is sent from an excel file.
If I run the test, the transaction does not happen, and I get error message that says something like "ABC" is not a numeric value.

My test node is using Input Mode: Form JSON, but it doesn't need to be this mode..

Comments

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited October 2020

    A JSON string is represented very differently than a JSON number. You can't sometimes encode the value as a string and sometimes a number or something else. This is true whether you use the Form JSON view or the Literal view.

    You would probably need to setup different tests, one that has the value configured to be sent as a JSON string and one that has the value configured to be sent as a JSON number. This may be arguably better for organization anyway, keeping your positive tests separate from your negative tests.

  • chaieh1015
    chaieh1015 Posts: 6

    If I use the Literal view with either 123 or "123" for the input, the API runs fine with its own validation message and I get the transaction details, but yes. I agree with your point about Pos/Neg scenarios.

    Thank you!

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited October 2020

    If I use the Literal view with either 123 or "123" for the input

    Sending "123" isn't the same as sending 123 without quotes as they have different types and may be interpreted differently. Also, "ABC" without quotes isn't valid JSON. So, it depends what you want to send. You can't sometimes send "ABC" (with quotes) or 123 (without quotes) unless you setup two separate tests.

  • chaieh1015
    chaieh1015 Posts: 6
    edited October 2020

    ABC was an example. What I'm really sending is something like below.
    "userInput" : 123
    vs.
    "userInput" : "123"

    I would like to test both and the first case is POS, and second is NEG because the field "userInput" should accept a numeric, not a string. The failure is correct result in the end, but I want see if the API could be ran with the above setting (JSON view) so the API transaction is created with an error message rather than the Parasoft drops/blocks it without running the API.

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited October 2020

    The message can't be configured to sometimes send a value as a JSON string and sometimes as a JSON number based on some criteria. As mentioned, you have to configure two separate tests where one has the value configured as a string and the other with the value configured a number since the logical value has to be encoded differently in each case.

  • chaieh1015
    chaieh1015 Posts: 6

    Alright.. Thanks!