use of org.wso2.carbon.apimgt.api.model.Application in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testUpdateApplicationException.
@Test(description = "Exception when updating an application", expectedExceptions = APIManagementException.class)
public void testUpdateApplicationException() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APIStore apiStore = getApiStoreImpl(applicationDAO);
Application application = new Application(APP_NAME, USER_NAME);
Mockito.doThrow(new APIMgtDAOException("Error occurred while updating the application - " + UUID)).when(applicationDAO).updateApplication(UUID, application);
apiStore.updateApplication(UUID, application);
}
use of org.wso2.carbon.apimgt.api.model.Application 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.Application in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddSubscriptionWorkflowReject.
@Test(description = "Test Subscription workflow rejection")
public void testAddSubscriptionWorkflowReject() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
Policy policy = new SubscriptionPolicy(UUID, TIER);
APIStore apiStore = getApiStoreImpl(apiDAO, applicationDAO, apiSubscriptionDAO, workflowDAO, apiGateway, policyDAO);
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, TIER)).thenReturn(policy);
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
apiBuilder.lifeCycleStatus(APIStatus.PUBLISHED.getStatus());
API api = apiBuilder.build();
String apiId = api.getId();
Application application = new Application("TestApp", USER_ID);
application.setId(UUID);
Mockito.when(apiDAO.getAPI(apiId)).thenReturn(api);
Mockito.when(applicationDAO.getApplication(UUID)).thenReturn(application);
SubscriptionResponse response = apiStore.addApiSubscription(apiId, UUID, TIER);
DefaultWorkflowExecutor executor = Mockito.mock(DefaultWorkflowExecutor.class);
Workflow workflow = new SubscriptionCreationWorkflow(apiSubscriptionDAO, workflowDAO, apiGateway);
workflow.setWorkflowType(APIMgtConstants.WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION);
workflow.setWorkflowReference(response.getSubscriptionUUID());
WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
workflowResponse.setWorkflowStatus(WorkflowStatus.REJECTED);
Mockito.when(executor.complete(workflow)).thenReturn(workflowResponse);
apiStore.completeWorkflow(executor, workflow);
Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).updateSubscriptionStatus(response.getSubscriptionUUID(), SubscriptionStatus.REJECTED);
}
use of org.wso2.carbon.apimgt.api.model.Application in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testDeleteApplicationException.
@Test(description = "Exception when deleting an application", expectedExceptions = APIManagementException.class)
public void testDeleteApplicationException() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APIStore apiStore = getApiStoreImpl(applicationDAO);
Application application = new Application(APP_NAME, USER_NAME);
application.setId(UUID);
Mockito.doThrow(new APIMgtDAOException("Error occurred while deleting the application - " + UUID, new SQLException())).when(applicationDAO).deleteApplication(UUID);
apiStore.deleteApplication(UUID);
Mockito.verify(applicationDAO, Mockito.times(1)).deleteApplication(UUID);
}
use of org.wso2.carbon.apimgt.api.model.Application 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);
}
Aggregations