From 3f9d1b1fec11390087f937b15d8b701f4c536505 Mon Sep 17 00:00:00 2001 From: sullis Date: Mon, 16 Sep 2019 10:05:44 -0700 Subject: [PATCH] ScalaAkkaClientCodegenTest: refactor assertions (#3893) --- .../scalaakka/ScalaAkkaClientCodegenTest.java | 28 ++--------- .../resources/codegen/scala/SomeObj.scala.txt | 50 +++++++++++++++++++ 2 files changed, 55 insertions(+), 23 deletions(-) create mode 100644 modules/openapi-generator/src/test/resources/codegen/scala/SomeObj.scala.txt diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/scalaakka/ScalaAkkaClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/scalaakka/ScalaAkkaClientCodegenTest.java index 40dd7b39253a..9d3c52649864 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/scalaakka/ScalaAkkaClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/scalaakka/ScalaAkkaClientCodegenTest.java @@ -18,6 +18,7 @@ package org.openapitools.codegen.scalaakka; import com.google.common.collect.Sets; +import com.google.common.io.Resources; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.media.*; import io.swagger.v3.parser.util.SchemaTypeUtil; @@ -28,6 +29,7 @@ import org.testng.annotations.Test; import java.io.File; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.HashMap; import java.util.Map; @@ -303,28 +305,8 @@ public void codeGenerationTest() throws Exception { Assert.assertEquals(generatedFiles.size(), 13); final String someObjFilename = new File(output, "src/main/scala/hello/world/model/SomeObj.scala").getAbsolutePath().replace("\\", "/"); - final String someObjFileContents = generatedFiles.get(someObjFilename); - Assert.assertTrue(someObjFileContents.contains("package hello.world.model")); - Assert.assertTrue(someObjFileContents.contains("case class SomeObj")); - Assert.assertTrue(someObjFileContents.contains("id: Long,")); - Assert.assertTrue(someObjFileContents.contains("name: Option[String] = None,")); - Assert.assertTrue(someObjFileContents.contains("`val`: Option[String] = None,")); - Assert.assertTrue(someObjFileContents.contains("`var`: Option[String] = None,")); - Assert.assertTrue(someObjFileContents.contains("`class`: Option[String] = None,")); - Assert.assertTrue(someObjFileContents.contains("`trait`: Option[String] = None,")); - Assert.assertTrue(someObjFileContents.contains("`object`: Option[String] = None,")); - Assert.assertTrue(someObjFileContents.contains("`try`: String,")); - Assert.assertTrue(someObjFileContents.contains("`catch`: String,")); - Assert.assertTrue(someObjFileContents.contains("`finally`: String,")); - Assert.assertTrue(someObjFileContents.contains("`def`: Option[String] = None,")); - Assert.assertTrue(someObjFileContents.contains("`for`: Option[String] = None,")); - Assert.assertTrue(someObjFileContents.contains("`implicit`: Option[String] = None,")); - Assert.assertTrue(someObjFileContents.contains("`match`: Option[String] = None,")); - Assert.assertTrue(someObjFileContents.contains("`case`: Option[String] = None,")); - Assert.assertTrue(someObjFileContents.contains("`import`: Option[String] = None,")); - Assert.assertTrue(someObjFileContents.contains("`lazy`: String,")); - Assert.assertTrue(someObjFileContents.contains("`private`: Option[String] = None,")); - Assert.assertTrue(someObjFileContents.contains("`type`: Option[String] = None,")); - Assert.assertTrue(someObjFileContents.contains("foobar: Boolean")); + Assert.assertEquals( + generatedFiles.get(someObjFilename), + Resources.toString(Resources.getResource("codegen/scala/SomeObj.scala.txt"), StandardCharsets.UTF_8)); } } diff --git a/modules/openapi-generator/src/test/resources/codegen/scala/SomeObj.scala.txt b/modules/openapi-generator/src/test/resources/codegen/scala/SomeObj.scala.txt new file mode 100644 index 000000000000..0a055fed673b --- /dev/null +++ b/modules/openapi-generator/src/test/resources/codegen/scala/SomeObj.scala.txt @@ -0,0 +1,50 @@ +/** + * ping some object + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +package hello.world.model + +import hello.world.core.ApiModel +import org.joda.time.DateTime +import java.util.UUID + +case class SomeObj ( + `type`: Option[SomeObjEnums.`Type`] = None, + id: Long, + name: Option[String] = None, + `val`: Option[String] = None, + `var`: Option[String] = None, + `class`: Option[String] = None, + `trait`: Option[String] = None, + `object`: Option[String] = None, + `try`: String, + `catch`: String, + `finally`: String, + `def`: Option[String] = None, + `for`: Option[String] = None, + `implicit`: Option[String] = None, + `match`: Option[String] = None, + `case`: Option[String] = None, + `import`: Option[String] = None, + `lazy`: String, + `private`: Option[String] = None, + `type`: Option[String] = None, + foobar: Boolean +) extends ApiModel + +object SomeObjEnums { + + type `Type` = `Type`.Value + object `Type` extends Enumeration { + val SomeObjIdentifier = Value("SomeObjIdentifier") + } + +} +