Search in sources :

Example 6 with DocumentDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.dto.DocumentDTO in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisApiIdDocumentsPostEmptyOtherType.

@Test(expected = BadRequestException.class)
public void testApisApiIdDocumentsPostEmptyOtherType() throws Exception {
    printTestMethodName();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    String apiId = UUID.randomUUID().toString();
    DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultDocumentationInfo().type(DocumentInfo.DocType.OTHER).otherType("").build();
    DocumentDTO documentDTO = MappingUtil.toDocumentDTO(documentInfo);
    Response response = apisApiService.apisApiIdDocumentsPost(apiId, documentDTO, null, null, getRequest());
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) DocumentDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.DocumentDTO) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with DocumentDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.dto.DocumentDTO in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisApiIdDocumentsPostEmptySourceUrlType.

@Test(expected = BadRequestException.class)
public void testApisApiIdDocumentsPostEmptySourceUrlType() throws Exception {
    printTestMethodName();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    String apiId = UUID.randomUUID().toString();
    DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultDocumentationInfo().sourceType(DocumentInfo.SourceType.URL).sourceURL("").build();
    DocumentDTO documentDTO = MappingUtil.toDocumentDTO(documentInfo);
    Response response = apisApiService.apisApiIdDocumentsPost(apiId, documentDTO, null, null, getRequest());
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) DocumentDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.DocumentDTO) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with DocumentDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.dto.DocumentDTO in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisApiIdDocumentsDocumentIdPutOtherTypeNameEmpty.

@Test
public void testApisApiIdDocumentsDocumentIdPutOtherTypeNameEmpty() throws Exception {
    printTestMethodName();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultDocumentationInfo().otherType("").type(DocumentInfo.DocType.OTHER).build();
    DocumentDTO documentDTO = MappingUtil.toDocumentDTO(documentInfo);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    String documentId = UUID.randomUUID().toString();
    String apiId = UUID.randomUUID().toString();
    Mockito.doReturn(documentInfo).doThrow(new IllegalArgumentException()).when(apiPublisher).getDocumentationSummary(documentId);
    Response response = apisApiService.apisApiIdDocumentsDocumentIdPut(apiId, documentId, documentDTO, null, null, getRequest());
    assertEquals(response.getStatus(), 400);
    assertTrue(response.getEntity().toString().contains("otherTypeName cannot be empty if type is OTHER."));
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) DocumentDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.DocumentDTO) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with DocumentDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.dto.DocumentDTO in project carbon-apimgt by wso2.

the class DocumentationMappingUtil method fromDocumentationToDTO.

/**
 * Converts an ArtifactResourceMetaData object into corresponding REST API Document DTO object
 *
 * @param documentInfo DocumentInfo object
 * @return a new DocumentDTO object corresponding to given ArtifactResourceMetaData object
 */
public static DocumentDTO fromDocumentationToDTO(DocumentInfo documentInfo) {
    DocumentDTO documentDTO = new DocumentDTO();
    documentDTO.setDocumentId(documentInfo.getId());
    documentDTO.setName(documentInfo.getName());
    documentDTO.setSummary(documentInfo.getSummary());
    documentDTO.setType(DocumentDTO.TypeEnum.valueOf(documentInfo.getType().toString()));
    documentDTO.setOtherTypeName(documentInfo.getOtherType());
    documentDTO.setSourceType(DocumentDTO.SourceTypeEnum.valueOf(documentInfo.getSourceType().toString()));
    documentDTO.setSourceUrl(documentInfo.getSourceURL());
    return documentDTO;
}
Also used : DocumentDTO(org.wso2.carbon.apimgt.rest.api.store.dto.DocumentDTO)

Example 10 with DocumentDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.dto.DocumentDTO 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)

Aggregations

DocumentInfo (org.wso2.carbon.apimgt.core.models.DocumentInfo)13 DocumentDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.DocumentDTO)12 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)11 Response (javax.ws.rs.core.Response)9 Test (org.junit.Test)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)9 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)9 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)5 HashMap (java.util.HashMap)3 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)3 DocumentDTO (org.wso2.carbon.apimgt.rest.api.store.dto.DocumentDTO)3 Test (org.testng.annotations.Test)1 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)1 DocumentListDTO (org.wso2.carbon.apimgt.rest.api.store.dto.DocumentListDTO)1