use of io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest in project java-chassis by ServiceComb.
the class TestSwaggerDefinition method testFillDefault.
@Test
public void testFillDefault() {
SwaggerGenerator swaggerGenerator = new SwaggerGeneratorForTest(context, SwaggerNoAnnotation.class);
swaggerGenerator.generate();
swaggerGenerator.correctSwagger();
Swagger swagger = swaggerGenerator.getSwagger();
Assert.assertEquals("2.0", swagger.getSwagger());
Assert.assertEquals("/SwaggerNoAnnotation", swagger.getBasePath());
Assert.assertEquals("swagger definition for " + SwaggerNoAnnotation.class.getName(), swagger.getInfo().getTitle());
}
use of io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest in project java-chassis by ServiceComb.
the class TestSwaggerDefinition method testSwaggerDefinition.
@SuppressWarnings("unchecked")
@Test
public void testSwaggerDefinition() {
SwaggerGenerator swaggerGenerator = new SwaggerGeneratorForTest(context, SwaggerAnnotation.class);
swaggerGenerator.generate();
Swagger swagger = swaggerGenerator.getSwagger();
Assert.assertEquals(SwaggerAnnotation.class.getName(), swagger.getInfo().getVendorExtensions().get(SwaggerConst.EXT_JAVA_INTF));
Assert.assertEquals("2.0", swagger.getSwagger());
Assert.assertEquals("/base", swagger.getBasePath());
Assert.assertEquals("host", swagger.getHost());
Assert.assertEquals(Arrays.asList("json", "xml"), swagger.getConsumes());
Assert.assertEquals(Arrays.asList("abc", "123"), swagger.getProduces());
Assert.assertEquals(1, swagger.getTags().size());
io.swagger.models.Tag tagA = swagger.getTags().get(0);
Assert.assertEquals("tagA", tagA.getName());
Assert.assertEquals("desc of tagA", tagA.getDescription());
Assert.assertEquals("tagA ext docs", tagA.getExternalDocs().getDescription());
Assert.assertEquals("url of tagA ext docs", tagA.getExternalDocs().getUrl());
Assert.assertEquals(1, tagA.getVendorExtensions().size());
Map<String, Object> tagValue = (Map<String, Object>) tagA.getVendorExtensions().get("x-tagA");
Assert.assertEquals("value of tagAExt", tagValue.get("x-tagAExt"));
io.swagger.models.Info info = swagger.getInfo();
Assert.assertEquals("title of SwaggerAnnotation", info.getTitle());
Assert.assertEquals("0.1", info.getVersion());
Assert.assertEquals("termsOfService", info.getTermsOfService());
Assert.assertEquals("description of info for SwaggerAnnotation", info.getDescription());
Assert.assertEquals("contact", info.getContact().getName());
Assert.assertEquals("contact@email.com", info.getContact().getEmail());
Assert.assertEquals("http://contact", info.getContact().getUrl());
Assert.assertEquals("license ", info.getLicense().getName());
Assert.assertEquals("http://license", info.getLicense().getUrl());
Assert.assertEquals(2, info.getVendorExtensions().size());
Map<String, Object> infoValue = (Map<String, Object>) info.getVendorExtensions().get("x-info");
Assert.assertEquals("value of infoExt", infoValue.get("x-infoExt"));
Assert.assertEquals("SwaggerAnnotation ext docs", swagger.getExternalDocs().getDescription());
Assert.assertEquals("url of SwaggerAnnotation ext docs", swagger.getExternalDocs().getUrl());
}
use of io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest in project java-chassis by ServiceComb.
the class TestSwaggerUtils method testConverter.
@Test
public void testConverter() {
SwaggerGenerator generator = new SwaggerGeneratorForTest(context, null);
Swagger swagger = generator.getSwagger();
ParamUtils.addDefinitions(swagger, User.class);
Model model = swagger.getDefinitions().get("User");
model.getVendorExtensions().clear();
JavaType javaType = ConverterMgr.findJavaType(generator, model);
checkJavaType(swagger, javaType);
RefModel refModel = new RefModel();
refModel.setReference("User");
javaType = ConverterMgr.findJavaType(generator, refModel);
checkJavaType(swagger, javaType);
}
use of io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest in project java-chassis by ServiceComb.
the class TestApiOperation method testApiOperation.
@Test
public void testApiOperation() {
SwaggerGenerator swaggerGenerator = new SwaggerGeneratorForTest(context, ApiOperationAnnotation.class);
swaggerGenerator.generate();
Swagger swagger = swaggerGenerator.getSwagger();
testBase(swagger.getPath("/test"));
testPrimitive(swagger.getPath("/testPrimitive"));
testMap(swagger.getPath("/testMap"));
testList(swagger.getPath("/testList"));
testSet(swagger.getPath("/testSet"));
}
use of io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest in project java-chassis by ServiceComb.
the class TestApiImplicitParams method testBody.
@Test
public void testBody() {
SwaggerGenerator swaggerGenerator = new SwaggerGeneratorForTest(context, ApiImplicitParamsAnnotation.class);
swaggerGenerator.generate();
Swagger swagger = swaggerGenerator.getSwagger();
Path path = swagger.getPaths().get("/testBody");
Operation operation = path.getOperations().get(0);
Parameter parameter = operation.getParameters().get(0);
JavaType javaType = ConverterMgr.findJavaType(swaggerGenerator, parameter);
Assert.assertEquals(User.class, javaType.getRawClass());
}
Aggregations