use of org.wso2.carbon.apimgt.rest.api.store.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());
}
use of org.wso2.carbon.apimgt.rest.api.store.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());
}
use of org.wso2.carbon.apimgt.rest.api.store.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."));
}
use of org.wso2.carbon.apimgt.rest.api.store.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;
}
use of org.wso2.carbon.apimgt.rest.api.store.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;
}
Aggregations