|
1 | 1 | package org.openapitools.codegen.java.jaxrs;
|
2 | 2 |
|
| 3 | +import io.swagger.parser.OpenAPIParser; |
3 | 4 | import io.swagger.v3.oas.models.OpenAPI;
|
4 | 5 | import io.swagger.v3.oas.models.servers.Server;
|
| 6 | +import io.swagger.v3.oas.models.Operation; |
| 7 | +import io.swagger.v3.oas.models.info.Info; |
| 8 | +import io.swagger.v3.oas.models.media.Schema; |
| 9 | +import io.swagger.v3.parser.core.models.ParseOptions; |
| 10 | + |
5 | 11 | import org.openapitools.codegen.ClientOptInput;
|
6 | 12 | import org.openapitools.codegen.CodegenConstants;
|
7 | 13 | import org.openapitools.codegen.CodegenOperation;
|
| 14 | +import org.openapitools.codegen.DefaultCodegen; |
8 | 15 | import org.openapitools.codegen.MockDefaultGenerator;
|
9 | 16 | import org.openapitools.codegen.MockDefaultGenerator.WrittenTemplateBasedFile;
|
10 | 17 | import org.openapitools.codegen.TestUtils;
|
11 | 18 | import org.openapitools.codegen.languages.JavaJerseyServerCodegen;
|
| 19 | +import org.openapitools.codegen.languages.features.CXFServerFeatures; |
12 | 20 | import org.openapitools.codegen.templating.MustacheEngineAdapter;
|
| 21 | +import org.openapitools.codegen.DefaultGenerator; |
13 | 22 | import org.testng.Assert;
|
14 | 23 | import org.testng.annotations.BeforeMethod;
|
15 | 24 | import org.testng.annotations.Test;
|
16 | 25 |
|
| 26 | +import static org.openapitools.codegen.TestUtils.assertFileContains; |
| 27 | + |
17 | 28 | import java.io.File;
|
| 29 | +import java.io.IOException; |
18 | 30 | import java.nio.file.Files;
|
19 | 31 | import java.util.List;
|
20 | 32 | import java.util.Map;
|
| 33 | +import java.util.stream.Collectors; |
21 | 34 |
|
22 | 35 | public class JavaJerseyServerCodegenTest extends JavaJaxrsBaseTest {
|
23 | 36 |
|
@@ -87,4 +100,46 @@ public void testAdditionalPropertiesPutForConfigValues() throws Exception {
|
87 | 100 | Assert.assertEquals(codegen.additionalProperties().get(JavaJerseyServerCodegen.SERVER_PORT), "8088");
|
88 | 101 | }
|
89 | 102 |
|
| 103 | + // Helper function, intended to reduce boilerplate @ copied from ../spring/SpringCodegenTest.java |
| 104 | + private Map<String, File> generateFiles(DefaultCodegen codegen, String filePath) throws IOException { |
| 105 | + final File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); |
| 106 | + output.deleteOnExit(); |
| 107 | + final String outputPath = output.getAbsolutePath().replace('\\', '/'); |
| 108 | + |
| 109 | + codegen.setOutputDir(output.getAbsolutePath()); |
| 110 | + codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true"); |
| 111 | + |
| 112 | + final ClientOptInput input = new ClientOptInput(); |
| 113 | + final OpenAPI openAPI = new OpenAPIParser().readLocation(filePath, null, new ParseOptions()).getOpenAPI(); |
| 114 | + input.openAPI(openAPI); |
| 115 | + input.config(codegen); |
| 116 | + |
| 117 | + final DefaultGenerator generator = new DefaultGenerator(); |
| 118 | + List<File> files = generator.opts(input).generate(); |
| 119 | + |
| 120 | + return files.stream().collect(Collectors.toMap(e -> e.getName().replace(outputPath, ""), i -> i)); |
| 121 | + } |
| 122 | + |
| 123 | + // almost same test as issue #3139 on Spring |
| 124 | + @Test |
| 125 | + public void testMultipartJerseyServer() throws Exception { |
| 126 | + |
| 127 | + final Map<String, File> files = generateFiles(codegen, "src/test/resources/3_0/form-multipart-binary-array.yaml"); |
| 128 | + |
| 129 | + // Check files for Single, Mixed |
| 130 | + String[] fileS = new String[] { |
| 131 | + "MultipartSingleApi.java", "MultipartSingleApiService.java", "MultipartSingleApiServiceImpl.java", |
| 132 | + "MultipartMixedApi.java", "MultipartMixedApiService.java", "MultipartMixedApiServiceImpl.java" }; |
| 133 | + for (String f : fileS){ |
| 134 | + assertFileContains( files.get(f).toPath(), "FormDataBodyPart file" ); |
| 135 | + } |
| 136 | + |
| 137 | + // Check files for Array |
| 138 | + final String[] fileA = new String[] { "MultipartArrayApiService.java", "MultipartArrayApi.java", "MultipartArrayApiServiceImpl.java"}; |
| 139 | + for (String f : fileA) { |
| 140 | + assertFileContains( files.get(f).toPath(), "List<FormDataBodyPart> files"); |
| 141 | + } |
| 142 | + |
| 143 | + } |
| 144 | + |
90 | 145 | }
|
0 commit comments