use of org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy in project carbon-apimgt by wso2.
the class PoliciesApiServiceImplTest method policiesThrottlingApplicationPolicyIdPutTest.
@Test
public void policiesThrottlingApplicationPolicyIdPutTest() throws APIManagementException, NotFoundException {
printTestMethodName();
PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
String uuid = UUID.randomUUID().toString();
ApplicationThrottlePolicyDTO dto = new ApplicationThrottlePolicyDTO();
ApplicationPolicy policy = ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyDTOToModel(dto);
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
Mockito.doNothing().doThrow(new IllegalArgumentException()).when(adminService).updateApplicationPolicy(policy);
Mockito.doReturn(policy).doThrow(new IllegalArgumentException()).when(adminService).getApplicationPolicyByUuid(uuid);
Response response = policiesApiService.policiesThrottlingApplicationIdPut(uuid, dto, null, null, getRequest());
Assert.assertEquals(response.getStatus(), 200);
}
use of org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testUpdateApplicationPolicy.
@Test(description = "Test update application policy")
public void testUpdateApplicationPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
ApplicationPolicy applicationPolicy = SampleTestObjectCreator.createDefaultApplicationPolicy();
adminService.updateApplicationPolicy(applicationPolicy);
Mockito.verify(policyDAO, Mockito.times(1)).updateApplicationPolicy(applicationPolicy);
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).updateApplicationPolicy(applicationPolicy);
try {
adminService.updateApplicationPolicy(applicationPolicy);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't update Application policy for uuid: " + applicationPolicy.getUuid());
}
}
use of org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testAddApplicationPolicyWhenPolicyIdNull.
@Test(description = "Test add application policy when the policy ID is null")
public void testAddApplicationPolicyWhenPolicyIdNull() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
ApplicationPolicy policy = SampleTestObjectCreator.createDefaultApplicationPolicy();
policy.setUuid(null);
adminService.addApplicationPolicy(policy);
Mockito.verify(policyDAO, Mockito.times(1)).addApplicationPolicy(policy);
}
use of org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetApplicationPolicyByUuid.
@Test(description = "Test getting Application policy by UUID")
public void testGetApplicationPolicyByUuid() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
ApplicationPolicy applicationPolicy = SampleTestObjectCreator.createDefaultApplicationPolicy();
Mockito.when(policyDAO.getApplicationPolicyByUuid(applicationPolicy.getUuid())).thenReturn(applicationPolicy);
adminService.getApplicationPolicyByUuid(applicationPolicy.getUuid());
Mockito.verify(policyDAO, Mockito.times(1)).getApplicationPolicyByUuid(applicationPolicy.getUuid());
// Error path
Mockito.when(policyDAO.getApplicationPolicyByUuid(applicationPolicy.getUuid())).thenThrow(APIMgtDAOException.class);
try {
adminService.getApplicationPolicyByUuid(applicationPolicy.getUuid());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't retrieve Application policy with id: " + applicationPolicy.getUuid());
}
}
use of org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy in project carbon-apimgt by wso2.
the class ThrottleTemplateBuilderTestCase method testSiddiQueryForApp.
@Test
public void testSiddiQueryForApp() throws APITemplateException {
ApplicationPolicy policy = SampleTestObjectCreator.createDefaultApplicationPolicy();
ApplicationThrottlePolicyTemplateBuilder templateBuilder = new ApplicationThrottlePolicyTemplateBuilder(policy);
String siddhiQuery = templateBuilder.getThrottlePolicyForAppLevel();
String sampleQuery = SampleTestObjectCreator.createDefaultSiddhiAppforAppPolicy();
Assert.assertEquals(siddhiQuery, sampleQuery);
}
Aggregations