Show error message if date is null or greater then 7 days

Hi,

I am new to parasoft and trying to understand my requirement. I have two scenarios where if date is null or greater then 7 days then it should show error message as:invalid dates. I can see my message if date is passed but not without. Can any one help me on this issue please?

Below is my requirement flow:-

Assets:-

Test1 with dates.
Test2 with dates.
Responder (Parameters with dates)

Test1 without dates
Test2 without dates
Responder (No Parameters - without dates)

Tagged:

Comments

  • williammccuskerwilliammccusker Posts: 409 ✭✭

    Hi,
    I made a few tweaks to the previous example I shared with you to make this work. It is mostly changes to the custom correlation script. I also removed a URL parameter correlation from the first responder and have the script check for the presence or absence of the parameter.

    The first responder catches cases when the parameter is not sent, or is sent will empty value. It also checks for the mentioned date condition using some date math. Basic tutorial can be found here

    https://beginnersbook.com/2017/11/java-8-adding-days-to-the-localdate/

    The second responder returns an ok response assuming that if the message does not match the first responder then the date is ok.

    Example requests that get an error
    http://localhost:9080/parameters?date=2020-02-07
    http://localhost:9080/parameters?date=
    http://localhost:9080/parameters?date
    http://localhost:9080/parameters

  • jithenderreddyjithenderreddy Posts: 73

    Thank You for sharing code with me. I will verify and let you know if i see any issues.

  • jithenderreddyjithenderreddy Posts: 73

    Thank You for helping. I have created new responder with date is null. I tried executing it and it never shows error message. It is always showing line number 1. I am i missing something?

    i have created responder with 4 parameters and put it under the assets.:-

    1. from date
    2. to date
    3. city
    4. IDs
  • williammccuskerwilliammccusker Posts: 409 ✭✭

    Hi,

    Without being able to see your responders I will have to guess. Is the first responder setup to match when the date is missing? Thats what it sounds like is happening. I would check the correlation condition for "1. from date" to make sure that it is not accepting the null case when it should not.

  • jithenderreddyjithenderreddy Posts: 73

    Thank You. I have created two responders with and without parameters. The date parameter responder have 4 parameters as mentioned above. It is placed under asset which have dates. I also created another responder without parameters and placed under no dates asset. I am following below:-

    Asset:-
    Test1 with date
    Test2 with date
    Dates Responder with 4 parameters.
    Test1 without date
    Test2 without date
    Test3 without date
    Without-Dates Responder with no parameters.

    Executing with 4 parameters as date is null always shows empty response.

  • williammccuskerwilliammccusker Posts: 409 ✭✭

    Hi,

    I don't have enough information to say what exactly is configured incorrectly. It still sounds like you have a correlation misconfigured. If you use event monitoring you can see which responder was selected to send the response. Base on that I would debug that responders correlations to figure why it matched when it should not have.

    See this in the documentation to learn about event monitoring
    https://docs.parasoft.com/display/VIRT9105/Gaining+Visibility+into+Server+Events
    https://docs.parasoft.com/display/SOAVIRT9103/Monitoring+Parasoft+Virtualize+Server+Events

  • jithenderreddyjithenderreddy Posts: 73

    Thank You. I am seeing some validation result - failure error message in the log as:- java.text.ParseException: Unparseable date: "".

  • williammccuskerwilliammccusker Posts: 409 ✭✭

    Hi,
    It sounds like one of the responders may be trying to parse an empty string. You probably will want to update that responder to handle the empty string case.

  • jithenderreddyjithenderreddy Posts: 73

    It looks like the issue is in other area. My responders are not even reaching there. Is there a way in parasoft where i can go to the error line directly ex: line 13 etc? I want to see if there is any issue and might try to fix it.

  • williammccuskerwilliammccusker Posts: 409 ✭✭

    Hi,
    I am not sure. I think because you are using scripting you have to locate which responder's script is causing that manually. It will be one the responders before the one that sent back the response.

  • jithenderreddyjithenderreddy Posts: 73

    Thank You. I figured out the responder that is causing the error. The script has lot of logic and i am not able to figure out where the problem is. I am trying to see if there is a line number that is causing the problem.

  • williammccuskerwilliammccusker Posts: 409 ✭✭

    Hi,

    It looked like the error message you mention said line 13? The editor for the scripts should have the line number on the left side edge of the editor.

  • jithenderreddyjithenderreddy Posts: 73

    My responder always throws error if my date is null. I also have logic if date is > 7 from current date but this logic never runs. It always shows for date is greater then current date. How can i make them work for both?

  • williammccuskerwilliammccusker Posts: 409 ✭✭

    Hi,
    I am not sure how that case is different from the example that I previously shared. In that example it the "error case" responder checked for the date being null or empty.

    Are you saying you have two separate cases? One for null date and one for date being to far in the future?

    If that is the case the original example I provided checks for both things so you should be able to use that script as a basis for modification.

  • jithenderreddyjithenderreddy Posts: 73

    Sorry. They are two different cases.

    1. Check if date is null then shows message as ex:- Please enter dates.
    2. Check if date is >7 then shows as ex: Date is 7 days greater then current.

    I made some changes to the code provided but not working. Now i am seeing data for future dates. It should not allow for future dates.

  • williammccuskerwilliammccusker Posts: 409 ✭✭

    Hi,
    Here is an example. The first responder checks for the null case, the second for the future dates and the third is the "ok" response.

  • jithenderreddyjithenderreddy Posts: 73

    Thak You. I have gone through your responder and create one for my message.

    I have three scenarios below:-

    1. Date is empty then throw - error date is empty with code 555.
    2. Date is greater then today - error date is greater with code 666.
    3. Date is greater then 7 days then error date is greater with code 777.

    i always gets the error message for 2nd. it never reaches to 3rd. Should i change the sequence below to work it or it is good?

    my sequence is as below:-

    Responder-DateEmpty
    Responder-DateGreaterToday
    Responder-DateGreaterThen7

  • williammccuskerwilliammccusker Posts: 409 ✭✭

    Hi,

    From the way you have the responders ordered yes 2. would always respond because the condition "is greater than today" is always true for the case "7 days greater than today"

    Try moving responder 3. to be the second responder.

  • jithenderreddyjithenderreddy Posts: 73

    Thank You. It is working if i move it to 1 position.

Sign In or Register to comment.