use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApiPolicy in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testAddPolicyWhenPolicyIdNull.
@Test(description = "Add policy when policy id is null")
public void testAddPolicyWhenPolicyIdNull() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
APIPolicy policy = SampleTestObjectCreator.createDefaultAPIPolicy();
policy.setUuid(null);
adminService.addApiPolicy(policy);
Mockito.verify(policyDAO, Mockito.times(1)).addApiPolicy(policy);
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApiPolicy in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testUpdateApiPolicy.
@Test(description = "Test update API policy")
public void testUpdateApiPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
adminService.updateApiPolicy(apiPolicy);
Mockito.verify(policyDAO, Mockito.times(1)).updateApiPolicy(apiPolicy);
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).updateApiPolicy(apiPolicy);
try {
adminService.updateApiPolicy(apiPolicy);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't update API policy for uuid: " + apiPolicy.getUuid());
}
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApiPolicy in project carbon-apimgt by wso2.
the class ThrottleTemplateBuilderTestCase method testSiddhiQueryForAPIPolicy.
@Test
public void testSiddhiQueryForAPIPolicy() throws APITemplateException {
APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
APIThrottlePolicyTemplateBuilder templateBuilder = new APIThrottlePolicyTemplateBuilder(apiPolicy);
Map<String, String> siddhiQueryMap = templateBuilder.getThrottlePolicyTemplateForPipelines();
String actualQuery = siddhiQueryMap.get("resource_SampleAPIPolicy_condition_0");
String expectedQuery = SampleTestObjectCreator.createDefaultSiddhiAppForAPIThrottlePolicy();
Assert.assertEquals(actualQuery, expectedQuery);
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApiPolicy in project carbon-apimgt by wso2.
the class ThrottleTemplateBuilderTestCase method testSiddhiQueryForAPILevelDefaultConditions.
@Test
public void testSiddhiQueryForAPILevelDefaultConditions() throws APITemplateException {
APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
APIThrottlePolicyTemplateBuilder templateBuilder = new APIThrottlePolicyTemplateBuilder(apiPolicy);
String actualQuery = templateBuilder.getThrottlePolicyTemplateForAPILevelDefaultCondition();
String expectedQuery = SampleTestObjectCreator.createDefaultSiddhiAppForAPILevelDefaultThrottlePolicy();
Assert.assertEquals(actualQuery, expectedQuery);
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApiPolicy in project carbon-apimgt by wso2.
the class PolicyExportManager method getApiPolicySiddhiApps.
/**
* Get execution plan/ siddhi apps for custom policies.
*
* @param apiPolicies APIPolicy object list
* @return Map<String, String> containing execution plan name and execution plans.
* @throws APITemplateException If template generating fails
*/
private List<Map<String, String>> getApiPolicySiddhiApps(List<APIPolicy> apiPolicies) throws APITemplateException {
if (log.isDebugEnabled()) {
log.debug("Get execution plans for API policies.");
}
List<Map<String, String>> policies = new ArrayList<>();
Map<String, String> siddhiApps = new HashMap<>();
APIThrottlePolicyTemplateBuilder templateBuilder;
for (APIPolicy apiPolicy : apiPolicies) {
templateBuilder = new APIThrottlePolicyTemplateBuilder(apiPolicy);
if (apiPolicy.getPipelines() != null) {
siddhiApps = templateBuilder.getThrottlePolicyTemplateForPipelines();
}
siddhiApps.put(RESOURCE + apiPolicy.getPolicyName() + DEFAULT, templateBuilder.getThrottlePolicyTemplateForAPILevelDefaultCondition());
policies.add(siddhiApps);
}
return policies;
}
Aggregations