use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testDeleteCommentApiMissingException.
@Test(description = "Exception when deleting a comment due to missing api", expectedExceptions = APIManagementException.class)
public void testDeleteCommentApiMissingException() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIStore apiStore = getApiStoreImpl(apiDAO);
String randomUUIDForApi = java.util.UUID.randomUUID().toString();
Mockito.when(apiDAO.getAPI(randomUUIDForApi)).thenReturn(null);
String randomUUIDForComment = java.util.UUID.randomUUID().toString();
apiStore.deleteComment(randomUUIDForComment, randomUUIDForApi, "admin");
}
use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetAPIWSDLArchive.
@Test(description = "Retrieve a WSDL archive of an API")
public void testGetAPIWSDLArchive() throws APIManagementException, IOException {
final String labelName = "SampleLabel";
Label label = SampleTestObjectCreator.createLabel(labelName, SampleTestObjectCreator.LABEL_TYPE_STORE).build();
List<String> labels = new ArrayList<>();
labels.add(label.getName());
API api = SampleTestObjectCreator.createDefaultAPI().labels(labels).build();
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
APIStore apiStore = getApiStoreImpl(apiDAO, labelDAO);
Mockito.when(apiDAO.getAPI(api.getId())).thenReturn(api);
Mockito.when(labelDAO.getLabelByName(labelName)).thenReturn(label);
Mockito.when(apiDAO.getWSDLArchive(api.getId())).thenReturn(SampleTestObjectCreator.createDefaultWSDL11ArchiveInputStream());
String expectedEndpoint = SampleTestObjectCreator.ACCESS_URL + labelName + (api.getContext().startsWith("/") ? api.getContext() : "/" + api.getContext());
WSDLArchiveInfo archiveInfo = apiStore.getAPIWSDLArchive(api.getId(), label.getName());
Assert.assertNotNull(archiveInfo);
Assert.assertNotNull(archiveInfo.getWsdlInfo());
Assert.assertNotNull(archiveInfo.getWsdlInfo().getEndpoints());
Map<String, String> endpoints = archiveInfo.getWsdlInfo().getEndpoints();
Assert.assertTrue(endpoints.containsValue(expectedEndpoint));
Assert.assertFalse(endpoints.containsValue(SampleTestObjectCreator.ORIGINAL_ENDPOINT_STOCK_QUOTE));
Assert.assertFalse(endpoints.containsValue(SampleTestObjectCreator.ORIGINAL_ENDPOINT_WEATHER));
}
use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testCompleteApplicationWorkflowWithoutReference.
// End of exception testing
@Test(description = "Exception when completing application creation workflow without a reference", expectedExceptions = APIManagementException.class)
public void testCompleteApplicationWorkflowWithoutReference() throws Exception {
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APIStore apiStore = getApiStoreImpl(applicationDAO, workflowDAO);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
WorkflowExecutor executor = new DefaultWorkflowExecutor();
Workflow workflow = new ApplicationCreationWorkflow(applicationDAO, workflowDAO, apiGateway);
workflow.setWorkflowReference(null);
apiStore.completeWorkflow(executor, workflow);
}
use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddRatingDaoException.
/**
* Tests to catch exceptions in methods
*/
@Test(description = "Add rating exception in dao", expectedExceptions = APIRatingException.class)
public void testAddRatingDaoException() 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);
Rating rating = SampleTestObjectCreator.createDefaultRating(api.getId());
Mockito.when(apiDAO.getRatingByUUID(api.getId(), rating.getUuid())).thenReturn(rating);
Mockito.doThrow(new APIMgtDAOException("Error occurred while adding rating for api", new SQLException())).when(apiDAO).addRating(api.getId(), rating);
apiStore.addRating(api.getId(), rating);
}
use of org.wso2.carbon.apimgt.api.model.APIStore in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testDeleteComment.
@Test(description = "Delete comment")
public void testDeleteComment() 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());
Mockito.when(apiDAO.getCommentByUUID(comment.getUuid(), api.getId())).thenReturn(comment);
apiStore.deleteComment(comment.getUuid(), api.getId(), "admin");
Mockito.verify(apiDAO, Mockito.times(1)).isAPIExists(api.getId());
Mockito.verify(apiDAO, Mockito.times(1)).deleteComment(comment.getUuid(), api.getId());
}
Aggregations