Skip to content

Additional escape character added to the escaped header values results in test failure #1790

@hegdevishwa

Description

@hegdevishwa

Additional escape characters (\) were added to the header in generated tests
Looks similar to: #851
Spring cloud contract plugin version: 2.2.3.RELEASE

Contract :

import static org.springframework.cloud.contract.spec.Contract.make

[
    make {
        request {
            name("test")
            method 'GET'
            urlPath('/test')
        }
        response {
            status OK()
            body( "test": "\"escaped\"")
            headers {
                contentType('application/pdf')
                header(contentDisposition(), "attachment; filename=\"test.pdf\"")
            }
        }
    }
]

Generated test:

	@Test
	public void validate_test() throws Exception {
		// given:
			RequestSpecification request = given();


		// when:
			Response response = given().spec(request)
					.get("/test");

		// then:
			assertThat(response.statusCode()).isEqualTo(200);
			assertThat(response.header("Content-Type")).matches("application/pdf.*");
			assertThat(response.header("Content-Disposition")).isEqualTo("attachment; filename=\\\"test.pdf\\\"");

		// and:
			String responseBody = response.getBody().asString();
			assertThat(responseBody).isEqualTo("{test=\"escaped\"}");
	}

Note that the body is compiled correctly but the header Content-Disposition value has an additional \\ resulting in a test failure.
The compiled header should have been assertThat(response.header("Content-Disposition")).isEqualTo("attachment; filename=\"test.pdf\"");

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions