Search in sources :

Example 26 with APIDefinitionValidationResponse

use of org.wso2.carbon.apimgt.api.APIDefinitionValidationResponse in project carbon-apimgt by wso2.

the class OAS3ParserTest method testValidateOpenAPIDefinitionWithBlankTitle.

@Test
public void testValidateOpenAPIDefinitionWithBlankTitle() throws Exception {
    String relativePath = "definitions" + File.separator + "oas3" + File.separator + "oas3_blank_title.yaml";
    String openApi = IOUtils.toString(getClass().getClassLoader().getResourceAsStream(relativePath), "UTF-8");
    APIDefinitionValidationResponse response = oas3Parser.validateAPIDefinition(openApi, false);
    Assert.assertTrue(response.isValid());
    Assert.assertTrue(response.getParser().getClass().equals(oas3Parser.getClass()));
}
Also used : APIDefinitionValidationResponse(org.wso2.carbon.apimgt.api.APIDefinitionValidationResponse) Test(org.junit.Test)

Example 27 with APIDefinitionValidationResponse

use of org.wso2.carbon.apimgt.api.APIDefinitionValidationResponse in project carbon-apimgt by wso2.

the class OASTestBase method testGenerateAPIDefinition.

public void testGenerateAPIDefinition(APIDefinition parser) throws Exception {
    APIIdentifier identifier = new APIIdentifier("admin", "simple", "1.0.0");
    API api = new API(identifier);
    api.setScopes(new HashSet<>(Arrays.asList(sampleScope, extensionScope)));
    api.setUriTemplates(new HashSet<>(Arrays.asList(petGet)));
    String definition = parser.generateAPIDefinition(new SwaggerData(api));
    APIDefinitionValidationResponse response = parser.validateAPIDefinition(definition, false);
    Assert.assertTrue(response.isValid());
    Assert.assertTrue(response.getParser().getClass().equals(parser.getClass()));
    Set<URITemplate> uriTemplates = parser.getURITemplates(definition);
    Assert.assertEquals(1, uriTemplates.size());
    Assert.assertTrue(uriTemplates.contains(petGet));
    Set<Scope> scopes = parser.getScopes(definition);
    Assert.assertEquals(2, scopes.size());
    Assert.assertTrue(scopes.contains(sampleScope));
    Assert.assertTrue(scopes.contains(extensionScope));
}
Also used : Scope(org.wso2.carbon.apimgt.api.model.Scope) SwaggerData(org.wso2.carbon.apimgt.api.model.SwaggerData) URITemplate(org.wso2.carbon.apimgt.api.model.URITemplate) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) API(org.wso2.carbon.apimgt.api.model.API) APIDefinitionValidationResponse(org.wso2.carbon.apimgt.api.APIDefinitionValidationResponse)

Example 28 with APIDefinitionValidationResponse

use of org.wso2.carbon.apimgt.api.APIDefinitionValidationResponse in project carbon-apimgt by wso2.

the class OASTestBase method testGenerateAPIDefinitionWithExtension.

public String testGenerateAPIDefinitionWithExtension(APIDefinition parser, String content) throws Exception {
    JSONObject jsonObject = new JSONObject(content);
    String equalNoOfResourcesWithExtension = jsonObject.getJSONObject("equalNoOfResourcesWithExtension").toString();
    Scope newScope = new Scope();
    newScope.setName("newScope");
    newScope.setKey("newScope");
    newScope.setRoles("admin");
    newScope.setDescription("newScopeDescription");
    URITemplate updatedItemGet = new URITemplate();
    updatedItemGet.setUriTemplate("/items");
    updatedItemGet.setAuthType("Application & Application User");
    updatedItemGet.setAuthTypes("Application & Application User");
    updatedItemGet.setHTTPVerb("GET");
    updatedItemGet.setHttpVerbs("GET");
    updatedItemGet.setThrottlingTier("Unlimited");
    updatedItemGet.setThrottlingTiers("Unlimited");
    updatedItemGet.setScope(newScope);
    updatedItemGet.setScopes(newScope);
    APIIdentifier identifier = new APIIdentifier("admin", "simple", "1.0.0");
    API api = new API(identifier);
    api.setScopes(new HashSet<>(Arrays.asList(sampleScope, extensionScope, newScope)));
    api.setUriTemplates(new HashSet<>(Arrays.asList(petPost, updatedItemGet)));
    String definition = parser.generateAPIDefinition(new SwaggerData(api), equalNoOfResourcesWithExtension);
    APIDefinitionValidationResponse response = parser.validateAPIDefinition(definition, false);
    Assert.assertTrue(response.isValid());
    return definition;
}
Also used : JSONObject(org.json.JSONObject) Scope(org.wso2.carbon.apimgt.api.model.Scope) SwaggerData(org.wso2.carbon.apimgt.api.model.SwaggerData) URITemplate(org.wso2.carbon.apimgt.api.model.URITemplate) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) API(org.wso2.carbon.apimgt.api.model.API) APIDefinitionValidationResponse(org.wso2.carbon.apimgt.api.APIDefinitionValidationResponse)

Aggregations

APIDefinitionValidationResponse (org.wso2.carbon.apimgt.api.APIDefinitionValidationResponse)24 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)14 API (org.wso2.carbon.apimgt.api.model.API)10 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 LinkedHashMap (java.util.LinkedHashMap)7 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)7 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)6 APIDefinition (org.wso2.carbon.apimgt.api.APIDefinition)5 SwaggerData (org.wso2.carbon.apimgt.api.model.SwaggerData)5 ArrayList (java.util.ArrayList)4 FaultGatewaysException (org.wso2.carbon.apimgt.api.FaultGatewaysException)4 JSONObject (org.json.JSONObject)3 ErrorItem (org.wso2.carbon.apimgt.api.ErrorItem)3 Scope (org.wso2.carbon.apimgt.api.model.Scope)3 AsyncAPISpecificationValidationResponseDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.AsyncAPISpecificationValidationResponseDTO)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Gson (com.google.gson.Gson)2 JsonObject (com.google.gson.JsonObject)2