Search in sources :

Example 81 with APIGateway

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

the class APIPublisherImplTestCase method testUpdateSubscriptionStatus.

@Test(description = "Update subscription status")
public void testUpdateSubscriptionStatus() throws APIManagementException {
    APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
    APIGateway apiGatewayPublisher = Mockito.mock(APIGateway.class);
    Application application = SampleTestObjectCreator.createDefaultApplication();
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    Policy policy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
    Subscription subscription = new Subscription(SUB_ID, application, api, policy);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiSubscriptionDAO, apiGatewayPublisher);
    Mockito.when(apiSubscriptionDAO.getAPISubscription(SUB_ID)).thenReturn(subscription);
    apiPublisher.updateSubscriptionStatus(SUB_ID, APIMgtConstants.SubscriptionStatus.ACTIVE);
    Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).updateSubscriptionStatus(SUB_ID, APIMgtConstants.SubscriptionStatus.ACTIVE);
}
Also used : SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) API(org.wso2.carbon.apimgt.core.models.API) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) Application(org.wso2.carbon.apimgt.core.models.Application) Test(org.testng.annotations.Test)

Example 82 with APIGateway

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

the class APIPublisherImplTestCase method testUpdateAPIStatusWhileAPINotAvailable.

@Test(description = "Update api status", expectedExceptions = { APIManagementException.class })
public void testUpdateAPIStatusWhileAPINotAvailable() throws APIManagementException, LifecycleException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    String uuid = api.getId();
    String lifecycleId = api.getLifecycleInstanceId();
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(null);
    Mockito.when(apiLifecycleManager.executeLifecycleEvent(APIStatus.CREATED.getStatus(), APIStatus.PUBLISHED.getStatus(), uuid, USER, api)).thenReturn(SampleTestObjectCreator.getMockLifecycleStateObject(lifecycleId));
    Mockito.doThrow(new APIMgtDAOException("Couldn't change the status of api ID " + uuid)).when(apiDAO).changeLifeCycleStatus(uuid, APIStatus.PUBLISHED.getStatus());
    APIGateway gateway = Mockito.mock(APIGateway.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gateway);
    apiPublisher.updateAPIStatus(uuid, APIStatus.PUBLISHED.getStatus(), Collections.emptyMap());
}
Also used : APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) 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 83 with APIGateway

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

the class APIPublisherImplTestCase method testUpdateAPIWithContextChange.

@Test(description = "Test UpdateAPI with context changed")
public void testUpdateAPIWithContextChange() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
    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);
    API.APIBuilder api = SampleTestObjectCreator.createDefaultAPI();
    String uuid = api.getId();
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api.build());
    Mockito.when(identityProvider.getRoleId(ADMIN_ROLE)).thenReturn(ADMIN_ROLE_ID);
    Mockito.when(identityProvider.getRoleId(DEVELOPER_ROLE)).thenReturn(DEVELOPER_ROLE_ID);
    Mockito.when(apiDAO.getApiSwaggerDefinition(api.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
    apiPublisher.updateAPI(api.context("test"));
    Mockito.verify(apiDAO, Mockito.times(1)).updateAPI(uuid, api.context("test").build());
}
Also used : APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) 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) 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) GatewaySourceGenerator(org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator) Test(org.testng.annotations.Test)

Example 84 with APIGateway

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

the class APIMgtAdminServiceImplTestCase method testAddApplicationPolicy.

@Test(description = "Test add application policy")
public void testAddApplicationPolicy() throws APIManagementException {
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
    ApplicationPolicy policy = SampleTestObjectCreator.createDefaultApplicationPolicy();
    adminService.addApplicationPolicy(policy);
    Mockito.verify(policyDAO, Mockito.times(1)).addApplicationPolicy(policy);
    // Error path
    Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).addApplicationPolicy(policy);
    try {
        adminService.addApplicationPolicy(policy);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Couldn't add Application for uuid: " + policy.getUuid());
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 85 with APIGateway

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

the class APIMgtAdminServiceImplTestCase method testUpdateBlockConditionStateByUUID.

@Test(description = "Test updating block condition state by uuid")
public void testUpdateBlockConditionStateByUUID() throws APIManagementException {
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
    BlockConditions blockConditions = SampleTestObjectCreator.createDefaultBlockCondition(BLOCK_CONDITION_TYPE);
    Mockito.when(policyDAO.updateBlockConditionStateByUUID(blockConditions.getUuid(), true)).thenReturn(true);
    Boolean statusTrue = adminService.updateBlockConditionStateByUUID(blockConditions.getUuid(), true);
    Assert.assertTrue(statusTrue);
    // Error path
    // Failure updating
    Mockito.when(policyDAO.updateBlockConditionStateByUUID(blockConditions.getUuid(), true)).thenReturn(false);
    Boolean statusFalse = adminService.updateBlockConditionStateByUUID(blockConditions.getUuid(), true);
    Assert.assertFalse(statusFalse);
    // Error path
    // APIMgtDAOException
    Mockito.when(policyDAO.updateBlockConditionStateByUUID(blockConditions.getUuid(), true)).thenThrow(APIMgtDAOException.class);
    try {
        adminService.updateBlockConditionStateByUUID(blockConditions.getUuid(), true);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Couldn't update block condition with UUID: " + blockConditions.getUuid() + ", state: " + true);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) 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