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"));
}
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);
}
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);
}
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);
}
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");
}
Aggregations