Search in sources :

Example 76 with APILifecycleManager

use of org.wso2.carbon.apimgt.core.api.APILifecycleManager 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

APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)76 Test (org.testng.annotations.Test)75 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)75 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)73 API (org.wso2.carbon.apimgt.core.models.API)67 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)51 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)34 LifecycleState (org.wso2.carbon.lcm.core.impl.LifecycleState)28 LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)26 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)24 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)22 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)20 HashMap (java.util.HashMap)19 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)19 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)17 WorkflowDAO (org.wso2.carbon.apimgt.core.dao.WorkflowDAO)11 APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)10 WorkflowExtensionsConfigBuilder (org.wso2.carbon.apimgt.core.workflow.WorkflowExtensionsConfigBuilder)10 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)9 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)7