Search in sources :

Example 1 with DynamicHtmlGen

use of org.wso2.carbon.apimgt.rest.api.common.codegen.DynamicHtmlGen in project carbon-apimgt by wso2.

the class DynamicHtmlGenTestCase method testToApiName.

@Test
public void testToApiName() throws Exception {
    DynamicHtmlGen htmlGen = new DynamicHtmlGen();
    final String originalTag = "API (Collection)";
    String sanitised = htmlGen.sanitizeTag(originalTag);
    Assert.assertEquals(sanitised, "APICollection");
    String retrievedTag = htmlGen.toApiName(sanitised);
    Assert.assertEquals(retrievedTag, originalTag);
    sanitised = htmlGen.toApiFilename(originalTag);
    Assert.assertEquals(sanitised, "APICollection");
}
Also used : DynamicHtmlGen(org.wso2.carbon.apimgt.rest.api.common.codegen.DynamicHtmlGen) Test(org.testng.annotations.Test)

Example 2 with DynamicHtmlGen

use of org.wso2.carbon.apimgt.rest.api.common.codegen.DynamicHtmlGen in project carbon-apimgt by wso2.

the class DynamicHtmlGenTestCase method testFromParameter.

@Test
public void testFromParameter() throws Exception {
    Parameter parameter = new QueryParameter();
    parameter.setName("query");
    final String description = "Sample parameter description";
    parameter.setDescription(description);
    DynamicHtmlGen htmlGen = new DynamicHtmlGen();
    CodegenParameter modified = htmlGen.fromParameter(parameter, new HashSet<>());
    Assert.assertEquals(modified.description, description);
}
Also used : CodegenParameter(io.swagger.codegen.CodegenParameter) QueryParameter(io.swagger.models.parameters.QueryParameter) DynamicHtmlGen(org.wso2.carbon.apimgt.rest.api.common.codegen.DynamicHtmlGen) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) CodegenParameter(io.swagger.codegen.CodegenParameter) Test(org.testng.annotations.Test)

Example 3 with DynamicHtmlGen

use of org.wso2.carbon.apimgt.rest.api.common.codegen.DynamicHtmlGen in project carbon-apimgt by wso2.

the class DynamicHtmlGenTestCase method testPreprocessSwagger.

@Test
public void testPreprocessSwagger() throws Exception {
    DynamicHtmlGen htmlGen = new DynamicHtmlGen();
    Swagger swagger = new Swagger();
    Path path = new Path();
    Operation operation = new Operation();
    List<String> tags = new ArrayList<>();
    tags.add("tag1");
    tags.add("tag2");
    tags.add("tag3");
    tags.add("tag4");
    operation.setTags(tags);
    path.setGet(operation);
    swagger.path("get_sample", path);
    htmlGen.preprocessSwagger(swagger);
    List<String> processedTags = swagger.getPath("get_sample").getGet().getTags();
    Assert.assertEquals(processedTags.size(), 1);
    Assert.assertEquals(processedTags.get(0), "tag1");
}
Also used : Path(io.swagger.models.Path) DynamicHtmlGen(org.wso2.carbon.apimgt.rest.api.common.codegen.DynamicHtmlGen) Swagger(io.swagger.models.Swagger) ArrayList(java.util.ArrayList) CodegenOperation(io.swagger.codegen.CodegenOperation) Operation(io.swagger.models.Operation) Test(org.testng.annotations.Test)

Example 4 with DynamicHtmlGen

use of org.wso2.carbon.apimgt.rest.api.common.codegen.DynamicHtmlGen in project carbon-apimgt by wso2.

the class DynamicHtmlGenTestCase method testFromOperation.

@Test
public void testFromOperation() throws Exception {
    Operation operation = new Operation();
    final String summary = "Sample operation summary";
    final String description = "Sample operation description";
    operation.setDescription(description);
    operation.setSummary(summary);
    DynamicHtmlGen htmlGen = new DynamicHtmlGen();
    CodegenOperation modified = htmlGen.fromOperation("/apis", "GET", operation, null, null);
    Assert.assertEquals(modified.summary, summary);
    Assert.assertEquals(modified.notes, description);
}
Also used : CodegenOperation(io.swagger.codegen.CodegenOperation) DynamicHtmlGen(org.wso2.carbon.apimgt.rest.api.common.codegen.DynamicHtmlGen) CodegenOperation(io.swagger.codegen.CodegenOperation) Operation(io.swagger.models.Operation) Test(org.testng.annotations.Test)

Example 5 with DynamicHtmlGen

use of org.wso2.carbon.apimgt.rest.api.common.codegen.DynamicHtmlGen in project carbon-apimgt by wso2.

the class DynamicHtmlGenTestCase method testEscapeQuotationMark.

@Test
public void testEscapeQuotationMark() throws Exception {
    DynamicHtmlGen htmlGen = new DynamicHtmlGen();
    final String stringToEscape = "\"";
    String result = htmlGen.escapeQuotationMark(stringToEscape);
    // Shouldn't be escaped
    Assert.assertEquals(result, stringToEscape);
}
Also used : DynamicHtmlGen(org.wso2.carbon.apimgt.rest.api.common.codegen.DynamicHtmlGen) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)6 DynamicHtmlGen (org.wso2.carbon.apimgt.rest.api.common.codegen.DynamicHtmlGen)6 CodegenOperation (io.swagger.codegen.CodegenOperation)2 Operation (io.swagger.models.Operation)2 CodegenParameter (io.swagger.codegen.CodegenParameter)1 Path (io.swagger.models.Path)1 Swagger (io.swagger.models.Swagger)1 Parameter (io.swagger.models.parameters.Parameter)1 QueryParameter (io.swagger.models.parameters.QueryParameter)1 ArrayList (java.util.ArrayList)1