use of org.wso2.carbon.apimgt.core.models.DocumentInfo in project carbon-apimgt by wso2.
the class AbstractAPIManagerTestCase method testGetDocumentationContentInlineWithNullContent.
@Test(description = "Getting Documentation content when source type is INLINE and inline content is null", expectedExceptions = APIManagementException.class)
public void testGetDocumentationContentInlineWithNullContent() throws APIManagementException {
ApiDAO apiDAO = mock(ApiDAO.class);
AbstractAPIManager apiPublisher = getApiPublisherImpl(apiDAO);
DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultDocumentationInfo();
when(apiDAO.getDocumentInfo(DOC_ID)).thenReturn(documentInfo);
when(apiDAO.getDocumentInlineContent(DOC_ID)).thenReturn(null);
apiPublisher.getDocumentationContent(DOC_ID);
verify(apiDAO, times(0)).getDocumentInlineContent(DOC_ID);
}
use of org.wso2.carbon.apimgt.core.models.DocumentInfo in project carbon-apimgt by wso2.
the class AbstractAPIManagerTestCase method testGetDocumentationContentFile.
@Test(description = "Getting Documentation content when source type is FILE")
public void testGetDocumentationContentFile() throws APIManagementException {
ApiDAO apiDAO = mock(ApiDAO.class);
AbstractAPIManager apiPublisher = getApiPublisherImpl(apiDAO);
DocumentInfo.Builder builder = new DocumentInfo.Builder();
builder.name("CalculatorDoc");
builder.sourceType(DocumentInfo.SourceType.FILE);
DocumentInfo documentInfo = builder.build();
when(apiDAO.getDocumentInfo(DOC_ID)).thenReturn(documentInfo);
String stream = "This is sample file content";
InputStream inputStream = new ByteArrayInputStream(stream.getBytes());
when(apiDAO.getDocumentFileContent(DOC_ID)).thenReturn(inputStream);
apiPublisher.getDocumentationContent(DOC_ID);
verify(apiDAO, times(1)).getDocumentFileContent(DOC_ID);
}
use of org.wso2.carbon.apimgt.core.models.DocumentInfo in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUnableToUpdateDocumentationException.
@Test(description = "Unable to update documentation info")
public void testUnableToUpdateDocumentationException() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultDocumentationInfo();
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
Mockito.when(apiDAO.isDocumentExist(API_ID, documentInfo)).thenReturn(true);
Mockito.doThrow(APIMgtDAOException.class).when(apiDAO).updateDocumentInfo(API_ID, documentInfo, USER);
try {
apiPublisher.updateDocumentation(API_ID, documentInfo);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Unable to update the documentation");
}
}
use of org.wso2.carbon.apimgt.core.models.DocumentInfo in project carbon-apimgt by wso2.
the class AbstractAPIManager method getDocumentationContent.
/**
* This method used to get the content of a documentation
*
* @param docId Document ID
* @return {@link InputStream} Input stream for document content
* @throws APIManagementException if the requested documentation content is not available
*/
public DocumentContent getDocumentationContent(String docId) throws APIManagementException {
try {
DocumentInfo documentInfo = getDocumentationSummary(docId);
DocumentContent.Builder documentContentBuilder = new DocumentContent.Builder();
if (documentInfo != null) {
documentContentBuilder.documentInfo(documentInfo);
if (DocumentInfo.SourceType.FILE.equals(documentInfo.getSourceType())) {
InputStream inputStream = getApiDAO().getDocumentFileContent(docId);
if (inputStream != null) {
documentContentBuilder = documentContentBuilder.fileContent(inputStream);
} else {
throw new APIManagementException("Couldn't find file content of document", ExceptionCodes.DOCUMENT_CONTENT_NOT_FOUND);
}
} else if (documentInfo.getSourceType().equals(DocumentInfo.SourceType.INLINE)) {
String inlineContent = getApiDAO().getDocumentInlineContent(docId);
if (inlineContent != null) {
documentContentBuilder = documentContentBuilder.inlineContent(inlineContent);
} else {
throw new APIManagementException("Couldn't find inline content of document", ExceptionCodes.DOCUMENT_CONTENT_NOT_FOUND);
}
}
} else {
throw new APIManagementException("Couldn't fnd document", ExceptionCodes.DOCUMENT_NOT_FOUND);
}
return documentContentBuilder.build();
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while retrieving document content";
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, e.getErrorHandler());
}
}
use of org.wso2.carbon.apimgt.core.models.DocumentInfo in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateDocumentationDocNotExists.
@Test(description = "Documentation does not exists error when updating Documentation Info", expectedExceptions = APIManagementException.class)
public void testUpdateDocumentationDocNotExists() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultDocumentationInfo();
Mockito.when(apiDAO.isDocumentExist(API_ID, documentInfo)).thenReturn(false);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
apiPublisher.updateDocumentation(API_ID, documentInfo);
}
Aggregations