use of org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddApplication.
@Test(description = "Add an application")
public void testAddApplication() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
Policy policy = Mockito.mock(Policy.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("[{\"groupId\": \"testGroup\",\"permission\":[\"READ\",\"UPDATE\",\"DELETE\",\"SUBSCRIPTION\"]}]");
Mockito.when(applicationDAO.isApplicationNameExists(APP_NAME)).thenReturn(false);
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, TIER)).thenReturn(policy);
ApplicationCreationResponse response = apiStore.addApplication(application);
Assert.assertNotNull(response.getApplicationUUID());
Mockito.verify(applicationDAO, Mockito.times(1)).addApplication(application);
}
use of org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddApplicationPermissionStringEmpty.
@Test(description = "Add an application with empty permission String")
public void testAddApplicationPermissionStringEmpty() 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("");
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.ApplicationPolicy in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddApplicationWorkflowReject.
@Test(description = "Test Application workflow rejection")
public void testAddApplicationWorkflowReject() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
Policy policy = Mockito.mock(Policy.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("[{\"groupId\": \"testGroup\",\"permission\":[\"READ\",\"UPDATE\",\"DELETE\",\"SUBSCRIPTION\"]}]");
Mockito.when(applicationDAO.isApplicationNameExists(APP_NAME)).thenReturn(false);
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, TIER)).thenReturn(policy);
apiStore.addApplication(application);
DefaultWorkflowExecutor executor = Mockito.mock(DefaultWorkflowExecutor.class);
Workflow workflow = new ApplicationCreationWorkflow(applicationDAO, workflowDAO, apiGateway);
workflow.setWorkflowReference(application.getId());
WorkflowResponse response = new GeneralWorkflowResponse();
response.setWorkflowStatus(WorkflowStatus.REJECTED);
Mockito.when(executor.complete(workflow)).thenReturn(response);
apiStore.completeWorkflow(executor, workflow);
Mockito.verify(applicationDAO, Mockito.times(1)).updateApplicationState(application.getId(), "REJECTED");
}
use of org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy 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.ApplicationPolicy 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());
}
Aggregations