Search in sources :

Example 1 with DocumentDTO

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());
}
Also used : DocumentDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.DocumentDTO) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) Test(org.testng.annotations.Test)

Example 2 with DocumentDTO

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;
}
Also used : DocumentDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.DocumentDTO)

Example 3 with 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"));
}
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 4 with DocumentDTO

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"));
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) 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 5 with DocumentDTO

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()));
}
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)

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