use of org.wso2.carbon.apimgt.rest.api.store.dto.DocumentDTO in project carbon-apimgt by wso2.
the class TestMappingUtilTestCase method testDocumentInfoToDocumentDTOInfoMappingAndViceVersa.
@Test(description = "DocumentInfo to DocumentDTO mapping and vice versa")
void testDocumentInfoToDocumentDTOInfoMappingAndViceVersa() {
DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultDocumentationInfo().build();
DocumentDTO documentDTO = MappingUtil.toDocumentDTO(documentInfo);
// Test DocumentInfo to DocumentDTO mapping
assertEquals(documentInfo.getName(), documentDTO.getName());
assertEquals(documentInfo.getId(), documentDTO.getDocumentId());
assertEquals(documentInfo.getOtherType(), documentDTO.getOtherTypeName());
assertEquals(documentInfo.getSourceType().getType(), documentDTO.getSourceType().name());
assertEquals(documentInfo.getSourceURL(), documentDTO.getSourceUrl());
assertEquals(documentInfo.getFileName(), documentDTO.getFileName());
assertEquals(documentInfo.getSummary(), documentDTO.getSummary());
assertEquals(documentInfo.getVisibility().toString(), documentDTO.getVisibility().name());
assertEquals(documentInfo.getType().toString(), documentDTO.getType().name());
// Test DocumentDTO to DocumentInfo mapping
DocumentInfo mappedDocumentInfo = MappingUtil.toDocumentInfo(documentDTO);
assertEquals(mappedDocumentInfo.getName(), documentDTO.getName());
assertEquals(mappedDocumentInfo.getId(), documentDTO.getDocumentId());
assertEquals(mappedDocumentInfo.getOtherType(), documentDTO.getOtherTypeName());
assertEquals(mappedDocumentInfo.getSourceType().getType(), documentDTO.getSourceType().name());
assertEquals(mappedDocumentInfo.getSourceURL(), documentDTO.getSourceUrl());
assertEquals(mappedDocumentInfo.getFileName(), documentDTO.getFileName());
assertEquals(mappedDocumentInfo.getSummary(), documentDTO.getSummary());
assertEquals(mappedDocumentInfo.getVisibility().toString(), documentDTO.getVisibility().name());
assertEquals(mappedDocumentInfo.getType().toString(), documentDTO.getType().name());
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.DocumentDTO in project carbon-apimgt by wso2.
the class MappingUtil method toDocumentDTO.
/**
* this method convert Model object into Dto
*
* @param documentInfo object containing document information
* @return DTO object containing document data
*/
public static DocumentDTO toDocumentDTO(DocumentInfo documentInfo) {
DocumentDTO documentDTO = new DocumentDTO();
documentDTO.setName(documentInfo.getName());
documentDTO.setDocumentId(documentInfo.getId());
documentDTO.setOtherTypeName(documentInfo.getOtherType());
documentDTO.setSourceType(DocumentDTO.SourceTypeEnum.fromValue(documentInfo.getSourceType().getType()));
documentDTO.setSourceUrl(documentInfo.getSourceURL());
documentDTO.setFileName(documentInfo.getFileName());
documentDTO.setSummary(documentInfo.getSummary());
documentDTO.setVisibility(DocumentDTO.VisibilityEnum.fromValue(documentInfo.getVisibility().toString()));
documentDTO.setType(DocumentDTO.TypeEnum.fromValue(documentInfo.getType().toString()));
return documentDTO;
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.DocumentDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdDocumentsDocumentIdPut.
@Test
public void testApisApiIdDocumentsDocumentIdPut() throws Exception {
printTestMethodName();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
DocumentInfo documentInfo1 = SampleTestObjectCreator.createDefaultDocumentationInfo().build();
DocumentInfo documentInfo2 = SampleTestObjectCreator.createDefaultDocumentationInfo().id(documentInfo1.getId()).summary("My new summary").build();
DocumentDTO documentDTO = MappingUtil.toDocumentDTO(documentInfo2);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
String documentId = UUID.randomUUID().toString();
String apiId = UUID.randomUUID().toString();
Mockito.doReturn(documentInfo1).doReturn(documentInfo2).doThrow(new IllegalArgumentException()).when(apiPublisher).getDocumentationSummary(documentId);
Mockito.doReturn("updated").doThrow(new IllegalArgumentException()).when(apiPublisher).updateDocumentation(apiId, documentInfo1);
Response response = apisApiService.apisApiIdDocumentsDocumentIdPut(apiId, documentId, documentDTO, null, null, getRequest());
assertEquals(response.getStatus(), 200);
assertTrue(response.getEntity().toString().contains("My new summary"));
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.DocumentDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdDocumentsDocumentIdPutException.
@Test
public void testApisApiIdDocumentsDocumentIdPutException() throws Exception {
printTestMethodName();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
DocumentInfo documentInfo1 = SampleTestObjectCreator.createDefaultDocumentationInfo().build();
DocumentInfo documentInfo2 = SampleTestObjectCreator.createDefaultDocumentationInfo().id(documentInfo1.getId()).summary("My new summary").build();
DocumentDTO documentDTO = MappingUtil.toDocumentDTO(documentInfo2);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
String documentId = UUID.randomUUID().toString();
String apiId = UUID.randomUUID().toString();
Mockito.doReturn(documentInfo1).doReturn(documentInfo2).doThrow(new IllegalArgumentException()).when(apiPublisher).getDocumentationSummary(documentId);
Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.INVALID_DOCUMENT_CONTENT_DATA)).when(apiPublisher).updateDocumentation(apiId, documentInfo1);
Response response = apisApiService.apisApiIdDocumentsDocumentIdPut(apiId, documentId, documentDTO, null, null, getRequest());
assertEquals(response.getStatus(), 400);
assertTrue(response.getEntity().toString().contains("Invalid document content data provided"));
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.DocumentDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdDocumentsPost.
@Test
public void testApisApiIdDocumentsPost() 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.INLINE).build();
DocumentDTO documentDTO = MappingUtil.toDocumentDTO(documentInfo);
Mockito.doReturn(documentDTO.getDocumentId()).doThrow(new IllegalArgumentException()).when(apiPublisher).addDocumentationInfo(apiId, documentInfo);
Mockito.doReturn(documentInfo).doThrow(new IllegalArgumentException()).when(apiPublisher).getDocumentationSummary(documentDTO.getDocumentId());
Mockito.doNothing().doThrow(new IllegalArgumentException()).when(apiPublisher).addDocumentationContent(documentDTO.getDocumentId(), "");
Response response = apisApiService.apisApiIdDocumentsPost(apiId, documentDTO, null, null, getRequest());
assertEquals(response.getStatus(), 201);
assertTrue(response.getEntity().toString().contains(documentDTO.getDocumentId()));
}
Aggregations