Search in sources :

Example 76 with APIStore

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);
}
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) ApplicationUpdateWorkflow(org.wso2.carbon.apimgt.core.workflow.ApplicationUpdateWorkflow) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Workflow(org.wso2.carbon.apimgt.core.workflow.Workflow) ApplicationCreationWorkflow(org.wso2.carbon.apimgt.core.workflow.ApplicationCreationWorkflow) ApplicationUpdateWorkflow(org.wso2.carbon.apimgt.core.workflow.ApplicationUpdateWorkflow) SubscriptionCreationWorkflow(org.wso2.carbon.apimgt.core.workflow.SubscriptionCreationWorkflow) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) DefaultWorkflowExecutor(org.wso2.carbon.apimgt.core.workflow.DefaultWorkflowExecutor) WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) 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 77 with APIStore

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

Example 78 with APIStore

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);
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) 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 79 with APIStore

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);
}
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 80 with APIStore

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

Aggregations

APIStore (org.wso2.carbon.apimgt.core.api.APIStore)226 Test (org.testng.annotations.Test)109 Test (org.junit.Test)98 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)96 BeforeTest (org.testng.annotations.BeforeTest)93 Response (javax.ws.rs.core.Response)90 Request (org.wso2.msf4j.Request)87 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)72 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)56 API (org.wso2.carbon.apimgt.core.models.API)51 HashMap (java.util.HashMap)49 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)49 ArrayList (java.util.ArrayList)47 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)47 Application (org.wso2.carbon.apimgt.core.models.Application)46 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)38 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)32 SQLException (java.sql.SQLException)31 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)31 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)29