Search in sources :

Example 91 with ApplicationPolicy

use of org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method testGetAPISubscriptionsByApplicationException.

@Test(description = "Exception when getting API subscriptions by application", expectedExceptions = APIManagementException.class)
public void testGetAPISubscriptionsByApplicationException() throws APIManagementException {
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
    APIStore apiStore = getApiStoreImpl(applicationDAO, apiSubscriptionDAO);
    Application application = new Application(APP_NAME, USER_NAME);
    application.setPolicy(new ApplicationPolicy(TIER));
    application.setId(UUID);
    Mockito.when(apiSubscriptionDAO.getAPISubscriptionsByApplication(application.getId())).thenThrow(new APIMgtDAOException("Error occurred while retrieving subscriptions for application - " + application.getName(), new SQLException()));
    apiStore.getAPISubscriptionsByApplication(application);
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) SQLException(java.sql.SQLException) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 92 with ApplicationPolicy

use of org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy in project carbon-apimgt by wso2.

the class PoliciesApiServiceImplTest method policiesThrottlingApplicationGetTest.

@Test
public void policiesThrottlingApplicationGetTest() throws APIManagementException, NotFoundException {
    printTestMethodName();
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    ApplicationPolicy policy1 = new ApplicationPolicy("sampleAppPolicy1");
    ApplicationPolicy policy2 = new ApplicationPolicy("sampleAppPolicy2");
    List<ApplicationPolicy> policies = new ArrayList<>();
    policies.add(policy1);
    policies.add(policy2);
    Mockito.doReturn(policies).doThrow(new IllegalArgumentException()).when(adminService).getApplicationPolicies();
    Response response = policiesApiService.policiesThrottlingApplicationGet(null, null, getRequest());
    Assert.assertEquals(response.getStatus(), 200);
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) PoliciesApiServiceImpl(org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) ArrayList(java.util.ArrayList) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 93 with ApplicationPolicy

use of org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy in project carbon-apimgt by wso2.

the class PoliciesApiServiceImplTest method policiesThrottlingApplicationPolicyIdGetTest.

@Test
public void policiesThrottlingApplicationPolicyIdGetTest() throws APIManagementException, NotFoundException {
    printTestMethodName();
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    String uuid = UUID.randomUUID().toString();
    ApplicationPolicy policy = new ApplicationPolicy(uuid, "SampleApplicationPolicy");
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    Mockito.doReturn(policy).doThrow(new IllegalArgumentException()).when(adminService).getApplicationPolicyByUuid(uuid);
    Response response = policiesApiService.policiesThrottlingApplicationIdGet(uuid, null, null, getRequest());
    Assert.assertEquals(response.getStatus(), 200);
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) PoliciesApiServiceImpl(org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 94 with ApplicationPolicy

use of org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy in project carbon-apimgt by wso2.

the class ApplicationThrottlePolicyMappingUtilTest method fromApplicationThrottlePolicyToDTOTest.

@Test(description = "Convert from Policy to DTO")
public void fromApplicationThrottlePolicyToDTOTest() throws Exception {
    Policy policy = new ApplicationPolicy(uuid, policyName);
    QuotaPolicy quotaPolicy = new QuotaPolicy();
    RequestCountLimit requestCountLimit = new RequestCountLimit("s", 1000, 10000);
    quotaPolicy.setLimit(requestCountLimit);
    quotaPolicy.setType(REQUEST_COUNT_TYPE);
    policy.setDefaultQuotaPolicy(quotaPolicy);
    policy.setDisplayName(displayName);
    ApplicationThrottlePolicyDTO dto = ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyToDTO(policy);
    Assert.assertNotNull(dto);
    Assert.assertEquals(dto.getDisplayName(), displayName);
    Assert.assertNotNull(dto.getPolicyName(), policyName);
    Assert.assertEquals(dto.getId(), uuid);
    Assert.assertEquals(dto.getDefaultLimit().getRequestCountLimit().getRequestCount().intValue(), requestCountLimit.getRequestCount());
    Assert.assertEquals(dto.getDisplayName(), displayName);
}
Also used : Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) ApplicationThrottlePolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ApplicationThrottlePolicyDTO) Test(org.testng.annotations.Test)

Example 95 with ApplicationPolicy

use of org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy in project carbon-apimgt by wso2.

the class ApplicationThrottlePolicyMappingUtilTest method fromApplicationThrottlePolicyDTOToModelTest.

@Test(description = "Convert from DTO to Policy")
public void fromApplicationThrottlePolicyDTOToModelTest() throws Exception {
    ApplicationThrottlePolicyDTO dto = new ApplicationThrottlePolicyDTO();
    dto.setDisplayName(displayName);
    dto.setPolicyName(policyName);
    dto.setId(uuid);
    ThrottleLimitDTO throttleLimitDTO = new ThrottleLimitDTO();
    throttleLimitDTO.setType("RequestCountLimit");
    throttleLimitDTO.setTimeUnit("s");
    throttleLimitDTO.setUnitTime(1);
    RequestCountLimitDTO requestCountLimitDTO = new RequestCountLimitDTO();
    requestCountLimitDTO.setRequestCount(2);
    throttleLimitDTO.setRequestCountLimit(requestCountLimitDTO);
    dto.setDefaultLimit(throttleLimitDTO);
    ApplicationPolicy policy = ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyDTOToModel(dto);
    Assert.assertNotNull(policy);
    Assert.assertEquals(policy.getDisplayName(), displayName);
    Assert.assertEquals(policy.getPolicyName(), policyName);
    Assert.assertEquals(policy.getDefaultQuotaPolicy().getType(), "requestCount");
    Assert.assertEquals(policy.getDefaultQuotaPolicy().getLimit().getTimeUnit(), dto.getDefaultLimit().getTimeUnit());
    Assert.assertEquals((Integer) policy.getDefaultQuotaPolicy().getLimit().getUnitTime(), dto.getDefaultLimit().getUnitTime());
    Assert.assertEquals((Integer) ((RequestCountLimit) policy.getDefaultQuotaPolicy().getLimit()).getRequestCount(), dto.getDefaultLimit().getRequestCountLimit().getRequestCount());
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) RequestCountLimitDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.RequestCountLimitDTO) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) ThrottleLimitDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleLimitDTO) ApplicationThrottlePolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ApplicationThrottlePolicyDTO) Test(org.testng.annotations.Test)

Aggregations

ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)56 Test (org.testng.annotations.Test)30 ApplicationPolicy (org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy)29 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)24 ArrayList (java.util.ArrayList)23 Test (org.junit.Test)18 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)18 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)18 Application (org.wso2.carbon.apimgt.core.models.Application)17 Connection (java.sql.Connection)16 PreparedStatement (java.sql.PreparedStatement)16 SQLException (java.sql.SQLException)16 ResultSet (java.sql.ResultSet)13 BeforeTest (org.testng.annotations.BeforeTest)13 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)13 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)13 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)13 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)13 APIPolicy (org.wso2.carbon.apimgt.api.model.policy.APIPolicy)12 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)12