|
19 | 19 | */
|
20 | 20 | package org.zaproxy.zap.extension.openapi.v3;
|
21 | 21 |
|
22 |
| -import static org.hamcrest.MatcherAssert.assertThat; |
23 |
| -import static org.hamcrest.Matchers.contains; |
24 |
| -import static org.hamcrest.Matchers.emptyString; |
25 |
| -import static org.hamcrest.Matchers.is; |
26 | 22 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
27 | 23 | import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
28 | 24 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
@@ -716,19 +712,30 @@ void shouldGenerateBodyWithNoSchema() throws IOException {
|
716 | 712 | }
|
717 | 713 |
|
718 | 714 | @Test
|
719 |
| - void shouldNotGenerateContentForApplicationXml() throws IOException { |
| 715 | + void shouldGenerateXmlObject() throws IOException { |
720 | 716 | // Given
|
721 |
| - OpenAPI definition = parseResource("openapi_xml_bodies.yaml"); |
722 |
| - OperationModel operationModel = |
723 |
| - new OperationModel("/xml", definition.getPaths().get("/xml").getPost(), null); |
| 717 | + OpenAPI openAPI = parseResource("openapi_xml_bodies.yaml"); |
| 718 | + |
724 | 719 | // When
|
725 |
| - String content = new RequestModelConverter().convert(operationModel, generators).getBody(); |
| 720 | + String xmlString = |
| 721 | + generators |
| 722 | + .getBodyGenerator() |
| 723 | + .generateXml( |
| 724 | + openAPI.getPaths() |
| 725 | + .get("/xml") |
| 726 | + .getPost() |
| 727 | + .getRequestBody() |
| 728 | + .getContent() |
| 729 | + .get("application/xml") |
| 730 | + .getSchema()); |
| 731 | + |
726 | 732 | // Then
|
727 |
| - assertThat(content, is(emptyString())); |
728 |
| - assertThat( |
729 |
| - generators.getErrorMessages(), |
730 |
| - contains( |
731 |
| - "Not generating request body for operation xml, the content type application/xml is not supported.")); |
| 733 | + String expectedOutput = |
| 734 | + "<value-string>John Doe</value-string>\n" |
| 735 | + + "<value-boolean>true</value-boolean>\n" |
| 736 | + + "<value-integer>10</value-integer>\n"; |
| 737 | + |
| 738 | + assertEquals(expectedOutput, xmlString); |
732 | 739 | }
|
733 | 740 |
|
734 | 741 | @Test
|
|
0 commit comments