Adding some tests for PR 1051

This commit is contained in:
Andrew B 2015-08-06 15:22:18 -07:00
parent c67a6582fc
commit 7a92f53b55

View File

@ -31,4 +31,55 @@ class JavaModelEnumTest extends FlatSpec with Matchers {
enumVar.baseType should be("String")
enumVar.isEnum should equal(true)
}
it should "not override identical parent enums" in {
val identicalEnumProperty = new StringProperty()
identicalEnumProperty.setEnum(List("VALUE1", "VALUE2", "VALUE3").asJava)
val subEnumProperty = new StringProperty()
subEnumProperty.setEnum(List("SUB1", "SUB2", "SUB3").asJava)
// Add one enum ptoperty to the parent
val parentProperties = new java.util.HashMap[String, Property]()
parentProperties.put("sharedThing", identicalEnumProperty)
// Add TWO enums to the subType model; one of which is identical to the one in parent class
val subProperties = new java.util.HashMap[String, Property]()
subProperties.put("sharedThing", identicalEnumProperty)
subProperties.put("unsharedThing", identicalEnumProperty)
val parentModel = new ModelImpl();
parentModel.setProperties(parentProperties);
parentModel.name("parentModel");
val subModel = new ModelImpl();
subModel.setProperties(subProperties);
subModel.name("subModel");
val model = new ComposedModel()
.parent(new RefModel(parentModel.getName()))
.child(subModel)
.interfaces(new java.util.ArrayList[RefModel]())
val codegen = new JavaClientCodegen()
val allModels = new java.util.HashMap[String, Model]()
allModels.put(codegen.toModelName(parentModel.getName()), parentModel)
allModels.put(codegen.toModelName(subModel.getName()), subModel)
val cm = codegen.fromModel("sample", model, allModels)
cm.name should be("sample")
cm.classname should be("Sample")
cm.parent should be("ParentModel")
cm.imports.asScala should be(Set("ParentModel"))
// Assert that only the unshared/uninherited enum remains
cm.vars.size should be (1)
val enumVar = cm.vars.get(0)
enumVar.baseName should be("unsharedThing")
enumVar.datatype should be("String")
enumVar.datatypeWithEnum should be("UnsharedThingEnum")
enumVar.isEnum should equal(true)
}
}