From d4d08c322ed4bbaa5eb4e46901bfafcdd81ff3c7 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Wed, 12 Mar 2014 11:45:13 -0700 Subject: [PATCH] added tests --- .../converter/PropertyAnnotationTest.scala | 45 +++++++++++++++++++ .../models/ModelWithAnnotationOnProperty.java | 17 +++++++ 2 files changed, 62 insertions(+) create mode 100644 modules/swagger-core/src/test/scala/converter/PropertyAnnotationTest.scala create mode 100644 modules/swagger-core/src/test/scala/converter/models/ModelWithAnnotationOnProperty.java diff --git a/modules/swagger-core/src/test/scala/converter/PropertyAnnotationTest.scala b/modules/swagger-core/src/test/scala/converter/PropertyAnnotationTest.scala new file mode 100644 index 0000000000..3d868376bc --- /dev/null +++ b/modules/swagger-core/src/test/scala/converter/PropertyAnnotationTest.scala @@ -0,0 +1,45 @@ +package converter + +import converter.models._ + +import com.wordnik.swagger.converter._ +import com.wordnik.swagger.model._ + +import com.wordnik.swagger.annotations._ +import com.wordnik.swagger.converter._ +import com.wordnik.swagger.core.util._ +import com.wordnik.swagger.model._ + +import scala.reflect.BeanProperty +import scala.collection.mutable.LinkedHashMap + +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner +import org.scalatest.FlatSpec +import org.scalatest.matchers.ShouldMatchers + +import javax.xml.bind.annotation._ + +@RunWith(classOf[JUnitRunner]) +class PropertyAnnotationTest extends FlatSpec with ShouldMatchers { + it should "read annotations on a property" in { + val a = ModelConverters.readAll(classOf[ModelWithAnnotationOnProperty]) + JsonSerializer.asJson(a) should be ("""[{"id":"ModelWithAnnotationOnProperty","description":"my annotated model","properties":{"count":{"type":"integer","format":"int32","description":"the count of items"}}}]""") + +/* +[ + { + "id": "ModelWithAnnotationOnProperty", + "description": "my annotated model", + "properties": { + "count": { + "type": "integer", + "format": "int32", + "description": "the count of items" + } + } + } +] +*/ + } +} diff --git a/modules/swagger-core/src/test/scala/converter/models/ModelWithAnnotationOnProperty.java b/modules/swagger-core/src/test/scala/converter/models/ModelWithAnnotationOnProperty.java new file mode 100644 index 0000000000..a3448ec88e --- /dev/null +++ b/modules/swagger-core/src/test/scala/converter/models/ModelWithAnnotationOnProperty.java @@ -0,0 +1,17 @@ +package converter.models; + +import com.wordnik.swagger.annotations.*; + +@ApiModel(description = "my annotated model") +public class ModelWithAnnotationOnProperty { + @ApiModelProperty(value = "the count of items", position = 1) + private Integer count; + + public void setCount(Integer count) { + this.count = count; + } + + public Integer getCount() { + return count; + } +}