|
10 | 10 | import org.springframework.http.MediaType;
|
11 | 11 | import org.springframework.test.context.junit.jupiter.SpringExtension;
|
12 | 12 | import org.springframework.test.web.servlet.MockMvc;
|
| 13 | +import org.springframework.util.Assert; |
13 | 14 |
|
14 | 15 | import static org.hamcrest.Matchers.hasItem;
|
15 | 16 | import static org.hamcrest.Matchers.not;
|
@@ -133,4 +134,32 @@ public void generateClientWithInvalidOpenAPIUrl() throws Exception {
|
133 | 134 | .content("{\"openAPIUrl\": \"" + invalidOpenAPIUrl + "\"}"))
|
134 | 135 | .andExpect(status().isBadRequest());
|
135 | 136 | }
|
| 137 | + |
| 138 | + @Test |
| 139 | + public void generateWithOpenAPINormalizer() throws Exception { |
| 140 | + String withOpenAPINormalizer = "{\"openAPIUrl\":\"https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml\",\"openapiNormalizer\":[\"FILTER=operationId:updatePet\"],\"options\":{},\"spec\":{}}"; |
| 141 | + String withoutOpenAPINormalizer = "{\"openAPIUrl\":\"https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml\",\"options\":{},\"spec\":{}}"; |
| 142 | + |
| 143 | + String responseOfNormalized = mockMvc.perform(post("http://test.com:1234/api/gen/clients/java") |
| 144 | + .contentType(MediaType.APPLICATION_JSON) |
| 145 | + .content(withOpenAPINormalizer)) |
| 146 | + .andExpect(status().isOk()).andReturn().getResponse().getContentAsString(); |
| 147 | + String codeOfNormalized = new ObjectMapper().readValue(responseOfNormalized, ResponseCode.class).getCode(); |
| 148 | + Long lengthOfNormalized = Long.parseLong(mockMvc.perform(get("http://test.com:1234/api/gen/download/" + codeOfNormalized)) |
| 149 | + .andExpect(content().contentType("application/zip")) |
| 150 | + .andExpect(status().isOk()).andReturn().getResponse().getHeader("Content-Length")); |
| 151 | + |
| 152 | + String responseOfNotNormalized = mockMvc.perform(post("http://test.com:1234/api/gen/clients/java") |
| 153 | + .contentType(MediaType.APPLICATION_JSON) |
| 154 | + .content(withoutOpenAPINormalizer)) |
| 155 | + .andExpect(status().isOk()).andReturn().getResponse().getContentAsString(); |
| 156 | + |
| 157 | + String codeOfNotNormalized = new ObjectMapper().readValue(responseOfNotNormalized, ResponseCode.class).getCode(); |
| 158 | + Long lengthOfNotNormalized = Long.parseLong(mockMvc.perform(get("http://test.com:1234/api/gen/download/" + codeOfNotNormalized)) |
| 159 | + .andExpect(content().contentType("application/zip")) |
| 160 | + .andExpect(status().isOk()).andReturn().getResponse().getHeader("Content-Length")); |
| 161 | + |
| 162 | + Assert.isTrue(lengthOfNormalized <= lengthOfNotNormalized,"Using the normalizer should result in a smaller or equal file size"); |
| 163 | + |
| 164 | + } |
136 | 165 | }
|
0 commit comments