Search in sources :

Example 71 with GatewaySourceGenerator

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

the class APIPublisherImplTestCase method testReplaceGroupNamesWithIdWithInvalidRoles.

@Test(description = "Update API when there is a list of invalid roles specified for permission")
public void testReplaceGroupNamesWithIdWithInvalidRoles() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
    IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
    String permissionString = "[{\"groupId\" : \"developer\", \"permission\" : [\"READ\",\"UPDATE\"]}," + "{\"groupId\" : \"invalid_role\", \"permission\" : [\"READ\",\"UPDATE\",\"DELETE\"]}]";
    String errorMessage = "There are invalid roles in the permission string";
    API.APIBuilder api = SampleTestObjectCreator.createDefaultAPI().apiPermission(permissionString);
    String uuid = api.getId();
    GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
    APIGateway gateway = Mockito.mock(APIGateway.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, apiLifecycleManager, gatewaySourceGenerator, gateway);
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api.lifeCycleStatus(APIStatus.CREATED.getStatus()).build());
    Mockito.when(identityProvider.getRoleId("invalid_role")).thenThrow(new IdentityProviderException(errorMessage, ExceptionCodes.ROLE_DOES_NOT_EXIST));
    Mockito.when(identityProvider.getRoleId(DEVELOPER_ROLE)).thenReturn(DEVELOPER_ROLE_ID);
    Mockito.when(apiDAO.isAPIContextExists(api.getContext())).thenReturn(true);
    String configString = SampleTestObjectCreator.createSampleGatewayConfig();
    Mockito.when(apiDAO.getGatewayConfigOfAPI(uuid)).thenReturn(configString);
    Mockito.when(apiDAO.getApiSwaggerDefinition(api.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
    try {
        apiPublisher.updateAPI(api.lifeCycleStatus(APIStatus.CREATED.getStatus()).id(uuid));
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "There are invalid roles in the permission string");
    }
}
Also used : APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) IdentityProvider(org.wso2.carbon.apimgt.core.api.IdentityProvider) API(org.wso2.carbon.apimgt.core.models.API) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) IdentityProviderException(org.wso2.carbon.apimgt.core.exception.IdentityProviderException) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) GatewaySourceGenerator(org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator) Test(org.testng.annotations.Test)

Aggregations

GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)71 Test (org.testng.annotations.Test)65 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)65 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)59 API (org.wso2.carbon.apimgt.core.models.API)59 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)34 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)34 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)34 LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)28 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)28 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)24 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)22 HashMap (java.util.HashMap)20 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)20 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)17 LifecycleState (org.wso2.carbon.lcm.core.impl.LifecycleState)16 KeyManager (org.wso2.carbon.apimgt.core.api.KeyManager)13 FileInputStream (java.io.FileInputStream)12 Scope (org.wso2.carbon.apimgt.core.models.Scope)12 WorkflowExtensionsConfigBuilder (org.wso2.carbon.apimgt.core.workflow.WorkflowExtensionsConfigBuilder)11