use of org.wso2.carbon.apimgt.api.model.APIStore 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);
}
use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddComment.
@Test(description = "Add comment")
public void testAddComment() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIStore apiStore = getApiStoreImpl(apiDAO);
API api = SampleTestObjectCreator.createDefaultAPI().build();
Mockito.when(apiDAO.isAPIExists(api.getId())).thenReturn(true);
Comment comment = SampleTestObjectCreator.createDefaultComment(api.getId());
apiStore.addComment(comment, api.getId());
Mockito.verify(apiDAO, Mockito.times(1)).isAPIExists(api.getId());
Mockito.verify(apiDAO, Mockito.times(1)).addComment(comment, api.getId());
}
use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method getAllLabelsException.
@Test(description = "get all labels Exception", expectedExceptions = Exception.class)
public void getAllLabelsException() throws Exception {
LabelDAO labelDao = Mockito.mock(LabelDAO.class);
APIStore apiStore = getApiStoreImpl();
List<Label> labels = new ArrayList<>();
Label label = new Label.Builder().id("123").name("Default").type("STORE").accessUrls(new ArrayList<>()).build();
labels.add(label);
Mockito.when(labelDao.getLabels()).thenReturn(labels);
Mockito.doThrow(new LabelException("Error occurred while retrieving labels ")).when(labelDao).getLabels();
apiStore.getAllLabels();
}
use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetLabelInfo.
@Test(description = "Retrieve labels")
public void testGetLabelInfo() throws APIManagementException {
LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
APIStore apiStore = getApiStoreImpl(labelDAO);
List<Label> labelList = new ArrayList<>();
List<String> labelNames = new ArrayList<>();
Label label = SampleTestObjectCreator.createLabel("Public", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
labelList.add(label);
labelNames.add(label.getName());
Mockito.when(labelDAO.getLabelsByName(labelNames)).thenReturn(labelList);
List<Label> returnedLabels = apiStore.getLabelInfo(labelNames, USER_NAME);
Assert.assertEquals(returnedLabels, labelList);
Mockito.verify(labelDAO, Mockito.times(1)).getLabelsByName(labelNames);
}
use of org.wso2.carbon.apimgt.api.model.APIStore 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);
}
Aggregations