use of org.wso2.carbon.apimgt.core.dao.WorkflowDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddApplicationWithDuplicateName.
@Test(description = "Add application with duplicate name", expectedExceptions = APIMgtResourceAlreadyExistsException.class)
public void testAddApplicationWithDuplicateName() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
APIStore apiStore = getApiStoreImpl(applicationDAO, workflowDAO);
Application application = new Application(APP_NAME, USER_NAME);
Mockito.when(applicationDAO.isApplicationNameExists(APP_NAME)).thenReturn(true);
apiStore.addApplication(application);
}
use of org.wso2.carbon.apimgt.core.dao.WorkflowDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddSubscriptionForInvalidApplication.
@Test(description = "Add subscription without a valid app", expectedExceptions = APIManagementException.class)
public void testAddSubscriptionForInvalidApplication() 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);
APIStore apiStore = getApiStoreImpl(apiDAO, applicationDAO, apiSubscriptionDAO, workflowDAO, apiGateway);
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
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(null);
SubscriptionResponse subscriptionResponse = apiStore.addApiSubscription(apiId, UUID, TIER);
String subscriptionId = subscriptionResponse.getSubscriptionUUID();
Assert.assertNotNull(subscriptionId);
// subscription should not be added
Mockito.verify(apiSubscriptionDAO, Mockito.times(0)).addAPISubscription(subscriptionId, apiId, UUID, TIER, APIMgtConstants.SubscriptionStatus.ON_HOLD);
}
use of org.wso2.carbon.apimgt.core.dao.WorkflowDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testDeleteApplicationWithOnHoldState.
@Test(description = "Delete application which is in on_hold state")
public void testDeleteApplicationWithOnHoldState() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APISubscriptionDAO subscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIStore apiStore = getApiStoreImpl(applicationDAO, subscriptionDAO, workflowDAO, apiGateway);
Application application = SampleTestObjectCreator.createDefaultApplication();
application.setStatus(APIMgtConstants.ApplicationStatus.APPLICATION_ONHOLD);
application.setId(UUID);
String externalRef = java.util.UUID.randomUUID().toString();
Mockito.when(applicationDAO.getApplication(UUID)).thenReturn(application);
Mockito.when(workflowDAO.getExternalWorkflowReferenceForPendingTask(application.getId(), WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION)).thenReturn(Optional.of(externalRef));
Mockito.when(workflowDAO.getExternalWorkflowReferenceForPendingTask(application.getId(), WorkflowConstants.WF_TYPE_AM_APPLICATION_UPDATE)).thenReturn(Optional.of(externalRef));
apiStore.deleteApplication(UUID);
Mockito.verify(applicationDAO, Mockito.times(1)).deleteApplication(UUID);
Mockito.verify(workflowDAO, Mockito.times(1)).getExternalWorkflowReferenceForPendingTask(application.getId(), WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION);
Mockito.verify(workflowDAO, Mockito.times(1)).getExternalWorkflowReferenceForPendingTask(application.getId(), WorkflowConstants.WF_TYPE_AM_APPLICATION_UPDATE);
}
use of org.wso2.carbon.apimgt.core.dao.WorkflowDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddApplicationPermissionStringInvalid.
@Test(description = "Add an application with invalid permission String")
public void testAddApplicationPermissionStringInvalid() 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("[{\"groupId\": \"testGroup\",\"permission\":[\"TESTREAD\",\"TESTUPDATE\"]}]");
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);
}
use of org.wso2.carbon.apimgt.core.dao.WorkflowDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddApplicationNullTier.
@Test(description = "Add an application with null tier", expectedExceptions = APIManagementException.class)
public void testAddApplicationNullTier() throws Exception {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
APIStore apiStore = getApiStoreImpl(applicationDAO, policyDAO, workflowDAO);
Application application = new Application(APP_NAME, USER_NAME);
application.setPolicy(new ApplicationPolicy(null));
Mockito.when(applicationDAO.isApplicationNameExists(APP_NAME)).thenReturn(false);
apiStore.addApplication(application);
}
Aggregations