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