|
21 | 21 | import io.swagger.v3.oas.models.OpenAPI;
|
22 | 22 | import io.swagger.v3.oas.models.media.*;
|
23 | 23 | import io.swagger.v3.parser.util.SchemaTypeUtil;
|
24 |
| -import org.openapitools.codegen.CodegenModel; |
25 |
| -import org.openapitools.codegen.CodegenProperty; |
26 |
| -import org.openapitools.codegen.DefaultCodegen; |
27 |
| -import org.openapitools.codegen.TestUtils; |
| 24 | +import org.openapitools.codegen.*; |
| 25 | +import org.openapitools.codegen.config.CodegenConfigurator; |
28 | 26 | import org.openapitools.codegen.languages.ScalaAkkaClientCodegen;
|
29 | 27 | import org.testng.Assert;
|
30 | 28 | import org.testng.annotations.Test;
|
31 | 29 |
|
| 30 | +import java.io.File; |
| 31 | +import java.nio.file.Files; |
| 32 | +import java.util.HashMap; |
| 33 | +import java.util.Map; |
| 34 | + |
32 | 35 | public class ScalaAkkaClientCodegenTest {
|
33 | 36 |
|
34 | 37 | private ScalaAkkaClientCodegen scalaAkkaClientCodegen;
|
@@ -276,4 +279,52 @@ public void mapModelTest() {
|
276 | 279 | Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("Map", "Children")).size(), 1);
|
277 | 280 | }
|
278 | 281 |
|
| 282 | + @Test(description = "validate codegen output") |
| 283 | + public void codeGenerationTest() throws Exception { |
| 284 | + Map<String, Object> properties = new HashMap<>(); |
| 285 | + properties.put("mainPackage", "hello.world"); |
| 286 | + |
| 287 | + File output = Files.createTempDirectory("test").toFile(); |
| 288 | + output.deleteOnExit(); |
| 289 | + |
| 290 | + final DefaultCodegen codegen = new ScalaAkkaClientCodegen(); |
| 291 | + |
| 292 | + final CodegenConfigurator configurator = new CodegenConfigurator() |
| 293 | + .setGeneratorName(codegen.getName()) |
| 294 | + .setAdditionalProperties(properties) |
| 295 | + .setInputSpec("src/test/resources/3_0/scala_reserved_words.yaml") |
| 296 | + .setOutputDir(output.getAbsolutePath().replace("\\", "/")); |
| 297 | + |
| 298 | + final ClientOptInput clientOptInput = configurator.toClientOptInput(); |
| 299 | + MockDefaultGenerator generator = new MockDefaultGenerator(); |
| 300 | + generator.opts(clientOptInput).generate(); |
| 301 | + |
| 302 | + Map<String, String> generatedFiles = generator.getFiles(); |
| 303 | + Assert.assertEquals(generatedFiles.size(), 13); |
| 304 | + |
| 305 | + final String someObjFilename = new File(output, "src/main/scala/hello/world/model/SomeObj.scala").getAbsolutePath().replace("\\", "/"); |
| 306 | + final String someObjFileContents = generatedFiles.get(someObjFilename); |
| 307 | + Assert.assertTrue(someObjFileContents.contains("package hello.world.model")); |
| 308 | + Assert.assertTrue(someObjFileContents.contains("case class SomeObj")); |
| 309 | + Assert.assertTrue(someObjFileContents.contains("id: Long,")); |
| 310 | + Assert.assertTrue(someObjFileContents.contains("name: Option[String] = None,")); |
| 311 | + Assert.assertTrue(someObjFileContents.contains("`val`: Option[String] = None,")); |
| 312 | + Assert.assertTrue(someObjFileContents.contains("`var`: Option[String] = None,")); |
| 313 | + Assert.assertTrue(someObjFileContents.contains("`class`: Option[String] = None,")); |
| 314 | + Assert.assertTrue(someObjFileContents.contains("`trait`: Option[String] = None,")); |
| 315 | + Assert.assertTrue(someObjFileContents.contains("`object`: Option[String] = None,")); |
| 316 | + Assert.assertTrue(someObjFileContents.contains("`try`: String,")); |
| 317 | + Assert.assertTrue(someObjFileContents.contains("`catch`: String,")); |
| 318 | + Assert.assertTrue(someObjFileContents.contains("`finally`: String,")); |
| 319 | + Assert.assertTrue(someObjFileContents.contains("`def`: Option[String] = None,")); |
| 320 | + Assert.assertTrue(someObjFileContents.contains("`for`: Option[String] = None,")); |
| 321 | + Assert.assertTrue(someObjFileContents.contains("`implicit`: Option[String] = None,")); |
| 322 | + Assert.assertTrue(someObjFileContents.contains("`match`: Option[String] = None,")); |
| 323 | + Assert.assertTrue(someObjFileContents.contains("`case`: Option[String] = None,")); |
| 324 | + Assert.assertTrue(someObjFileContents.contains("`import`: Option[String] = None,")); |
| 325 | + Assert.assertTrue(someObjFileContents.contains("`lazy`: String,")); |
| 326 | + Assert.assertTrue(someObjFileContents.contains("`private`: Option[String] = None,")); |
| 327 | + Assert.assertTrue(someObjFileContents.contains("`type`: Option[String] = None,")); |
| 328 | + Assert.assertTrue(someObjFileContents.contains("foobar: Boolean")); |
| 329 | + } |
279 | 330 | }
|
0 commit comments