Search in sources :

Example 96 with Application

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);
}
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 97 with 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);
}
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 98 with 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);
}
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) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) 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) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) SubscriptionCreationWorkflow(org.wso2.carbon.apimgt.core.workflow.SubscriptionCreationWorkflow) WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) SubscriptionResponse(org.wso2.carbon.apimgt.core.models.SubscriptionResponse) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) Application(org.wso2.carbon.apimgt.core.models.Application) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) 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 99 with Application

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);
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) 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 100 with Application

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);
}
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)

Aggregations

Test (org.testng.annotations.Test)156 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)143 Application (org.wso2.carbon.apimgt.api.model.Application)130 Application (org.wso2.carbon.apimgt.core.models.Application)121 Test (org.junit.Test)102 ArrayList (java.util.ArrayList)98 SQLException (java.sql.SQLException)94 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)94 PreparedStatement (java.sql.PreparedStatement)88 Connection (java.sql.Connection)83 ResultSet (java.sql.ResultSet)73 Subscriber (org.wso2.carbon.apimgt.api.model.Subscriber)71 HashMap (java.util.HashMap)70 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)63 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)63 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)61 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)60 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)59 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)58 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)57