Skip to content

Commit 3ed53dd

Browse files
committed
add unit tests covering both reactive and non-reactive
1 parent 816c009 commit 3ed53dd

1 file changed

Lines changed: 153 additions & 2 deletions

File tree

modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java

Lines changed: 153 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,6 @@ public void generateHttpInterfaceReactiveWithReactor() throws Exception {
11841184
);
11851185
}
11861186

1187-
11881187
@Test
11891188
public void generateHttpInterfaceReactiveWithCoroutines() throws Exception {
11901189
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
@@ -1383,7 +1382,12 @@ private void verifyGeneratedFilesContain(Map<Path, List<String>> expectedSnippet
13831382
for (var expectedSnippetsByPathToFile : expectedSnippetsByPathsToFiles.entrySet()) {
13841383
assertFileContains(expectedSnippetsByPathToFile.getKey(), expectedSnippetsByPathToFile.getValue().toArray(new String[0]));
13851384
}
1385+
}
13861386

1387+
private void verifyGeneratedFilesNotContain(Map<Path, List<String>> unexpectedSnippetsByPathsToFiles) {
1388+
for (var unexpectedSnippetsByPathToFile : unexpectedSnippetsByPathsToFiles.entrySet()) {
1389+
assertFileNotContains(unexpectedSnippetsByPathToFile.getKey(), unexpectedSnippetsByPathToFile.getValue().toArray(new String[0]));
1390+
}
13871391
}
13881392

13891393
@Test
@@ -1825,7 +1829,6 @@ public void nonReactiveWithHttpRequestContextControllerImplAnnotationNoneNoDeleg
18251829
);
18261830
}
18271831

