use of org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy 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.core.models.policy.SubscriptionPolicy in project carbon-apimgt by wso2.
the class ThrottleTemplateBuilderTestCase method testSiddhiQueryForSubscriptionPolicy.
@Test
public void testSiddhiQueryForSubscriptionPolicy() throws APITemplateException {
SubscriptionPolicy policy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
SubscriptionThrottlePolicyTemplateBuilder templateBuilder = new SubscriptionThrottlePolicyTemplateBuilder(policy);
String siddhiQuery = templateBuilder.getThrottlePolicyForSubscriptionLevel();
String sampleQuery = SampleTestObjectCreator.createDefaultSiddhiAppforSubscriptionPolicy();
Assert.assertEquals(siddhiQuery, sampleQuery);
}
use of org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy 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;
}
use of org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy in project carbon-apimgt by wso2.
the class PolicyDAOImpl method getSubscriptionPolicies.
@Override
public List<SubscriptionPolicy> getSubscriptionPolicies() throws APIMgtDAOException {
try {
List<SubscriptionPolicy> policyList = new ArrayList<>();
String sqlQuery = "SELECT UUID, NAME, QUOTA_TYPE, TIME_UNIT, UNIT_TIME, QUOTA, QUOTA_UNIT, DESCRIPTION, " + "DISPLAY_NAME, CUSTOM_ATTRIBUTES, IS_DEPLOYED,RATE_LIMIT_COUNT, RATE_LIMIT_TIME_UNIT, " + "STOP_ON_QUOTA_REACH, BILLING_PLAN FROM AM_SUBSCRIPTION_POLICY";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery)) {
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
policyList.add(createSubscriptionPolicyFromResultSet(resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_NAME), resultSet));
}
}
}
return policyList;
} catch (SQLException e) {
String errorMsg = "Error in retrieving Subscription policies";
log.error(errorMsg, e);
throw new APIMgtDAOException(errorMsg, e);
}
}
use of org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy in project carbon-apimgt by wso2.
the class PolicyDAOImpl method getSubscriptionPolicyById.
/**
* Retrieves {@link SubscriptionPolicy} with policy uuid <code>uuid</code>
* <p>This will retrieve complete details about the ApplicationPolicy with all pipelins and conditions.</p>
*
* @param uuid uuid of the policy to retrieve from the database
* @return {@link SubscriptionPolicy}
*/
private SubscriptionPolicy getSubscriptionPolicyById(String uuid) throws SQLException, APIMgtDAOException {
final String query = "SELECT NAME, UUID, QUOTA_TYPE, TIME_UNIT, UNIT_TIME, QUOTA, QUOTA_UNIT, DESCRIPTION, " + "DISPLAY_NAME, CUSTOM_ATTRIBUTES, IS_DEPLOYED, RATE_LIMIT_COUNT, RATE_LIMIT_TIME_UNIT, " + "STOP_ON_QUOTA_REACH, BILLING_PLAN FROM AM_SUBSCRIPTION_POLICY WHERE UUID = ?";
try (Connection conn = DAOUtil.getConnection();
PreparedStatement statement = conn.prepareStatement(query)) {
statement.setString(1, uuid);
statement.execute();
try (ResultSet rs = statement.getResultSet()) {
if (rs.next()) {
return createSubscriptionPolicyFromResultSet(uuid, rs);
} else {
// not found
String msg = "Subscription Policy not found for id: " + uuid;
log.warn(msg);
throw new APIMgtDAOException(msg, ExceptionCodes.POLICY_NOT_FOUND);
}
}
}
}
Aggregations