use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddApplicationUpdateWorkflowReject.
@Test(description = "Test Application update workflow reject")
public void testAddApplicationUpdateWorkflowReject() throws APIManagementException {
/*
* This test is to validate the rollback the application to its previous state for application
* update request rejection
*/
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
Policy policy = Mockito.mock(Policy.class);
APIStore apiStore = getApiStoreImpl(applicationDAO, policyDAO, workflowDAO);
Application application = new Application(APP_NAME, USER_NAME);
application.setStatus(ApplicationStatus.APPLICATION_APPROVED);
application.setPolicy(new ApplicationPolicy(TIER));
application.setId(UUID);
application.setPermissionString("[{\"groupId\": \"testGroup\",\"permission\":[\"READ\",\"UPDATE\",\"DELETE\",\"SUBSCRIPTION\"]}]");
Mockito.when(applicationDAO.isApplicationNameExists(APP_NAME)).thenReturn(false);
Mockito.when(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, TIER)).thenReturn(policy);
// following section mock the workflow callback api
DefaultWorkflowExecutor executor = Mockito.mock(DefaultWorkflowExecutor.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
Workflow workflow = new ApplicationUpdateWorkflow(applicationDAO, workflowDAO, apiGateway);
workflow.setWorkflowReference(application.getId());
workflow.setExternalWorkflowReference(UUID);
// validate the rejection flow
// here we assume the application is an approve state before update
// this attribute is set internally based on the workflow data
workflow.setAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_EXISTIN_APP_STATUS, ApplicationStatus.APPLICATION_APPROVED);
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(), ApplicationStatus.APPLICATION_APPROVED);
// here we assume the application is an rejected state before update.
workflow.setAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_EXISTIN_APP_STATUS, ApplicationStatus.APPLICATION_REJECTED);
apiStore.completeWorkflow(executor, workflow);
Mockito.verify(applicationDAO, Mockito.times(1)).updateApplicationState(application.getId(), ApplicationStatus.APPLICATION_REJECTED);
}
use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddCommentApiMissingException.
@Test(description = "Exception when adding a comment due to missing api", expectedExceptions = APIManagementException.class)
public void testAddCommentApiMissingException() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIStore apiStore = getApiStoreImpl(apiDAO);
String randomUUIDForApi = java.util.UUID.randomUUID().toString();
Mockito.when(apiDAO.getAPI(randomUUIDForApi)).thenReturn(null);
Comment comment = SampleTestObjectCreator.createDefaultComment(randomUUIDForApi);
apiStore.addComment(comment, randomUUIDForApi);
}
use of org.wso2.carbon.apimgt.api.model.APIStore 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.APIStore 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.APIStore in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetDedicatedGatewayForException.
@Test(description = "Get dedicated gateway exception scenario", expectedExceptions = APIManagementException.class)
public void testGetDedicatedGatewayForException() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
DedicatedGateway dedicatedGateway = new DedicatedGateway();
dedicatedGateway.setEnabled(true);
APIStoreImpl apiStore = getApiStoreImpl(apiDAO);
Mockito.when(apiDAO.getDedicatedGateway(Mockito.anyString())).thenThrow(APIMgtDAOException.class);
apiStore.getDedicatedGateway(Mockito.anyString());
}
Aggregations