1828-
18291832
@Test
18301833
public void reactiveWithHttpRequestContextControllerImplAnnotationNoneNoDelegateWithApiTests() throws Exception {
18311834
Path root = generateApiSources(Map.of(
@@ -2399,6 +2402,154 @@ public void nonReactiveWithoutHttpRequestContextInterfaceOnlyAnnotationNoneDeleg
23992402
);
24002403
}
24012404

2405+
@Test
2406+
public void reactiveWithoutResponseEntity() throws Exception {
2407+
Path root = generateApiSources(Map.of(
2408+
KotlinSpringServerCodegen.REACTIVE, true,
2409+
KotlinSpringServerCodegen.DOCUMENTATION_PROVIDER, "none",
2410+
KotlinSpringServerCodegen.ANNOTATION_LIBRARY, "none",
2411+
KotlinSpringServerCodegen.INTERFACE_ONLY, true,
2412+
KotlinSpringServerCodegen.USE_RESPONSE_ENTITY, false
2413+
), Map.of(
2414+
CodegenConstants.MODELS, "false",
2415+
CodegenConstants.MODEL_TESTS, "false",
2416+
CodegenConstants.MODEL_DOCS, "false",
2417+
CodegenConstants.APIS, "true",
2418+
CodegenConstants.SUPPORTING_FILES, "false"
2419+
));
2420+
verifyGeneratedFilesContain(
2421+
Map.of(
2422+
root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of(
2423+
"@ResponseStatus(HttpStatus.BAD_REQUEST)",
2424+
"suspend fun deletePet( @PathVariable(\"petId\") petId: kotlin.Long, @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?): Unit",
2425+
"@ResponseStatus(HttpStatus.OK)",
2426+
"suspend fun getPetById( @PathVariable(\"petId\") petId: kotlin.Long): Pet"),
2427+
root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of(
2428+
"@ResponseStatus(HttpStatus.OK)",
2429+
"suspend fun logoutUser(): Unit"
2430+
),
2431+
root.resolve("src/main/kotlin/org/openapitools/api/StoreApi.kt"), List.of(
2432+
"@ResponseStatus(HttpStatus.OK)",
2433+
"suspend fun getInventory(): Map<String, kotlin.Int>")
2434+
)
2435+
);
2436+
}
2437+
2438+
@Test
2439+
public void nonReactiveWithoutResponseEntity() throws Exception {
2440+
Path root = generateApiSources(Map.of(
2441+
KotlinSpringServerCodegen.REACTIVE, false,
2442+
KotlinSpringServerCodegen.DOCUMENTATION_PROVIDER, "none",
2443+
KotlinSpringServerCodegen.ANNOTATION_LIBRARY, "none",
2444+
KotlinSpringServerCodegen.INTERFACE_ONLY, true,
2445+
KotlinSpringServerCodegen.USE_RESPONSE_ENTITY, false
2446+
), Map.of(
2447+
CodegenConstants.MODELS, "false",
2448+
CodegenConstants.MODEL_TESTS, "false",
2449+
CodegenConstants.MODEL_DOCS, "false",
2450+
CodegenConstants.APIS, "true",
2451+
CodegenConstants.SUPPORTING_FILES, "false"
2452+
));
2453+
verifyGeneratedFilesContain(
2454+
Map.of(
2455+
root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of(
2456+
"@ResponseStatus(HttpStatus.BAD_REQUEST)",
2457+
"fun deletePet( @PathVariable(\"petId\") petId: kotlin.Long, @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?): Unit",
2458+
"@ResponseStatus(HttpStatus.OK)",
2459+
"fun getPetById( @PathVariable(\"petId\") petId: kotlin.Long): Pet"),
2460+
root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of(
2461+
"@ResponseStatus(HttpStatus.OK)",
2462+
"fun logoutUser(): Unit"
2463+
),
2464+
root.resolve("src/main/kotlin/org/openapitools/api/StoreApi.kt"), List.of(
2465+
"@ResponseStatus(HttpStatus.OK)",
2466+
"fun getInventory(): Map<String, kotlin.Int>")
2467+
)
2468+
);
2469+
2470+
verifyGeneratedFilesNotContain(
2471+
Map.of(
2472+
root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of("suspend"),
2473+
root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of("suspend"),
2474+
root.resolve("src/main/kotlin/org/openapitools/api/StoreApi.kt"), List.of("suspend")
2475+
)
2476+
);
2477+
}
2478+
2479+
@Test
2480+
public void reactiveWithResponseEntity() throws Exception {
2481+
Path root = generateApiSources(Map.of(
2482+
KotlinSpringServerCodegen.REACTIVE, true,
2483+
KotlinSpringServerCodegen.DOCUMENTATION_PROVIDER, "none",
2484+
KotlinSpringServerCodegen.ANNOTATION_LIBRARY, "none",
2485+
KotlinSpringServerCodegen.INTERFACE_ONLY, true,
2486+
KotlinSpringServerCodegen.USE_RESPONSE_ENTITY, true
2487+
), Map.of(
2488+
CodegenConstants.MODELS, "false",
2489+
CodegenConstants.MODEL_TESTS, "false",
2490+
CodegenConstants.MODEL_DOCS, "false",
2491+
CodegenConstants.APIS, "true",
2492+
CodegenConstants.SUPPORTING_FILES, "false"
2493+
));
2494+
verifyGeneratedFilesContain(
2495+
Map.of(
2496+
root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of(
2497+
"suspend fun deletePet( @PathVariable(\"petId\") petId: kotlin.Long, @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?): ResponseEntity<Unit>",
2498+
"suspend fun getPetById( @PathVariable(\"petId\") petId: kotlin.Long): ResponseEntity<Pet>"),
2499+
root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of(
2500+
"suspend fun logoutUser(): ResponseEntity<Unit>"
2501+
),
2502+
root.resolve("src/main/kotlin/org/openapitools/api/StoreApi.kt"), List.of(
2503+
"suspend fun getInventory(): ResponseEntity<Map<String, kotlin.Int>>")
2504+
)
2505+
);
2506+
2507+
verifyGeneratedFilesNotContain(
2508+
Map.of(
2509+
root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of("@ResponseStatus(HttpStatus."),
2510+
root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of("@ResponseStatus(HttpStatus."),
2511+
root.resolve("src/main/kotlin/org/openapitools/api/StoreApi.kt"), List.of("@ResponseStatus(HttpStatus.")
2512+
)
2513+
);
2514+
}
2515+
2516+
@Test
2517+
public void nonReactiveWithResponseEntity() throws Exception {
2518+
Path root = generateApiSources(Map.of(
2519+
KotlinSpringServerCodegen.REACTIVE, false,
2520+
KotlinSpringServerCodegen.DOCUMENTATION_PROVIDER, "none",
2521+
KotlinSpringServerCodegen.ANNOTATION_LIBRARY, "none",
2522+
KotlinSpringServerCodegen.INTERFACE_ONLY, true,
2523+
KotlinSpringServerCodegen.USE_RESPONSE_ENTITY, true
2524+
), Map.of(
2525+
CodegenConstants.MODELS, "false",
2526+
CodegenConstants.MODEL_TESTS, "false",
2527+
CodegenConstants.MODEL_DOCS, "false",
2528+
CodegenConstants.APIS, "true",
2529+
CodegenConstants.SUPPORTING_FILES, "false"
2530+
));
2531+
verifyGeneratedFilesContain(
2532+
Map.of(
2533+
root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of(
2534+
"fun deletePet( @PathVariable(\"petId\") petId: kotlin.Long, @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?): ResponseEntity<Unit>",
2535+
"fun getPetById( @PathVariable(\"petId\") petId: kotlin.Long): ResponseEntity<Pet>"),
2536+
root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of(
2537+
"fun logoutUser(): ResponseEntity<Unit>"
2538+
),
2539+
root.resolve("src/main/kotlin/org/openapitools/api/StoreApi.kt"), List.of(
2540+
"fun getInventory(): ResponseEntity<Map<String, kotlin.Int>>")
2541+
)
2542+
);
2543+
2544+
verifyGeneratedFilesNotContain(
2545+
Map.of(
2546+
root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of("suspend", "@ResponseStatus(HttpStatus."),
2547+
root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of("suspend", "@ResponseStatus(HttpStatus."),
2548+
root.resolve("src/main/kotlin/org/openapitools/api/StoreApi.kt"), List.of("suspend", "@ResponseStatus(HttpStatus.")
2549+
)
2550+
);
2551+
}
2552+
24022553
@Test
24032554
public void reactiveWithoutFlow() throws Exception {
24042555
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();

0 commit comments

Comments
 (0)