forked from loafle/openapi-generator-original
[JavaScript] add enum tests cases for JS generator (java) (#3546)
* add enum tests cases for JS generator (java) * fix typo quote
This commit is contained in:
@@ -11,6 +11,8 @@ import io.swagger.models.ModelImpl;
|
||||
import io.swagger.models.RefModel;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.properties.StringProperty;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.parser.SwaggerParser;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@@ -92,4 +94,61 @@ public class JavaScriptModelEnumTest {
|
||||
Assert.assertEquals(enumVar.datatypeWithEnum, "UnsharedThingEnum");
|
||||
Assert.assertTrue(enumVar.isEnum);
|
||||
}
|
||||
|
||||
@Test(description = "test enum array model")
|
||||
public void enumArrayMdoelTest() {
|
||||
final Swagger model = new SwaggerParser().read("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml");
|
||||
final DefaultCodegen codegen = new JavascriptClientCodegen();
|
||||
final Model definition = model.getDefinitions().get("EnumArrays");
|
||||
|
||||
Property property = definition.getProperties().get("array_enum");
|
||||
CodegenProperty prope = codegen.fromProperty("array_enum", property);
|
||||
codegen.updateCodegenPropertyEnum(prope);
|
||||
Assert.assertEquals(prope.datatypeWithEnum, "[ArrayEnumEnum]");
|
||||
Assert.assertEquals(prope.enumName, "ArrayEnumEnum");
|
||||
Assert.assertTrue(prope.isEnum);
|
||||
Assert.assertEquals(prope.allowableValues.get("values"), Arrays.asList("fish", "crab"));
|
||||
|
||||
HashMap<String, String> fish= new HashMap<String, String>();
|
||||
fish.put("name", "fish");
|
||||
fish.put("value", "\"fish\"");
|
||||
HashMap<String, String> crab= new HashMap<String, String>();
|
||||
crab.put("name", "crab");
|
||||
crab.put("value", "\"crab\"");
|
||||
Assert.assertEquals(prope.allowableValues.get("enumVars"), Arrays.asList(fish, crab));
|
||||
|
||||
// assert inner items
|
||||
Assert.assertEquals(prope.datatypeWithEnum, "[ArrayEnumEnum]");
|
||||
Assert.assertEquals(prope.enumName, "ArrayEnumEnum");
|
||||
Assert.assertTrue(prope.items.isEnum);
|
||||
Assert.assertEquals(prope.items.allowableValues.get("values"), Arrays.asList("fish", "crab"));
|
||||
Assert.assertEquals(prope.items.allowableValues.get("enumVars"), Arrays.asList(fish, crab));
|
||||
|
||||
}
|
||||
|
||||
@Test(description = "test enum model for values (numeric, string, etc)")
|
||||
public void enumMdoelValueTest() {
|
||||
final Swagger model = new SwaggerParser().read("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml");
|
||||
final DefaultCodegen codegen = new JavascriptClientCodegen();
|
||||
final Model definition = model.getDefinitions().get("Enum_Test");
|
||||
|
||||
Property property = definition.getProperties().get("enum_integer");
|
||||
CodegenProperty prope = codegen.fromProperty("enum_integer", property);
|
||||
codegen.updateCodegenPropertyEnum(prope);
|
||||
Assert.assertEquals(prope.datatypeWithEnum, "EnumIntegerEnum");
|
||||
Assert.assertEquals(prope.enumName, "EnumIntegerEnum");
|
||||
Assert.assertTrue(prope.isEnum);
|
||||
Assert.assertNull(prope.isContainer);
|
||||
Assert.assertNull(prope.items);
|
||||
Assert.assertEquals(prope.allowableValues.get("values"), Arrays.asList(1, -1));
|
||||
|
||||
HashMap<String, String> one = new HashMap<String, String>();
|
||||
one.put("name", "1");
|
||||
one.put("value", "1");
|
||||
HashMap<String, String> minusOne = new HashMap<String, String>();
|
||||
minusOne.put("name", "-1");
|
||||
minusOne.put("value", "-1");
|
||||
Assert.assertEquals(prope.allowableValues.get("enumVars"), Arrays.asList(one, minusOne));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user