use of org.wso2.carbon.apimgt.core.models.DocumentInfo 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()));
}
use of org.wso2.carbon.apimgt.core.models.DocumentInfo 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.core.models.DocumentInfo 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.core.models.DocumentInfo 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.core.models.DocumentInfo in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdDocumentsGet.
/**
* Retrieves a list of documents of an API
*
* @param apiId UUID of API
* @param limit maximum documents to return
* @param offset starting position of the pagination
* @param ifNoneMatch If-None-Match header value
* @param request msf4j request object
* @return a list of document DTOs
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response apisApiIdDocumentsGet(String apiId, Integer limit, Integer offset, String ifNoneMatch, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
List<DocumentInfo> documentInfos = apiPublisher.getAllDocumentation(apiId, offset, limit);
DocumentListDTO documentListDTO = MappingUtil.toDocumentListDTO(documentInfos);
return Response.status(Response.Status.OK).entity(documentListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while getting list of documents" + apiId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
Aggregations