use of org.wso2.carbon.apimgt.persistence.dto.Documentation 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.persistence.dto.Documentation 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);
}
use of org.wso2.carbon.apimgt.persistence.dto.Documentation in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testAddDocumentationInfo.
@Test(description = "Add Documentation Info")
public void testAddDocumentationInfo() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
DocumentInfo documentInfo = new DocumentInfo.Builder().fileName("sample_doc.pdf").name("howto_guide").id(DOC_ID).permission("[{\"groupId\": \"testGroup\",\"permission\":[\"READ\",\"UPDATE\",\"DELETE\"]}]").build();
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
apiPublisher.addDocumentationInfo(API_ID, documentInfo);
Mockito.verify(apiDAO, Mockito.times(1)).addDocumentInfo(API_ID, documentInfo);
}
use of org.wso2.carbon.apimgt.persistence.dto.Documentation in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdDocumentsGet.
@Test
public void testApisApiIdDocumentsGet() throws APIManagementException, NotFoundException {
printTestMethodName();
String apiId = UUID.randomUUID().toString();
String documentId = UUID.randomUUID().toString();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
DocumentInfo documentInfo1 = TestUtil.createAPIDoc(UUID.randomUUID().toString(), "documentInfo1", "", "API1 documentation 1", DocumentInfo.DocType.HOWTO, "other type", DocumentInfo.SourceType.FILE, "", DocumentInfo.Visibility.PRIVATE);
DocumentInfo documentInfo2 = TestUtil.createAPIDoc(UUID.randomUUID().toString(), "documentInfo2", "", "API1 documentation 2", DocumentInfo.DocType.HOWTO, "other type", DocumentInfo.SourceType.FILE, "", DocumentInfo.Visibility.PRIVATE);
List<DocumentInfo> documentInfoList = new ArrayList<>();
documentInfoList.add(documentInfo1);
documentInfoList.add(documentInfo2);
Mockito.when(apiStore.getAllDocumentation(apiId, 0, 10)).thenReturn(documentInfoList);
Response response = apisApiService.apisApiIdDocumentsGet(apiId, 10, 0, null, request);
Assert.assertEquals(200, response.getStatus());
}
use of org.wso2.carbon.apimgt.persistence.dto.Documentation in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUnableToAddDocumentationException.
@Test(description = "Unable to add documentation info", expectedExceptions = APIManagementException.class)
public void testUnableToAddDocumentationException() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultDocumentationInfo();
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
Mockito.doThrow(new APIMgtDAOException("Unable to add documentation")).when(apiDAO).addDocumentInfo(API_ID, documentInfo);
apiPublisher.addDocumentationInfo(API_ID, documentInfo);
}
Aggregations