Search in sources :

Example 36 with DocumentInfo

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);
}
Also used : ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) Test(org.testng.annotations.Test)

Example 37 with DocumentInfo

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) Test(org.testng.annotations.Test)

Example 38 with DocumentInfo

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");
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) Test(org.testng.annotations.Test)

Example 39 with DocumentInfo

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());
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) DocumentContent(org.wso2.carbon.apimgt.core.models.DocumentContent) InputStream(java.io.InputStream) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo)

Example 40 with DocumentInfo

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);
}
Also used : ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) Test(org.testng.annotations.Test)

Aggregations

DocumentInfo (org.wso2.carbon.apimgt.core.models.DocumentInfo)71 Test (org.testng.annotations.Test)28 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)28 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)22 Response (javax.ws.rs.core.Response)21 Test (org.junit.Test)21 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)21 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)20 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)18 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)18 API (org.wso2.carbon.apimgt.core.models.API)17 DocumentContent (org.wso2.carbon.apimgt.core.models.DocumentContent)16 HashMap (java.util.HashMap)14 DocumentDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.DocumentDTO)12 ArrayList (java.util.ArrayList)11 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)9 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)9 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)9 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)8 APIDetails (org.wso2.carbon.apimgt.core.models.APIDetails)7