HttpClientErrorException for 3 test cases

These 3 test cases are always failing. I am unable to figure out why. I ran as well as debugged these tests from the beaker icon. The Java Test Report showed pass there.

Can anyone help me?

Hi @KaranK
Looks like you are facing challenges in the current module.

Below is a link to all the FAQ’s for the current module

Below are a few similar topics raised by other users which you might find usefull

Note - This is a BETA Feature,if you find this helpful, kindly let us know.
Feedback link -

Kindly mark this as a solution if this has helped you solve your query

Hi @KaranK

Can you please paste stack trace using the command
./gradlew build --info

This will further gives us insight into your code.

Possible reason might be: Merging of new module lead to losing your old logic.

Another possible way to resolve is to debug mainReadQuotes using debugger if it’s expected and actual behaviour matches.

Yeah sir. It’s the same exception in each function.

However, there is no stock named ‘CISCO’ in the files used in these functions.

Hi @KaranK

In stack Trace clearly Error is raised from PotfolioManagerApplication function mainReadQuote Line No. 173

Mark Breakpoint in mainReadQuote.

Run as Debug Test. Check if mainReadQuote behaves in the way you expect it.

Try to paste mainReadQuote if you are not able to figure out what is raising the error.

Analyze your logic, something might be missing in the logic.

Sir I have already run these 3 functions as Debug test. The expected ArrayList is matching with the ArrayList that is generated in my function. I am unable to figure out the error since yesterday morning.

Hi @KaranK

You changed trades.json File.

    "symbol": "MSFT",
    "quantity": 100,
    "tradeType": "BUY",
    "purchaseDate": "2019-01-07"
    "symbol": "CSCO",
    "quantity": 10,
    "tradeType": "BUY",
    "purchaseDate": "2019-01-09"
    "symbol": "CTS",
    "quantity": 50,
    "tradeType": "BUY",
    "purchaseDate": "2019-01-29"

CISCO is not the name of any Symbol.
Which is being Raised by HttpClient.

Please Verify if any changes are made in trades.json File.

I haven’t touched these files.

Hey @KaranK,

You need to change your code. You are using HttpHeaders and HttpEntity and all. That needs to cover all error codes as well.

I’ll advise you to use RestTemplate library instead and use a RestTemplate class object to make your calls. It’ll be much easier for you to do as well. You can use its getForObject method to make your calls. It works on similar pattern as readValue method of ObjectMapper.

If you go over trades_invalid_stock.json, you’ll find a stock with symbol CISCO, which is intentionally wrong for testing purpose. Its possible the debugger tests were taking data from a different json file and hence all was working fine.

Sir even after using getForObject these 3 test cases fail with the same error messgae.

Okay, Have you added a null check before using the values returned by the API?
Like if the returned result is not null, only then you need to make a TotalReturnsDto object with that particular stocks’s symbol.

Closing this topic as your issue is resolved by the mentor. If it is still not resolved, Kindly un-mark the accepted solution or create a new topic and post this question as a reference link in the description of the new topic.