-1

I have a karate get test that is failing with a 400, but if I copy everything to postman it works. Also if I change the get to a post in the code and test and add an empty request body in the test it works. What am I doing wrong?

Here's the code to endpoint to be tested:

@Log
@Named
@Profile
@RestController
@Singleton
@Path("/commercial/deposits/accounts")
@Api(value = "/commercial/deposits/accounts")
@Produces({"application/vnd.com.capitalone.api+v3+json", "application/vnd.com.capitalone.api+v3+xml",
           "application/vnd.com.capitalone.api+v3+javascript", "application/javascript", MediaType.APPLICATION_JSON,
           MediaType.APPLICATION_XML})
@Consumes({"application/vnd.com.capitalone.api+v3+json", "application/vnd.com.capitalone.api+v3+xml",
            MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public class CommercialAccountsRSResource  {

    @Inject
    private CommercialAccountsRSService commercialAccountsRSService;

    /**
     * Account Summary - retrieves current bank account balances for accounts specified
     *
     * @param entityRequest Standard {@link EntityRequest} fields
     *
     * @return A BankThing
     */

    @GET
    @JSONP(queryParam = JSONP.DEFAULT_QUERY)
    @ApiOperation(value = "Get account balances for accountIds specified.", notes = "Get account balances for accountIds specified.", response = AccountSummaryResponse.class)
    @ApiResponses({
            @ApiResponse(code = HttpURLConnection.HTTP_OK, message = ChassisHTTPStatusMessageConstants.SUCCESS_MESSAGE),
            @ApiResponse(code = HttpURLConnection.HTTP_NOT_AUTHORITATIVE, message = ChassisHTTPStatusMessageConstants.PARTIAL_SUCCESS_MESSAGE),
            @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = ChassisHTTPStatusMessageConstants.BAD_REQUEST_MESSAGE),
            @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = ChassisHTTPStatusMessageConstants.UNAUTHORIZED_MESSAGE),
            @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = ChassisHTTPStatusMessageConstants.FORBIDDEN_MESSAGE),
            @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = ChassisHTTPStatusMessageConstants.NOT_FOUND_MESSAGE),
            @ApiResponse(code = HttpURLConnection.HTTP_BAD_METHOD, message = ChassisHTTPStatusMessageConstants.METHOD_NOT_ALLOWED_MESSAGE),
            @ApiResponse(code = HttpURLConnection.HTTP_NOT_ACCEPTABLE, message = ChassisHTTPStatusMessageConstants.NOT_ACCEPTABLE_MESSAGE),
            @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = ChassisHTTPStatusMessageConstants.INTERNAL_SERVER_ERROR_MESSAGE)})
    public AccountSummaryResponse accountSummaryResponse(@BeanParam EntityRequest entityRequest,
                                                         @ApiParam(value = "Customer Account number", name = "accountReferenceId",  required = true, allowMultiple = true) @QueryParam("accountReferenceId") String accountReferenceId,
                                                         @ApiParam(value = "Bank number", name = "bankNumber",  required = true, allowMultiple = true) @QueryParam("bankNumber") String bankNumber)
    {
        CommercialAccountsRSResourceUtil.validateInput(accountReferenceId, bankNumber);
        return commercialAccountsRSService.accountSummaryResponse(accountReferenceId, bankNumber);
    }

Here is the karate scenario:

Feature: Test DDA Account Summary

  Background:
    * url baseURL
    And headers { Api-Key: 'CMIX', Accept: 'application/json;v=3', Content-Type: 'application/json;v-3',Authorization: '#(bearerToken)' }

  @local
  Scenario: Get single account successfully
    Given path '/dda-account-summary-web/commercial/deposits/accounts'
    And param accountReferenceId = '0000030651'
    And param bankNumber = '0030'
    When method GET
    Then status 200
    And match response == read('AccountSummarySingleSuccess.json')

And this is the result:

08:36:16.316 [ForkJoinPool-1-worker-1] INFO  com.intuit.karate - << lock released, cached callSingle: classpath:oAuthToken.feature
08:36:16.324 [ForkJoinPool-1-worker-1] INFO  com.intuit.karate - baseURL: http://localhost:11400 
08:36:16.338 [ForkJoinPool-1-worker-1] DEBUG com.intuit.karate - request:
1 > GET http://localhost:11400/dda-account-summary-web/commercial/deposits/accounts?accountReferenceId=0000030651&bankNumber=0030
1 > Accept: application/json;v=3
1 > Accept-Encoding: gzip,deflate
1 > Api-Key: CMIX
1 > Authorization: Bearer xxx
1 > Connection: Keep-Alive
1 > Content-Type: application/json;v-3
1 > Host: localhost:11400
1 > User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_271)

08:36:16.390 [ForkJoinPool-1-worker-1] DEBUG com.intuit.karate - response time in milliseconds: 50.62
1 < 400
1 < Cache-Control: no-cache, no-store, max-age=0, must-revalidate
1 < Connection: close
1 < Content-Type: application/json; v=3
1 < Date: Thu, 04 Feb 2021 13:36:16 GMT
1 < Expires: 0
1 < Pragma: no-cache
1 < Set-Cookie: JSESSIONID=09DC5825407678630098BCD5087425DA; Path=/dda-account-summary-web; HttpOnly
1 < Transfer-Encoding: chunked
1 < X-Content-Type-Options: nosniff
1 < X-Frame-Options: DENY
1 < X-XSS-Protection: 1; mode=block
{
  "timestamp": "2021-02-04T13:36:16.385+00:00",
  "status": 400,
  "error": "Bad Request",
  "message": "",
  "path": "/dda-account-summary-web/commercial/deposits/accounts"
}
  • 1
    Since I'm not sure what is wrong, I'm not sure what is un-necessary, but here's a curl command that works: curl --location --request GET 'http://localhost:11400/dda-account-summary-web/commercial/deposits/accounts/?bankNumber=0030&accountReferenceId=0000030651' \ --header 'Accept: application/json;v=3' \ --header 'Api-Key: CMIX' \ --header 'Content-Type: application/json;v=3' \ --header 'Authorization: Bearer xxx' \ --header 'Cookie: JSESSIONID=4F26ECB17337846AA060C4A1162B8A5E' \ --data-raw '' – Pat Littleton Feb 04 '21 at 14:12
  • the server-side java side is of no use to me, personally. the cURL is also not helpful because I can't try the request. anyway attempting to answer, if that doesn't help, I'll pass – Peter Thomas Feb 04 '21 at 14:20

1 Answers1

1

Your command seems to be un-conventional, with a body as part of the GET.

Please try with the Karate 1.0 series: https://github.com/intuit/karate/wiki/1.0-upgrade-guide

and add this line before the method step:

And request ''

If that doesn't work, it can be a bug, but unless you provide a way to replicate, there isn't much I can do: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

EDIT: Postman unfortunately auto-adds an Accept header so try this also:

And header Accept = 'application/json'
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • The GET does not have a body. I only added a body to see if the POST would work and it did, but ultimately I need the GET. I will try to build a skeleton and submit it as an issue. – Pat Littleton Feb 04 '21 at 15:02
  • 1
    Actually I found the error. For the ContentType I had 'application/json;v-3'. Once I changed it to v=3, it started working. Couldn't see it for looking before. Thanks for your help anyway. – Pat Littleton Feb 04 '21 at 18:22