Search in sources :

Example 21 with ApplicationDAO

use of org.wso2.carbon.apimgt.core.dao.ApplicationDAO in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method testDeleteSubscriptionWithOnholdState.

@Test(description = "Delete subscription with on_hold state")
public void testDeleteSubscriptionWithOnholdState() throws APIManagementException {
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
    WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    APIStore apiStore = getApiStoreImpl(applicationDAO, apiSubscriptionDAO, workflowDAO, apiGateway);
    Application application = SampleTestObjectCreator.createDefaultApplication();
    APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
    API api = builder.build();
    Subscription subscription = new Subscription(UUID, application, api, new SubscriptionPolicy("Gold"));
    subscription.setStatus(SubscriptionStatus.ON_HOLD);
    String externalRef = java.util.UUID.randomUUID().toString();
    Mockito.when(workflowDAO.getExternalWorkflowReferenceForPendingTask(subscription.getId(), WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION)).thenReturn(Optional.of(externalRef));
    Mockito.when(apiSubscriptionDAO.getAPISubscription(UUID)).thenReturn(subscription);
    apiStore.deleteAPISubscription(UUID);
    Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).deleteAPISubscription(UUID);
    Mockito.verify(workflowDAO, Mockito.times(1)).getExternalWorkflowReferenceForPendingTask(subscription.getId(), WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION);
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) 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 22 with ApplicationDAO

use of org.wso2.carbon.apimgt.core.dao.ApplicationDAO in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method testDeleteSubscription.

@Test(description = "Delete subscription")
public void testDeleteSubscription() throws APIManagementException {
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
    WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    APIStore apiStore = getApiStoreImpl(applicationDAO, apiSubscriptionDAO, workflowDAO, apiGateway);
    Application application = SampleTestObjectCreator.createDefaultApplication();
    APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
    API api = builder.build();
    Subscription subscription = new Subscription(UUID, application, api, new SubscriptionPolicy("Gold"));
    Mockito.when(apiSubscriptionDAO.getAPISubscription(UUID)).thenReturn(subscription);
    apiStore.deleteAPISubscription(UUID);
    Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).deleteAPISubscription(UUID);
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) 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 23 with ApplicationDAO

use of org.wso2.carbon.apimgt.core.dao.ApplicationDAO in project carbon-apimgt by wso2.

the class AbstractAPIManagerTestCase method testGetLastUpdatedTimeOfApplicationException.

@Test(description = "Exception when getting last updated time of Application", expectedExceptions = APIManagementException.class)
public void testGetLastUpdatedTimeOfApplicationException() throws APIManagementException {
    ApplicationDAO applicationDAO = mock(ApplicationDAO.class);
    AbstractAPIManager apiStore = getAPIStoreImpl(applicationDAO);
    when(applicationDAO.getLastUpdatedTimeOfApplication(UUID)).thenThrow(new APIMgtDAOException("Error occurred while retrieving the last updated time of the application " + UUID, new SQLException()));
    apiStore.getLastUpdatedTimeOfApplication(UUID);
    verify(applicationDAO, times(0)).getLastUpdatedTimeOfApplication(UUID);
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Test(org.testng.annotations.Test)

Example 24 with ApplicationDAO

use of org.wso2.carbon.apimgt.core.dao.ApplicationDAO in project carbon-apimgt by wso2.

the class AbstractAPIManagerTestCase method testGetApplicationByUuidException.

/**
 * Test cases for exceptions
 */
@Test(description = "Exception when retrieving an application by uuid", expectedExceptions = APIManagementException.class)
public void testGetApplicationByUuidException() throws APIManagementException {
    ApplicationDAO applicationDAO = mock(ApplicationDAO.class);
    AbstractAPIManager apiStore = getAPIStoreImpl(applicationDAO);
    doThrow(new APIMgtDAOException("Error occurred while retrieving application")).when(applicationDAO).getApplication(UUID);
    apiStore.getApplication(UUID, USER_NAME);
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Test(org.testng.annotations.Test)

Example 25 with ApplicationDAO

use of org.wso2.carbon.apimgt.core.dao.ApplicationDAO in project carbon-apimgt by wso2.

the class ApplicationImportExportManagerTestCase method testUpdateApplicationError.

@Test(expected = APIManagementException.class)
public void testUpdateApplicationError() throws Exception {
    printTestMethodName();
    Application testApp = Mockito.mock(Application.class);
    PowerMockito.mockStatic(DAOFactory.class);
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    PowerMockito.when(DAOFactory.getApplicationDAO()).thenReturn(applicationDAO);
    PowerMockito.when(applicationDAO.isApplicationNameExists(Mockito.anyString())).thenReturn(true);
    Mockito.when(apiStore.getApplicationByName(testApp.getName(), USER)).thenReturn(testApp);
    WorkflowResponse workflowResponse = Mockito.mock(WorkflowResponse.class);
    Mockito.when(apiStore.updateApplication(testApp.getUuid(), testApp)).thenReturn(workflowResponse);
    Mockito.when(apiStore.getApplication(testApp.getUuid(), USER)).thenThrow(new APIMgtDAOException("Error occurred while finding application matching the provided name"));
    applicationImportExportManager.updateApplication(testApp, USER);
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)62 Test (org.testng.annotations.Test)56 Application (org.wso2.carbon.apimgt.core.models.Application)50 BeforeTest (org.testng.annotations.BeforeTest)32 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)32 WorkflowDAO (org.wso2.carbon.apimgt.core.dao.WorkflowDAO)21 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)18 APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)18 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)15 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)15 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)13 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)13 API (org.wso2.carbon.apimgt.core.models.API)12 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)10 SQLException (java.sql.SQLException)8 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)7 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)6 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)5 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)5 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)4