use of org.wso2.carbon.apimgt.keymgt.model.entity.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());
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.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());
}
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.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);
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.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;
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.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;
}
Aggregations