added tests

This commit is contained in:
Tony Tam
2015-12-29 23:44:15 -08:00
parent 29f928d644
commit 405e09a057
3 changed files with 73 additions and 1 deletions

View File

@@ -0,0 +1,36 @@
package io.swagger.codegen.jaxrs;
import io.swagger.codegen.CodegenModel;
import io.swagger.codegen.languages.JaxRSServerCodegen;
import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
import io.swagger.models.properties.DateProperty;
import io.swagger.models.properties.DateTimeProperty;
import io.swagger.models.properties.LongProperty;
import io.swagger.util.Json;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
public class JaxrsJava8ModelTest {
@Test(description = "convert a simple java model with java8 types")
public void simpleModelTest() {
final Model model = new ModelImpl()
.description("a sample model")
.property("id", new LongProperty())
.property("theDate", new DateProperty())
.property("createdAt", new DateTimeProperty())
.required("id")
.required("name");
final JaxRSServerCodegen codegen = new JaxRSServerCodegen();
codegen.setDateLibrary("java8");
codegen.processOpts();
final CodegenModel cm = codegen.fromModel("sample", model);
Json.prettyPrint(cm);
assertEquals(cm.vars.get(0).datatype, "Long");
assertEquals(cm.vars.get(1).datatype, "LocalDate");
assertEquals(cm.vars.get(2).datatype, "LocalDateTime");
}
}

View File

@@ -0,0 +1,36 @@
package io.swagger.codegen.jaxrs;
import io.swagger.codegen.CodegenModel;
import io.swagger.codegen.languages.JaxRSServerCodegen;
import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
import io.swagger.models.properties.DateProperty;
import io.swagger.models.properties.DateTimeProperty;
import io.swagger.models.properties.LongProperty;
import io.swagger.util.Json;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
public class JaxrsJodaModelTest {
@Test(description = "convert a simple java model with Joda types")
public void simpleModelTest() {
final Model model = new ModelImpl()
.description("a sample model")
.property("id", new LongProperty())
.property("theDate", new DateProperty())
.property("createdAt", new DateTimeProperty())
.required("id")
.required("name");
final JaxRSServerCodegen codegen = new JaxRSServerCodegen();
codegen.setDateLibrary("joda");
codegen.processOpts();
final CodegenModel cm = codegen.fromModel("sample", model);
Json.prettyPrint(cm);
assertEquals(cm.vars.get(0).datatype, "Long");
assertEquals(cm.vars.get(1).datatype, "LocalDate");
assertEquals(cm.vars.get(2).datatype, "DateTime");
}
}