Search in sources :

Example 11 with APIDefinitionFromSwagger20

use of org.wso2.carbon.apimgt.core.impl.APIDefinitionFromSwagger20 in project carbon-apimgt by wso2.

the class APIDefinitionFromSwagger20TestCase method testAddNewScopeToExistingOauthSecurity.

@Test()
public void testAddNewScopeToExistingOauthSecurity() throws IOException, APIManagementException {
    APIDefinitionFromSwagger20 apiDefinitionFromSwagger20 = new APIDefinitionFromSwagger20();
    String filePath = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "swagger" + File.separator + "swaggerWithAuthorization.yaml";
    File file = Paths.get(filePath).toFile();
    String sampleApi = IOUtils.toString(new FileInputStream(file));
    Scope scope = new Scope();
    scope.setName("apim:api_delete");
    scope.setDescription("Delete API");
    String scopeAddedSwagger = apiDefinitionFromSwagger20.addScopeToSwaggerDefinition(sampleApi, scope);
    Map<String, String> scopes = apiDefinitionFromSwagger20.getScopesFromSecurityDefinition(scopeAddedSwagger);
    Assert.assertTrue(scopes.containsKey("apim:api_delete"));
}
Also used : Scope(org.wso2.carbon.apimgt.core.models.Scope) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test)

Example 12 with APIDefinitionFromSwagger20

use of org.wso2.carbon.apimgt.core.impl.APIDefinitionFromSwagger20 in project carbon-apimgt by wso2.

the class APIDefinitionFromSwagger20TestCase method testApiResourceParseFromSwagger.

@Test()
public void testApiResourceParseFromSwagger() throws IOException, APIManagementException {
    APIDefinitionFromSwagger20 apiDefinitionFromSwagger20 = new APIDefinitionFromSwagger20();
    String sampleApi = SampleTestObjectCreator.getSampleApiSwagger();
    API.APIBuilder apiBuilder = apiDefinitionFromSwagger20.generateApiFromSwaggerResource("testProvider", sampleApi);
    API api = apiBuilder.build();
    Assert.assertNotNull(api);
}
Also used : API(org.wso2.carbon.apimgt.core.models.API) Test(org.testng.annotations.Test)

Example 13 with APIDefinitionFromSwagger20

use of org.wso2.carbon.apimgt.core.impl.APIDefinitionFromSwagger20 in project carbon-apimgt by wso2.

the class APIDefinitionFromSwagger20TestCase method testGenerateMergedResourceDefinitionUpdatingExistingresource.

@Test
public void testGenerateMergedResourceDefinitionUpdatingExistingresource() throws IOException {
    APIDefinitionFromSwagger20 apiDefinitionFromSwagger20 = new APIDefinitionFromSwagger20();
    String sampleApi = IOUtils.toString(this.getClass().getResourceAsStream(File.separator + "swagger" + File.separator + "swaggerWithAuthorization.yaml"));
    UriTemplate uriTemplate1 = new UriTemplate.UriTemplateBuilder().uriTemplate("/apis").httpVerb("get").scopes(Arrays.asList("apim:api_create")).build();
    UriTemplate uriTemplate2 = new UriTemplate.UriTemplateBuilder().uriTemplate("/endpoints").httpVerb("post").scopes(Arrays.asList("apim:api_create")).build();
    Map<String, UriTemplate> hasTemplateMap = new HashMap<>();
    hasTemplateMap.put(APIUtils.generateOperationIdFromPath(uriTemplate1.getUriTemplate(), uriTemplate1.getHttpVerb()), uriTemplate1);
    hasTemplateMap.put(APIUtils.generateOperationIdFromPath(uriTemplate2.getUriTemplate(), uriTemplate2.getHttpVerb()), uriTemplate2);
    API api = new API.APIBuilder("admin", "admin", "1.0.0").uriTemplates(hasTemplateMap).id(UUID.randomUUID().toString()).build();
    apiDefinitionFromSwagger20.generateMergedResourceDefinition(sampleApi, api);
}
Also used : HashMap(java.util.HashMap) API(org.wso2.carbon.apimgt.core.models.API) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate) Test(org.testng.annotations.Test)

Example 14 with APIDefinitionFromSwagger20

use of org.wso2.carbon.apimgt.core.impl.APIDefinitionFromSwagger20 in project carbon-apimgt by wso2.

