use of org.wso2.carbon.apimgt.api.model.policy.Policy in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddApplicationPermissionStringNull.
@Test(description = "Add an application with null permission String")
public void testAddApplicationPermissionStringNull() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
Policy policy = Mockito.mock(Policy.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIStore apiStore = getApiStoreImpl(applicationDAO, policyDAO, workflowDAO, apiGateway);
Application application = new Application(APP_NAME, USER_NAME);
application.setPolicy(new ApplicationPolicy(TIER));
application.setPermissionString(null);
Mockito.when(applicationDAO.isApplicationNameExists(APP_NAME)).thenReturn(false);
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, TIER)).thenReturn(policy);
ApplicationCreationResponse applicationResponse = apiStore.addApplication(application);
String applicationUuid = applicationResponse.getApplicationUUID();
Assert.assertNotNull(applicationUuid);
Mockito.verify(applicationDAO, Mockito.times(1)).addApplication(application);
}
use of org.wso2.carbon.apimgt.api.model.policy.Policy in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetPoliciesException.
@Test(description = "Exception when getting all policies of a specific policy level", expectedExceptions = APIManagementException.class)
public void testGetPoliciesException() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIStore apiStore = getApiStoreImpl(policyDAO);
Mockito.when(policyDAO.getPoliciesByLevel(APIMgtAdminService.PolicyLevel.application)).thenThrow(new APIMgtDAOException("Error occurred while retrieving policies for policy level - " + APPLICATION_POLICY_LEVEL, new SQLException()));
apiStore.getPolicies(APIMgtAdminService.PolicyLevel.application);
}
use of org.wso2.carbon.apimgt.api.model.policy.Policy in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetPolicies.
@Test(description = "Get all policies of a specific policy level")
public void testGetPolicies() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIStore apiStore = getApiStoreImpl(policyDAO);
apiStore.getPolicies(APIMgtAdminService.PolicyLevel.application);
Mockito.verify(policyDAO, Mockito.times(1)).getPoliciesByLevel(APIMgtAdminService.PolicyLevel.application);
}
use of org.wso2.carbon.apimgt.api.model.policy.Policy in project carbon-apimgt by wso2.
the class ApplicationThrottlePolicyMappingUtilTest method testFromApplicationPolicyArrayToListDTO.
@Test(description = "Convert from Policy Array to DTO")
public void testFromApplicationPolicyArrayToListDTO() throws Exception {
List<ApplicationPolicy> appPolicies = new ArrayList<>();
ApplicationPolicy policy1 = SampleTestObjectCreator.createApplicationPolicyWithRequestLimit("Gold");
ApplicationPolicy policy2 = SampleTestObjectCreator.createApplicationPolicyWithRequestLimit("Silver");
appPolicies.add(policy1);
appPolicies.add(policy2);
ApplicationThrottlePolicyListDTO listDTO = ApplicationThrottlePolicyMappingUtil.fromApplicationPolicyArrayToListDTO(appPolicies);
Assert.assertEquals(listDTO.getCount(), (Integer) appPolicies.size());
Assert.assertNotNull(listDTO.getList().get(0).getPolicyName(), policy1.getPolicyName());
Assert.assertEquals(listDTO.getList().get(0).getId(), policy1.getUuid());
Assert.assertEquals(listDTO.getList().get(0).getDefaultLimit().getRequestCountLimit().getRequestCount().intValue(), ((RequestCountLimit) policy1.getDefaultQuotaPolicy().getLimit()).getRequestCount());
Assert.assertEquals(listDTO.getList().get(0).getDisplayName(), policy1.getDisplayName());
Assert.assertNotNull(listDTO.getList().get(1).getPolicyName(), policy2.getPolicyName());
Assert.assertEquals(listDTO.getList().get(1).getId(), policy2.getUuid());
Assert.assertEquals(listDTO.getList().get(1).getDefaultLimit().getRequestCountLimit().getRequestCount().intValue(), ((RequestCountLimit) policy2.getDefaultQuotaPolicy().getLimit()).getRequestCount());
Assert.assertEquals(listDTO.getList().get(1).getDisplayName(), policy2.getDisplayName());
}
use of org.wso2.carbon.apimgt.api.model.policy.Policy in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtilTestCase method fromRequestCountThrottleLimitDtoToQuotaPolicyTest.
@Test(description = "Convert Request Count Throttle Limit DTO to Quota Policy")
public void fromRequestCountThrottleLimitDtoToQuotaPolicyTest() throws Exception {
ThrottleLimitDTO throttleLimitDTO = new ThrottleLimitDTO();
throttleLimitDTO.setType(PolicyConstants.REQUEST_COUNT_LIMIT_TYPE);
RequestCountLimitDTO requestCountLimitDTO = new RequestCountLimitDTO();
requestCountLimitDTO.setRequestCount(100);
throttleLimitDTO.setRequestCountLimit(requestCountLimitDTO);
throttleLimitDTO.setTimeUnit("sec");
throttleLimitDTO.setUnitTime(1);
QuotaPolicy policy = CommonThrottleMappingUtil.fromDTOToQuotaPolicy(throttleLimitDTO);
Assert.assertNotNull(policy);
RequestCountLimit limit = (RequestCountLimit) policy.getLimit();
Assert.assertNotNull(limit);
assertEquals(limit.getRequestCount(), 100);
assertEquals(limit.getTimeUnit(), "sec");
assertEquals(limit.getUnitTime(), 1);
}
Aggregations