Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Cloud Contract Fails to generate tests for Form URL encoded request body #1931

Closed
DhavalShewale opened this issue Aug 18, 2023 · 3 comments
Labels
Milestone

Comments

@DhavalShewale
Copy link

Spring Cloud Contract does not generate correct test classes for Form URL encoded request body

Version: 4.0.4

Contract

request:
  method: POST
  url: /exportData
  body: "fromDt=16-Aug-2023&toDt=25-Aug-2023"
  headers:
    Content-Type: "application/x-www-form-urlencoded; charset=UTF-8"
response:
  status: 200
  bodyFromFileAsBytes: response/export_data.xlsx
  headers:
    Content-Disposition: "attachment; filename=[EXTRACT] Export Data.xlsx"

Generated Test Case

@Test
public void validate_export_data() throws Exception {
	// given:
		MockMvcRequestSpecification request = given()
				.header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
				.body("");

	// when:
		ResponseOptions response = given().spec(request)

				.post("/exportData");

	// then:
		assertThat(response.statusCode()).isEqualTo(200);
		assertThat(response.header("Content-Disposition")).isEqualTo("attachment; filename=[EXTRACT] Export Data.xlsx");


	// and:
		assertThat(response.getBody().asByteArray()).isEqualTo(fileToBytes(this, "export_data_response_export_data.xlsx"));
}

The body of request is generated as empty string in Test Class instead of the configured body in yaml

The behavior is same even if contract is configured in groovy as follows:

org.springframework.cloud.contract.spec.Contract.make {
  request {
    method 'POST'
    url '/exportData'
    headers {
      header("Content-Type": 'application/x-www-form-urlencoded; charset=UTF-8')
    }
    body('fromDt=16-Aug-2023&toDt=25-Aug-2023')
  }
  response {
    status 200
  }
}
@marcingrzejszczak
Copy link
Contributor

fixed through 7975d43

@DhavalShewale
Copy link
Author

DhavalShewale commented Sep 26, 2023

@marcingrzejszczak: Do we know by when this fix will be GA? I checked the milestone page and it does not list a release date.

@marcingrzejszczak
Copy link
Contributor

We haven't yet picked the date. You can check this page https://github.com/spring-cloud/spring-cloud-release/milestones and once we agree on a release date the page will get updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Status: Done
Development

No branches or pull requests

3 participants