Search in sources :

Example 91 with Policy

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);
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) ApplicationCreationResponse(org.wso2.carbon.apimgt.core.workflow.ApplicationCreationResponse) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 92 with Policy

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);
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 93 with Policy

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);
}
Also used : PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 94 with Policy

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());
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) ArrayList(java.util.ArrayList) ApplicationThrottlePolicyListDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ApplicationThrottlePolicyListDTO) Test(org.testng.annotations.Test)

Example 95 with Policy

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);
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) Test(org.testng.annotations.Test)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)114 Test (org.testng.annotations.Test)106 ArrayList (java.util.ArrayList)96 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)79 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)73 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)73 Test (org.junit.Test)72 PreparedStatement (java.sql.PreparedStatement)68 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)64 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)63 SQLException (java.sql.SQLException)62 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)62 Connection (java.sql.Connection)58 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)58 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)54 ResultSet (java.sql.ResultSet)49 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)43 HashMap (java.util.HashMap)40 APIPolicy (org.wso2.carbon.apimgt.api.model.policy.APIPolicy)40 CustomPolicy (org.wso2.carbon.apimgt.core.models.policy.CustomPolicy)40