Search in sources :

Example 41 with DocumentInfo

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

Example 42 with DocumentInfo

use of org.wso2.carbon.apimgt.core.models.DocumentInfo 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());
}
Also used : Response(javax.ws.rs.core.Response) Request(org.wso2.msf4j.Request) ArrayList(java.util.ArrayList) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 43 with DocumentInfo

use of org.wso2.carbon.apimgt.core.models.DocumentInfo in project carbon-apimgt by wso2.

the class DocumentationMappingUtil method fromDocumentationListToDTO.

/**
 * Converts a List object of ArtifactResourceMetaData into a DTO
 *
 * @param documentInfoList List of ArtifactResourceMetaData
 * @param limit          maximum number of APIs returns
 * @param offset         starting index
 * @return DocumentListDTO object containing Document DTOs
 */
public static DocumentListDTO fromDocumentationListToDTO(List<DocumentInfo> documentInfoList, int offset, int limit) {
    DocumentListDTO documentListDTO = new DocumentListDTO();
    List<DocumentDTO> documentDTOs = documentListDTO.getList();
    if (documentDTOs == null) {
        documentDTOs = new ArrayList<>();
        documentListDTO.setList(documentDTOs);
    }
    // add the required range of objects to be returned
    int start = offset < documentInfoList.size() && offset >= 0 ? offset : Integer.MAX_VALUE;
    int end = offset + limit - 1 <= documentInfoList.size() - 1 ? offset + limit - 1 : documentInfoList.size() - 1;
    for (int i = start; i <= end; i++) {
        documentDTOs.add(fromDocumentationToDTO(documentInfoList.get(i)));
    }
    documentListDTO.setCount(documentDTOs.size());
    return documentListDTO;
}
Also used : DocumentDTO(org.wso2.carbon.apimgt.rest.api.store.dto.DocumentDTO) DocumentListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.DocumentListDTO)

Example 44 with DocumentInfo

use of org.wso2.carbon.apimgt.core.models.DocumentInfo in project carbon-apimgt by wso2.

the class DocMetaDataDAO method getDocumentInfoList.

static List<DocumentInfo> getDocumentInfoList(Connection connection, String apiID) throws SQLException {
    final String query = "SELECT meta.UUID, meta.NAME, meta.SUMMARY, meta.TYPE, meta.OTHER_TYPE_NAME, " + "meta.SOURCE_URL, meta.FILE_NAME, meta.SOURCE_TYPE, meta.VISIBILITY " + "FROM AM_API_DOC_META_DATA meta, AM_API_RESOURCES rec WHERE " + "meta.UUID = rec.UUID AND rec.API_ID = ?";
    List<DocumentInfo> metaDataList = new ArrayList<>();
    try (PreparedStatement statement = connection.prepareStatement(query)) {
        statement.setString(1, apiID);
        statement.execute();
        try (ResultSet rs = statement.getResultSet()) {
            while (rs.next()) {
                metaDataList.add(new DocumentInfo.Builder().id(rs.getString("UUID")).name(rs.getString("NAME")).summary(rs.getString("SUMMARY")).type(DocumentInfo.DocType.valueOf(rs.getString("TYPE"))).otherType(rs.getString("OTHER_TYPE_NAME")).sourceURL(rs.getString("SOURCE_URL")).fileName(rs.getString("FILE_NAME")).sourceType(DocumentInfo.SourceType.valueOf(rs.getString("SOURCE_TYPE"))).visibility(DocumentInfo.Visibility.valueOf(rs.getString("VISIBILITY"))).build());
            }
        }
    }
    return metaDataList;
}
Also used : ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo)

Example 45 with DocumentInfo

use of org.wso2.carbon.apimgt.core.models.DocumentInfo 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);
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) 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