|
58 | 58 |
|
59 | 59 | import static java.util.stream.Collectors.groupingBy;
|
60 | 60 | import static org.assertj.core.api.Assertions.assertThat;
|
| 61 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
61 | 62 | import static org.openapitools.codegen.TestUtils.*;
|
62 | 63 | import static org.openapitools.codegen.languages.AbstractJavaCodegen.GENERATE_BUILDERS;
|
63 | 64 | import static org.openapitools.codegen.languages.AbstractJavaCodegen.GENERATE_CONSTRUCTOR_WITH_ALL_ARGS;
|
@@ -4476,46 +4477,140 @@ public void multiLineTagDescription() throws IOException {
|
4476 | 4477 |
|
4477 | 4478 | @Test
|
4478 | 4479 | public void testSSEOperationSupport() throws Exception {
|
4479 |
| - Map<String, Object> additionalProperties = Map.of(SSE, true, REACTIVE, "true", INTERFACE_ONLY, "false", |
4480 |
| - DELEGATE_PATTERN, "true"); |
| 4480 | + Map<String, Object> additionalProperties = Map.of( |
| 4481 | + SSE, true, |
| 4482 | + REACTIVE, "true", |
| 4483 | + INTERFACE_ONLY, "false", |
| 4484 | + DELEGATE_PATTERN, "true" |
| 4485 | + ); |
4481 | 4486 | Map<String, File> files = generateFromContract("src/test/resources/3_0/sse.yaml", "spring-boot", additionalProperties);
|
4482 | 4487 |
|
4483 | 4488 | MapAssert.assertThatMap(files).isNotEmpty();
|
4484 | 4489 | File api = files.get("PathApi.java");
|
4485 | 4490 | File delegate = files.get("PathApiDelegate.java");
|
4486 | 4491 |
|
4487 | 4492 | JavaFileAssert.assertThat(api)
|
4488 |
| - .assertMethod("sseVariant1", "ServerWebExchange") |
4489 |
| - .isNotNull() |
4490 |
| - .hasReturnType("Flux<String>") |
4491 |
| - .toFileAssert() |
4492 |
| - .assertMethod("sseVariant2", "ServerWebExchange") |
4493 |
| - .isNotNull() |
4494 |
| - .hasReturnType("Flux<EventType>") |
4495 |
| - .toFileAssert() |
4496 |
| - .assertMethod("nonSSE", "ServerWebExchange") |
4497 |
| - .isNotNull() |
4498 |
| - .hasReturnType("Mono<ResponseEntity<String>>"); |
| 4493 | + .assertMethod("sse1", "ServerWebExchange") |
| 4494 | + .hasReturnType("Flux<String>") |
| 4495 | + .toFileAssert() |
| 4496 | + .assertMethod("sse2", "ServerWebExchange") |
| 4497 | + .hasReturnType("Flux<EventType>") |
| 4498 | + .toFileAssert() |
| 4499 | + // FIXME: Generator Crash |
| 4500 | + // .assertMethod("sse3", "ServerWebExchange") |
| 4501 | + // .hasReturnType("Flux<String>") |
| 4502 | + // .toFileAssert() |
| 4503 | + .assertMethod("sse4", "ServerWebExchange") |
| 4504 | + .hasReturnType("Flux<String>") |
| 4505 | + .toFileAssert() |
| 4506 | + // FIXME: Generator Crash, see #17271 |
| 4507 | + // .assertMethod("sse5", "ServerWebExchange") |
| 4508 | + // .hasReturnType("Flux<EventType>") |
| 4509 | + // .toFileAssert() |
| 4510 | + |
| 4511 | + // FIXME: Generator Crash |
| 4512 | + // .assertMethod("notSse1", "ServerWebExchange") |
| 4513 | + // .hasReturnType("Mono<ResponseEntity<Void>>") |
| 4514 | + // .toFileAssert() |
| 4515 | + // FIXME: Generator Crash |
| 4516 | + // .assertMethod("notSse2", "ServerWebExchange") |
| 4517 | + // .hasReturnType("Mono<ResponseEntity<Flux<String>>>") |
| 4518 | + // .toFileAssert() |
| 4519 | + .assertMethod("notSse3", "ServerWebExchange") |
| 4520 | + .hasReturnType("Mono<ResponseEntity<String>>") |
| 4521 | + .toFileAssert() |
| 4522 | + .assertMethod("notSse5", "ServerWebExchange") |
| 4523 | + .hasReturnType("Mono<ResponseEntity<Void>>") |
| 4524 | + .toFileAssert() |
| 4525 | + .assertMethod("notSse7", "ServerWebExchange") |
| 4526 | + .hasReturnType("Mono<ResponseEntity<String>>") |
| 4527 | + .toFileAssert() |
| 4528 | + // FIXME: Generator Crash |
| 4529 | + // .assertMethod("notSse8", "ServerWebExchange") |
| 4530 | + // .hasReturnType("Mono<ResponseEntity<String>>") |
| 4531 | + ; |
4499 | 4532 |
|
4500 | 4533 | JavaFileAssert.assertThat(delegate)
|
4501 |
| - .assertMethod("sseVariant1", "ServerWebExchange") |
4502 |
| - .isNotNull() |
4503 |
| - .hasReturnType("Flux<String>") |
4504 |
| - .bodyContainsLines("return Flux.empty();") |
4505 |
| - .toFileAssert() |
4506 |
| - .assertMethod("sseVariant2", "ServerWebExchange") |
4507 |
| - .isNotNull() |
4508 |
| - .hasReturnType("Flux<EventType>") |
4509 |
| - .bodyContainsLines("return Flux.empty();") |
4510 |
| - .toFileAssert() |
4511 |
| - .assertMethod("nonSSE", "ServerWebExchange") |
4512 |
| - .isNotNull() |
4513 |
| - .hasReturnType("Mono<ResponseEntity<String>>") |
4514 |
| - .bodyContainsLines("return result.then(Mono.empty());") |
| 4534 | + .assertMethod("sse1", "ServerWebExchange") |
| 4535 | + .hasReturnType("Flux<String>") |
| 4536 | + .bodyContainsLines("return Flux.empty();") |
| 4537 | + .toFileAssert() |
| 4538 | + .assertMethod("sse2", "ServerWebExchange") |
| 4539 | + .hasReturnType("Flux<EventType>") |
| 4540 | + .bodyContainsLines("return Flux.empty();") |
| 4541 | + .toFileAssert() |
| 4542 | + // FIXME: Generator Crash |
| 4543 | + // .assertMethod("sse3", "ServerWebExchange") |
| 4544 | + // .hasReturnType("Flux<String>") |
| 4545 | + // .bodyContainsLines("return Flux.empty();") |
| 4546 | + // .toFileAssert() |
| 4547 | + .assertMethod("sse4", "ServerWebExchange") |
| 4548 | + .hasReturnType("Flux<String>") |
| 4549 | + .bodyContainsLines("return Flux.empty();") |
| 4550 | + .toFileAssert() |
| 4551 | + // FIXME: Generator Crash |
| 4552 | + // .assertMethod("sse5", "ServerWebExchange") |
| 4553 | + // .hasReturnType("Flux<String>") |
| 4554 | + // .bodyContainsLines("return Flux.empty();") |
| 4555 | + // .toFileAssert() |
| 4556 | + |
| 4557 | + // FIXME: Generator Crash |
| 4558 | + // .assertMethod("notSse1", "ServerWebExchange") |
| 4559 | + // .hasReturnType("Mono<ResponseEntity<Void>>") |
| 4560 | + // .bodyContainsLines("return result.then(Mono.empty());") |
| 4561 | + // .toFileAssert() |
| 4562 | + // FIXME: Generator Crash |
| 4563 | + // .assertMethod("notSse2", "ServerWebExchange") |
| 4564 | + // .hasReturnType("Mono<ResponseEntity<Flux<String>>>") |
| 4565 | + // .bodyContainsLines("return result.then(Mono.empty());") |
| 4566 | + // .toFileAssert() |
| 4567 | + .assertMethod("notSse3", "ServerWebExchange") |
| 4568 | + .hasReturnType("Mono<ResponseEntity<String>>") |
| 4569 | + .bodyContainsLines("return result.then(Mono.empty());") |
| 4570 | + .toFileAssert() |
| 4571 | + .assertMethod("notSse5", "ServerWebExchange") |
| 4572 | + .hasReturnType("Mono<ResponseEntity<Void>>") |
| 4573 | + .bodyContainsLines("return result.then(Mono.empty());") |
| 4574 | + .toFileAssert() |
| 4575 | + .assertMethod("notSse7", "ServerWebExchange") |
| 4576 | + .hasReturnType("Mono<ResponseEntity<String>>") |
| 4577 | + .bodyContainsLines("return result.then(Mono.empty());") |
| 4578 | + .toFileAssert() |
| 4579 | + // FIXME: Generator Crash |
| 4580 | + // .assertMethod("notSse8", "ServerWebExchange") |
| 4581 | + // .hasReturnType("Mono<ResponseEntity<String>>") |
| 4582 | + // .bodyContainsLines("return result.then(Mono.empty());") |
4515 | 4583 | ;
|
4516 | 4584 |
|
4517 | 4585 | }
|
4518 | 4586 |
|
| 4587 | + @DataProvider(name = "invalid sse endpoints") |
| 4588 | + public static Object[][] specsWithInvalidSSEEndpoints() { |
| 4589 | + return new Object[][] { |
| 4590 | + {"sse_but_missing_format.yaml", "schema format 'event-stream' is required, when SSE is detected"}, |
| 4591 | + // FIXME: spec does not generate correct code, but not detected |
| 4592 | + // {"sse_but_multiple_media_types.yaml", "only 1 response media type supported, when SSE is detected"}, |
| 4593 | + {"sse_but_incompatible_item_types.yaml", "only single item type is supported, when SSE is detected"} |
| 4594 | + }; |
| 4595 | + } |
| 4596 | + |
| 4597 | + @Test(dataProvider = "invalid sse endpoints") |
| 4598 | + public void testSSEOperationSupport_forInvalidSSEEndpointSpecs(String inputSpec, String expectedError) { |
| 4599 | + // checks the design decision, that if the specs looks like it should be an SSE endpoint but it is not |
| 4600 | + // matching the required format, an exception is thrown containing a descriptive error message |
| 4601 | + Map<String, Object> additionalProperties = Map.of( |
| 4602 | + SSE, true, |
| 4603 | + REACTIVE, "true", |
| 4604 | + INTERFACE_ONLY, "false", |
| 4605 | + DELEGATE_PATTERN, "true" |
| 4606 | + ); |
| 4607 | + String input = "src/test/resources/3_0/" + inputSpec; |
| 4608 | + assertThatThrownBy(() -> generateFromContract(input, "spring-boot", additionalProperties)) |
| 4609 | + .rootCause() |
| 4610 | + .isInstanceOf(RuntimeException.class) |
| 4611 | + .hasMessage(expectedError); |
| 4612 | + } |
| 4613 | + |
4519 | 4614 | @Test
|
4520 | 4615 | public void givenMultipartForm_whenGenerateReactiveServer_thenParameterAreCreatedAsRequestPart() throws IOException {
|
4521 | 4616 | File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
|
|
0 commit comments