the class APIDefinitionFromSwagger20TestCase method testGenerateMergedResourceDefinitionWhileAddingRootLevelHavingDifferentLevelSecurity.

@Test
public void testGenerateMergedResourceDefinitionWhileAddingRootLevelHavingDifferentLevelSecurity() throws IOException {
    APIDefinitionFromSwagger20 apiDefinitionFromSwagger20 = new APIDefinitionFromSwagger20();
    String sampleApi = IOUtils.toString(this.getClass().getResourceAsStream(File.separator + "swagger" + File.separator + "swaggerWithAuthorizationApiKeyInRoot.yaml"));
    UriTemplate uriTemplate1 = new UriTemplate.UriTemplateBuilder().uriTemplate("/apis").httpVerb("post").scopes(Arrays.asList("apim:api_create")).build();
    UriTemplate uriTemplate2 = new UriTemplate.UriTemplateBuilder().uriTemplate("/endpoints").httpVerb("post").scopes(Arrays.asList("apim:api_create")).build();
    Map<String, UriTemplate> hasTemplateMap = new HashMap<>();
    hasTemplateMap.put(APIUtils.generateOperationIdFromPath(uriTemplate1.getUriTemplate(), uriTemplate1.getHttpVerb()), uriTemplate1);
    hasTemplateMap.put(APIUtils.generateOperationIdFromPath(uriTemplate2.getUriTemplate(), uriTemplate2.getHttpVerb()), uriTemplate2);
    API api = new API.APIBuilder("admin", "admin", "1.0.0").uriTemplates(hasTemplateMap).id(UUID.randomUUID().toString()).scopes(Arrays.asList("apim:api_create")).build();
    apiDefinitionFromSwagger20.generateMergedResourceDefinition(sampleApi, api);
}
Also used : HashMap(java.util.HashMap) API(org.wso2.carbon.apimgt.core.models.API) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate) Test(org.testng.annotations.Test)

Example 15 with APIDefinitionFromSwagger20

use of org.wso2.carbon.apimgt.core.impl.APIDefinitionFromSwagger20 in project carbon-apimgt by wso2.

the class APIDefinitionFromSwagger20TestCase method testUpdateScope.

@Test()
public void testUpdateScope() throws IOException, APIManagementException {
    APIDefinitionFromSwagger20 apiDefinitionFromSwagger20 = new APIDefinitionFromSwagger20();
    String sampleApi = IOUtils.toString(this.getClass().getResourceAsStream(File.separator + "swagger" + File.separator + "swaggerWithAuthorization.yaml"));
    Scope scope = new Scope();
    scope.setName("apim:api_create");
    scope.setDescription("Delete API");
    String scopeAddedSwagger = apiDefinitionFromSwagger20.updateScopesOnSwaggerDefinition(sampleApi, scope);
    Map<String, String> scopes = apiDefinitionFromSwagger20.getScopesFromSecurityDefinition(scopeAddedSwagger);
    Assert.assertTrue(scopes.containsKey("apim:api_create"));
// commented due to parallel test run
// Assert.assertEquals(scopes.get("apim:api_delete").getDescription(),"Delete API");
}
Also used : Scope(org.wso2.carbon.apimgt.core.models.Scope) Test(org.testng.annotations.Test)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)15 HashMap (java.util.HashMap)12 API (org.wso2.carbon.apimgt.core.models.API)12 Test (org.testng.annotations.Test)10 UriTemplate (org.wso2.carbon.apimgt.core.models.UriTemplate)9 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)8 Scope (org.wso2.carbon.apimgt.core.models.Scope)7 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)5 IOException (java.io.IOException)4 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)4 GatewayException (org.wso2.carbon.apimgt.core.exception.GatewayException)4 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)4 APIConfigContext (org.wso2.carbon.apimgt.core.template.APIConfigContext)4 LocalDateTime (java.time.LocalDateTime)3 Map (java.util.Map)3 ParseException (org.json.simple.parser.ParseException)3 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)3 APIDefinitionFromSwagger20 (org.wso2.carbon.apimgt.core.impl.APIDefinitionFromSwagger20)3 LifecycleException (org.wso2.carbon.lcm.core.exception.LifecycleException)3 FileInputStream (java.io.FileInputStream)2