Search in sources :

Example 36 with APIDefinition

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

the class ApiDAOImplIT method testDocumentAdd.

@Test
public void testDocumentAdd() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
    API api = builder.build();
    testAddGetEndpoint();
    apiDAO.addAPI(api);
    DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultFileDocumentationInfo();
    Assert.assertFalse(apiDAO.isDocumentExist(api.getId(), documentInfo));
    apiDAO.addDocumentInfo(api.getId(), documentInfo);
    apiDAO.addDocumentFileContent(documentInfo.getId(), IOUtils.toInputStream(SampleTestObjectCreator.createDefaultInlineDocumentationContent()), "inline1.txt", documentInfo.getCreatedBy());
    Assert.assertTrue(apiDAO.isDocumentExist(api.getId(), documentInfo));
    List<DocumentInfo> documentInfoList = apiDAO.getDocumentsInfoList(api.getId());
    Assert.assertEquals(documentInfoList.get(0), documentInfo);
    apiDAO.deleteDocument(documentInfo.getId());
    Assert.assertFalse(apiDAO.isDocumentExist(api.getId(), documentInfo));
}
Also used : CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) Test(org.testng.annotations.Test)

Example 37 with APIDefinition

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

the class ApiDAOImplIT method testUpdateGetDedicatedGatewayWhenLabelsAreNull.

@Test
public void testUpdateGetDedicatedGatewayWhenLabelsAreNull() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
    API api = builder.build();
    testAddGetEndpoint();
    apiDAO.addAPI(api);
    DedicatedGateway dedicatedGateway = new DedicatedGateway();
    dedicatedGateway.setEnabled(true);
    dedicatedGateway.setUpdatedBy(api.getCreatedBy());
    dedicatedGateway.setApiId(api.getId());
    apiDAO.updateDedicatedGateway(dedicatedGateway, null);
    DedicatedGateway result = apiDAO.getDedicatedGateway(api.getId());
    Assert.assertEquals(result.isEnabled(), dedicatedGateway.isEnabled());
}
Also used : CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) DedicatedGateway(org.wso2.carbon.apimgt.core.models.DedicatedGateway) Test(org.testng.annotations.Test)

Example 38 with APIDefinition

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

the class ApiDAOImplIT method testAddGetCommentsOfAPI.

@Test
public void testAddGetCommentsOfAPI() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
    API api = builder.build();
    testAddGetEndpoint();
    apiDAO.addAPI(api);
    Comment comment1 = SampleTestObjectCreator.createDefaultComment(api.getId());
    Comment comment2 = SampleTestObjectCreator.createAlternativeComment(api.getId());
    apiDAO.addComment(comment1, api.getId());
    apiDAO.addComment(comment2, api.getId());
    List<Comment> commentsFromDB = apiDAO.getCommentsForApi(api.getId());
    Assert.assertEquals(commentsFromDB.size(), 2);
    Assert.assertTrue(commentsFromDB.get(0).getCommentText().equals(comment1.getCommentText()) || commentsFromDB.get(0).getCommentText().equals(comment2.getCommentText()));
    Assert.assertTrue(commentsFromDB.get(1).getCommentText().equals(comment1.getCommentText()) || commentsFromDB.get(1).getCommentText().equals(comment2.getCommentText()));
}
Also used : Comment(org.wso2.carbon.apimgt.core.models.Comment) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 39 with APIDefinition

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

the class AuthenticatorService method getApplicationScopes.

/**
 * This method returns the scopes for a given application.
 *
 * @param appName Name the application
 * @return scopes - A space separated list of scope keys
 * @throws APIManagementException When retrieving scopes from swagger definition fails
 */
private String getApplicationScopes(String appName) throws APIManagementException {
    String scopes;
    String applicationRestAPI = null;
    if (AuthenticatorConstants.STORE_APPLICATION.equals(appName)) {
        applicationRestAPI = RestApiUtil.getStoreRestAPIResource();
    } else if (AuthenticatorConstants.PUBLISHER_APPLICATION.equals(appName)) {
        applicationRestAPI = RestApiUtil.getPublisherRestAPIResource();
    } else if (AuthenticatorConstants.ADMIN_APPLICATION.equals(appName)) {
        applicationRestAPI = RestApiUtil.getAdminRestAPIResource();
    }
    try {
        if (applicationRestAPI != null) {
            APIDefinition apiDefinitionFromSwagger20 = new APIDefinitionFromSwagger20();
            Map<String, Scope> applicationScopesMap = apiDefinitionFromSwagger20.getScopesFromSecurityDefinitionForWebApps(applicationRestAPI);
            scopes = String.join(" ", applicationScopesMap.keySet());
            // Set openid scope
            if (StringUtils.isEmpty(scopes)) {
                scopes = KeyManagerConstants.OPEN_ID_CONNECT_SCOPE;
            } else {
                scopes = scopes + " " + KeyManagerConstants.OPEN_ID_CONNECT_SCOPE;
            }
        } else {
            String errorMsg = "Error while getting application rest API resource.";
            log.error(errorMsg, ExceptionCodes.INTERNAL_ERROR);
            throw new APIManagementException(errorMsg, ExceptionCodes.INTERNAL_ERROR);
        }
    } catch (APIManagementException e) {
        String errorMsg = "Error while reading scopes from swagger definition.";
        log.error(errorMsg, e, ExceptionCodes.INTERNAL_ERROR);
        throw new APIManagementException(errorMsg, e, ExceptionCodes.INTERNAL_ERROR);
    }
    return scopes;
}
Also used : Scope(org.wso2.carbon.apimgt.core.models.Scope) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIDefinition(org.wso2.carbon.apimgt.core.api.APIDefinition) APIDefinitionFromSwagger20(org.wso2.carbon.apimgt.core.impl.APIDefinitionFromSwagger20)

Aggregations

API (org.wso2.carbon.apimgt.core.models.API)30 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)25 Test (org.testng.annotations.Test)18 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)18 HashMap (java.util.HashMap)16 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)13 HashSet (java.util.HashSet)12 BusinessInformation (org.wso2.carbon.apimgt.core.models.BusinessInformation)12 CorsConfiguration (org.wso2.carbon.apimgt.core.models.CorsConfiguration)12 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)12 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)11 Map (java.util.Map)9 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)8 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)8 QuotaPolicy (org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)7 ArrayList (java.util.ArrayList)5 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)5 CustomPolicy (org.wso2.carbon.apimgt.core.models.policy.CustomPolicy)5 ThreatProtectionPolicy (org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy)5 HashedMap (org.apache.commons.collections.map.HashedMap)4