question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Response status and type verification error

See original GitHub issue

Hi,

I have an example project (https://github.com/QAJungle/vertx-testing-example) where I have a Vertx application. I’m doing pact testing.

One of the problems is that when I launch a GetABookByISBNPactTest GetABookByNamePactTest or GetAllBooksPactTest (https://github.com/QAJungle/vertx-testing-example/tree/master/vertx-testing-example-server/src/test/java/com/qajungle/vertx) I obtain the next error, but is random, not alwails fails.

java.lang.AssertionError: 0 - Expected a header 'Content-Type' but was missing 1 - Expected a response type of 'application/json' but the actual type was 'text/plain'

The second error is status assertion error with AddABookPactTest. When I launch tests I obtain the next error:

java.lang.AssertionError: 0 - expected status of 201 but was 200

If you see the pact (https://github.com/QAJungle/vertx-testing-example/blob/master/vertx-testing-example-server/src/test/resources/pacts/add_book_test_consumer-add_book_test_provider.json) and controller code (https://github.com/QAJungle/vertx-testing-example/blob/master/vertx-testing-example-server/src/main/java/com/qajungle/vertx/infrastructure/delivery/vertx/controller/BookController.java#L47) I send 201 status code. In postman I validated it correctly.

You can see the provider and the client in the same repo.

I use: pact-jvm-provider-junit5_2.12 3.6.2 version.

Thanks.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
uglyogcommented, May 4, 2019

I don’t know much about vert.x, but I can see a difference when running the app versus when the pact test runs.

With the app running:

$ curl -v http://localhost:8080/books/978-0-321-53446-0
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x55c7ea9295c0)
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /books/978-0-321-53446-0 HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.64.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< content-type: application/json; charset=utf-8
< content-length: 62
< 
{
  "name" : "Agile Testing",
  "isbn" : "978-0-321-53446-0"
* Connection #0 to host localhost left intact
}

and when the pact test is run with debug logging enabled:

11:43:40.918 [main] DEBUG au.com.dius.pact.provider.junit5.PactVerificationStateChangeExtension - beforeEach for interaction 'GET REQUEST'
11:43:40.919 [main] DEBUG au.com.dius.pact.provider.junit5.PactVerificationStateChangeExtension - Invoking state change method getBookByISBN for state 'a book by ISBN'

Verifying a pact between get_book_by_isbn_test_consumer and get_book_by_isbn_test_provider
  Given a book by ISBN
  GET REQUEST
11:43:41.046 [main] DEBUG au.com.dius.pact.provider.ProviderClient - Making request for provider au.com.dius.pact.provider.ProviderInfo(http, localhost, 8080, /, provider, null, null, null, null, null, false, null, changeit, null, true, false, true, null, [], []):
11:43:41.060 [main] DEBUG au.com.dius.pact.provider.ProviderClient - 	method: GET
	path: /books/978-0-321-53446-0
	query: [:]
	headers: [:]
	matchers: MatchingRules(rules={})
	generators: Generators(categories={})
	body: MISSING
11:43:41.205 [vert.x-eventloop-thread-2] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096
11:43:41.205 [vert.x-eventloop-thread-2] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2
11:43:41.205 [vert.x-eventloop-thread-2] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16
11:43:41.205 [vert.x-eventloop-thread-2] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8
11:43:41.241 [vert.x-eventloop-thread-2] DEBUG io.netty.handler.codec.compression.ZlibCodecFactory - -Dio.netty.noJdkZlibDecoder: false
11:43:41.241 [vert.x-eventloop-thread-2] DEBUG io.netty.handler.codec.compression.ZlibCodecFactory - -Dio.netty.noJdkZlibEncoder: false
11:43:41.316 [main] DEBUG au.com.dius.pact.provider.ProviderClient - Received response: HTTP/1.1 200 OK
11:43:41.318 [main] DEBUG au.com.dius.pact.provider.ProviderClient - Response: {statusCode=200, headers={content-length=[0]}, contentType=application/json; charset=UTF-8, data=}
    returns a response which
      has status code 200 (OK)
      includes headers
        "Content-Type" with value "application/json; charset=utf-8" (FAILED)
      has a matching body (FAILED)

Failures:

0) Verifying a pact between get_book_by_isbn_test_consumer and get_book_by_isbn_test_provider - GET REQUEST returns a response which includes headers "Content-Type" with value "[application/json; charset=utf-8]"
      Expected a header 'Content-Type' but was missing

1) Verifying a pact between get_book_by_isbn_test_consumer and get_book_by_isbn_test_provider - GET REQUEST returns a response which has a matching body
      comparison -> Expected a response type of 'application/json' but the actual type was 'text/plain'

particularly, the line headers={content-length=[0]}, contentType=application/json; charset=UTF-8, data=} shows that the content type header is not being set correctly. It should be content-Type not contentType.

0reactions
goelshubham1509commented, Oct 14, 2020

0 - Expected a header ‘Content-Type’ but was missing 1 - expected status of 200 but was 404 2 - Expected a response type of ‘application/json’ but the actual type was ‘text/plain’

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP response status codes - MDN Web Docs - Mozilla
HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped in five classes:
Read more >
Verify Return and Error Codes - Twilio
Error Code HTTP Status Category 60000 400 ALL 60001 401 ALL 60002 400 ALL
Read more >
Response status and type verification error · Issue #856 · pact ...
Hi, I have an example project (https://github.com/QAJungle/vertx-testing-example) where I have a Vertx application. I'm doing pact testing.
Read more >
A Complete Guide and List of HTTP Status Codes
A complete list of HTTP status codes with explaination of what they are, why they occur and what you can do to fix...
Read more >
Which status code should I use for failed validations or invalid ...
Failed validation: 403 Forbidden ("The server understood the request, but is refusing to fulfill it") ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found