Search in sources :

Example 61 with Subscription

use of org.wso2.carbon.apimgt.api.model.subscription.Subscription in project carbon-apimgt by wso2.

the class SubscriptionsApiServiceImplTestCase method testSubscriptionsGetfromApplication.

@Test
public void testSubscriptionsGetfromApplication() throws APIManagementException, NotFoundException {
    TestUtil.printTestMethodName();
    String applicationId = UUID.randomUUID().toString();
    String subsID1 = UUID.randomUUID().toString();
    String subsID2 = UUID.randomUUID().toString();
    SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
    APIStore apiStore = Mockito.mock(APIStoreImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
    Request request = TestUtil.getRequest();
    PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
    Application application = SampleTestObjectCreator.createDefaultApplication();
    List<Subscription> subscriptionList = new ArrayList<>();
    subscriptionList.add(SampleTestObjectCreator.createSubscription(subsID1));
    subscriptionList.add(SampleTestObjectCreator.createSubscription(subsID2));
    Mockito.when(apiStore.getApplicationByUuid(applicationId)).thenReturn(application);
    Mockito.when(apiStore.getAPISubscriptionsByApplication(application, ApiType.STANDARD)).thenReturn(subscriptionList);
    Response response = subscriptionsApiService.subscriptionsGet(null, applicationId, ApiType.STANDARD.toString(), 0, 10, null, request);
    Assert.assertEquals(200, response.getStatus());
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) Request(org.wso2.msf4j.Request) ArrayList(java.util.ArrayList) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) Application(org.wso2.carbon.apimgt.core.models.Application) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 62 with Subscription

use of org.wso2.carbon.apimgt.api.model.subscription.Subscription in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImplTestCase method testGetSubscriptionPolicyByUuid.

@Test(description = "Test getting Subscription policy by UUID")
public void testGetSubscriptionPolicyByUuid() throws APIManagementException {
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
    SubscriptionPolicy subscriptionPolicy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
    Mockito.when(policyDAO.getSubscriptionPolicyByUuid(subscriptionPolicy.getUuid())).thenReturn(subscriptionPolicy);
    adminService.getSubscriptionPolicyByUuid(subscriptionPolicy.getUuid());
    Mockito.verify(policyDAO, Mockito.times(1)).getSubscriptionPolicyByUuid(subscriptionPolicy.getUuid());
    // Error path
    Mockito.when(policyDAO.getSubscriptionPolicyByUuid(subscriptionPolicy.getUuid())).thenThrow(APIMgtDAOException.class);
    try {
        adminService.getSubscriptionPolicyByUuid(subscriptionPolicy.getUuid());
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Couldn't retrieve Subscription policy with id: " + subscriptionPolicy.getUuid());
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 63 with Subscription

use of org.wso2.carbon.apimgt.api.model.subscription.Subscription in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImplTestCase method testAddSubscriptionPolicyWhenPolicyIdNull.

@Test(description = "Test add subscription policy when the policy ID is null")
public void testAddSubscriptionPolicyWhenPolicyIdNull() throws APIManagementException {
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
    SubscriptionPolicy policy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
    policy.setUuid(null);
    adminService.addSubscriptionPolicy(policy);
    Mockito.verify(policyDAO, Mockito.times(1)).addSubscriptionPolicy(policy);
}
Also used : SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 64 with Subscription

use of org.wso2.carbon.apimgt.api.model.subscription.Subscription in project carbon-apimgt by wso2.

the class MappingUtil method convertToSubscriptionListDto.

/**
 * This method converts List of SubscriptionValidationData into SubscriptionDTO list.
 *
 * @param subscriptionValidationData List of Subscription Validation Data
 * @return SubscriptionDTO list
 */
public static List<SubscriptionDTO> convertToSubscriptionListDto(List<SubscriptionValidationData> subscriptionValidationData) {
    List<SubscriptionDTO> subscriptionDTOList = new ArrayList<>();
    for (SubscriptionValidationData subscriptionData : subscriptionValidationData) {
        SubscriptionDTO subscriptionDTO = new SubscriptionDTO();
        subscriptionDTO.setApiName(subscriptionData.getApiName());
        subscriptionDTO.setApiContext(subscriptionData.getApiContext());
        subscriptionDTO.setApiVersion(subscriptionData.getApiVersion());
        subscriptionDTO.setApiProvider(subscriptionData.getApiProvider());
        subscriptionDTO.setConsumerKey(subscriptionData.getConsumerKey());
        subscriptionDTO.setSubscriptionPolicy(subscriptionData.getSubscriptionPolicy());
        subscriptionDTO.setKeyEnvType(subscriptionData.getKeyEnvType());
        subscriptionDTO.setApplicationId(subscriptionData.getApplicationId());
        subscriptionDTO.setStatus(subscriptionData.getStatus());
        subscriptionDTOList.add(subscriptionDTO);
    }
    return subscriptionDTOList;
}
Also used : ArrayList(java.util.ArrayList) SubscriptionValidationData(org.wso2.carbon.apimgt.core.models.SubscriptionValidationData) SubscriptionDTO(org.wso2.carbon.apimgt.rest.api.core.dto.SubscriptionDTO)

Example 65 with Subscription

use of org.wso2.carbon.apimgt.api.model.subscription.Subscription in project carbon-apimgt by wso2.

the class PolicyExportManager method getSubscriptionPolicySiddhiApps.

/**
 * Get execution plan/ siddhi apps for custom policies.
 *
 * @param subscriptionPolicies SubscriptionPolicy object list
 * @return Map<String, String> containing execution plan name and execution plans.
 * @throws APITemplateException If template generating fails
 */
private Map<String, String> getSubscriptionPolicySiddhiApps(List<SubscriptionPolicy> subscriptionPolicies) throws APITemplateException {
    if (log.isDebugEnabled()) {
        log.debug("Get execution plans for Subscription policies.");
    }
    Map<String, String> siddhiApps = new HashMap<>();
    String name;
    String executionPlan;
    SubscriptionThrottlePolicyTemplateBuilder templateBuilder;
    for (SubscriptionPolicy policy : subscriptionPolicies) {
        name = SUBSCRIPTION + policy.getPolicyName();
        templateBuilder = new SubscriptionThrottlePolicyTemplateBuilder(policy);
        executionPlan = templateBuilder.getThrottlePolicyForSubscriptionLevel();
        siddhiApps.put(name, executionPlan);
    }
    return siddhiApps;
}
Also used : HashMap(java.util.HashMap) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) SubscriptionThrottlePolicyTemplateBuilder(org.wso2.carbon.apimgt.core.template.SubscriptionThrottlePolicyTemplateBuilder)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)79 ArrayList (java.util.ArrayList)69 Test (org.testng.annotations.Test)58 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)58 Test (org.junit.Test)56 SQLException (java.sql.SQLException)55 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)51 Connection (java.sql.Connection)49 PreparedStatement (java.sql.PreparedStatement)48 ResultSet (java.sql.ResultSet)39 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)37 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)35 APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)34 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)34 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)31 Application (org.wso2.carbon.apimgt.core.models.Application)30 API (org.wso2.carbon.apimgt.core.models.API)28 Response (javax.ws.rs.core.Response)24 Application (org.wso2.carbon.apimgt.api.model.Application)22 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)22