Search in sources :

Example 51 with APIGateway

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

the class APIStoreImplTestCase method testDeleteSubscription.

@Test(description = "Delete subscription")
public void testDeleteSubscription() throws APIManagementException {
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
    WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    APIStore apiStore = getApiStoreImpl(applicationDAO, apiSubscriptionDAO, workflowDAO, apiGateway);
    Application application = SampleTestObjectCreator.createDefaultApplication();
    APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
    API api = builder.build();
    Subscription subscription = new Subscription(UUID, application, api, new SubscriptionPolicy("Gold"));
    Mockito.when(apiSubscriptionDAO.getAPISubscription(UUID)).thenReturn(subscription);
    apiStore.deleteAPISubscription(UUID);
    Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).deleteAPISubscription(UUID);
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) Application(org.wso2.carbon.apimgt.core.models.Application) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 52 with APIGateway

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

the class APIPublisherImplTestCase method testUpdateAPIWithStatusChanged.

@Test(description = "Test UpdateAPI with Status changed", expectedExceptions = APIManagementException.class)
public void testUpdateAPIWithStatusChanged() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
    APIGateway gateway = Mockito.mock(APIGateway.class);
    IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, apiLifecycleManager, gateway);
    API.APIBuilder api = SampleTestObjectCreator.createDefaultAPI();
    String uuid = api.getId();
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api.build());
    Mockito.when(identityProvider.getRoleName(SampleTestObjectCreator.DEVELOPER_ROLE_ID)).thenReturn(DEVELOPER_ROLE);
    Mockito.when(identityProvider.getRoleName(SampleTestObjectCreator.ADMIN_ROLE_ID)).thenReturn(ADMIN_ROLE);
    Mockito.when(apiDAO.getApiSwaggerDefinition(api.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
    apiPublisher.updateAPI(api.lifeCycleStatus(APIStatus.PUBLISHED.getStatus()));
}
Also used : APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) 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) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 53 with APIGateway

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

the class APIPublisherImplTestCase method testUpdateAPIWithRestrictedVisibility.

@Test(description = "Test UpdateAPI with restricted visibility")
public void testUpdateAPIWithRestrictedVisibility() throws APIManagementException, LifecycleException {
    Set<String> visibleRoles = new HashSet<>();
    visibleRoles.add(ADMIN_ROLE);
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
    API.APIBuilder api = SampleTestObjectCreator.createDefaultAPI().visibility(API.Visibility.RESTRICTED).visibleRoles(visibleRoles);
    String uuid = api.getId();
    GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
    APIGateway gateway = Mockito.mock(APIGateway.class);
    IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, APIMgtConstants.DEFAULT_API_POLICY)).thenReturn(new APIPolicy(APIMgtConstants.DEFAULT_API_POLICY));
    Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, GOLD_TIER)).thenReturn(new SubscriptionPolicy(GOLD_TIER));
    Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, SILVER_TIER)).thenReturn(new SubscriptionPolicy(SILVER_TIER));
    Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, BRONZE_TIER)).thenReturn(new SubscriptionPolicy(BRONZE_TIER));
    APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, apiLifecycleManager, gatewaySourceGenerator, gateway, policyDAO);
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api.lifeCycleStatus(APIStatus.CREATED.getStatus()).build());
    Mockito.when(apiDAO.isAPIContextExists(api.getContext())).thenReturn(true);
    String configString = SampleTestObjectCreator.createSampleGatewayConfig();
    Mockito.when(apiDAO.getGatewayConfigOfAPI(uuid)).thenReturn(configString);
    Mockito.when(identityProvider.getRoleId(ADMIN_ROLE)).thenReturn(ADMIN_ROLE_ID);
    Mockito.when(apiDAO.getApiSwaggerDefinition(api.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
    Mockito.when(identityProvider.getRoleId(DEVELOPER_ROLE)).thenReturn(DEVELOPER_ROLE_ID);
    apiPublisher.updateAPI(api.lifeCycleStatus(APIStatus.CREATED.getStatus()).id(uuid));
    Mockito.verify(apiDAO, Mockito.times(1)).getAPI(uuid);
    Mockito.verify(apiDAO, Mockito.times(0)).isAPIContextExists(api.getContext());
    Mockito.verify(apiDAO, Mockito.times(1)).updateAPI(uuid, api.lifeCycleStatus(APIStatus.CREATED.getStatus()).build());
}
Also used : APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) IdentityProvider(org.wso2.carbon.apimgt.core.api.IdentityProvider) GatewaySourceGenerator(org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator) APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) API(org.wso2.carbon.apimgt.core.models.API) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 54 with APIGateway

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

the class APIPublisherImplTestCase method testCreateNewAPIVersionWithInvalidUUID.

@Test(description = "Create new  API version with invalid APIID")
public void testCreateNewAPIVersionWithInvalidUUID() throws APIManagementException, LifecycleException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
    APIGateway gateway = Mockito.mock(APIGateway.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gateway);
    Mockito.when(apiDAO.getAPI("xxxxxx")).thenThrow(new APIMgtDAOException("API with ID does not exist", ExceptionCodes.API_NOT_FOUND));
    try {
        apiPublisher.createNewAPIVersion("xxxxxx", "2.0.0");
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getErrorHandler(), ExceptionCodes.API_NOT_FOUND);
    }
}
Also used : APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 55 with APIGateway

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

the class APIPublisherImplTestCase method testDeleteScopeToApi.

@Test(description = "Delete existing Scope of API")
public void testDeleteScopeToApi() throws APIManagementException, IOException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    String uuid = api.getId();
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
    GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
    APIGateway gateway = Mockito.mock(APIGateway.class);
    IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
    KeyManager keyManager = Mockito.mock(KeyManager.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, gatewaySourceGenerator, gateway, keyManager);
    String oldSwagger = IOUtils.toString(new FileInputStream("src" + File.separator + "test" + File.separator + "resources" + File.separator + "swagger" + File.separator + "swaggerWithAuthorization" + ".yaml"));
    Scope scope = new Scope("apim:api_create", "apim:api_create");
    Mockito.when(apiDAO.getApiSwaggerDefinition(uuid)).thenReturn(oldSwagger);
    Mockito.when(keyManager.deleteScope(scope.getName())).thenReturn(true);
    apiPublisher.deleteScopeFromApi(api.getId(), scope.getName());
}
Also used : Scope(org.wso2.carbon.apimgt.core.models.Scope) API(org.wso2.carbon.apimgt.core.models.API) IdentityProvider(org.wso2.carbon.apimgt.core.api.IdentityProvider) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) KeyManager(org.wso2.carbon.apimgt.core.api.KeyManager) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) FileInputStream(java.io.FileInputStream) GatewaySourceGenerator(org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator) Test(org.testng.annotations.Test)

Aggregations

APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)135 Test (org.testng.annotations.Test)129 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)100 API (org.wso2.carbon.apimgt.core.models.API)87 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)73 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)59 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)55 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)48 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)38 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)35 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)32 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)31 WorkflowDAO (org.wso2.carbon.apimgt.core.dao.WorkflowDAO)29 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)28 LifecycleState (org.wso2.carbon.lcm.core.impl.LifecycleState)28 LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)26 HashMap (java.util.HashMap)22 APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)22 BeforeTest (org.testng.annotations.BeforeTest)19 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)19