use of org.wso2.carbon.apimgt.core.models.DocumentInfo in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdDocumentsDocumentIdGet.
/**
* Retrives the document identified by the API's ID and the document's ID
*
* @param apiId UUID of API
* @param documentId UUID of the document
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header value
* @param request minor version header
* @return the document qualifying for the provided IDs
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response apisApiIdDocumentsDocumentIdGet(String apiId, String documentId, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
DocumentDTO documentDTO = null;
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
String existingFingerprint = apisApiIdDocumentsDocumentIdGetFingerprint(apiId, documentId, ifNoneMatch, ifModifiedSince, request);
if (!StringUtils.isEmpty(ifNoneMatch) && !StringUtils.isEmpty(existingFingerprint) && ifNoneMatch.contains(existingFingerprint)) {
return Response.notModified().build();
}
DocumentInfo documentInfo = apiStore.getDocumentationSummary(documentId);
documentDTO = DocumentationMappingUtil.fromDocumentationToDTO(documentInfo);
return Response.ok().entity(documentDTO).header(HttpHeaders.ETAG, "\"" + existingFingerprint + "\"").build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving documentation for given apiId " + apiId + "with docId " + documentId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
paramList.put(APIMgtConstants.ExceptionsConstants.DOC_ID, documentId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.core.models.DocumentInfo in project carbon-apimgt by wso2.
the class TestMappingUtilTestCase method testDocumentInfoListToDocumentDTOMapping.
@Test(description = "Document Info list to Document DTO list mapping")
void testDocumentInfoListToDocumentDTOMapping() {
DocumentInfo documentInfo1 = SampleTestObjectCreator.createDefaultDocumentationInfo().id("newId1").name("newName1").fileName("newFile1").summary("newSum1").build();
DocumentInfo documentInfo2 = SampleTestObjectCreator.createDefaultDocumentationInfo().id("newId2").name("newName2").fileName("newFile2").summary("newSum2").build();
List<DocumentInfo> documentInfos = new ArrayList<>();
documentInfos.add(documentInfo1);
documentInfos.add(documentInfo2);
DocumentListDTO documentListDTO = MappingUtil.toDocumentListDTO(documentInfos);
assertEquals((Integer) documentInfos.size(), documentListDTO.getCount());
assertEquals(documentInfo1.getName(), documentListDTO.getList().get(0).getName());
assertEquals(documentInfo1.getId(), documentListDTO.getList().get(0).getDocumentId());
assertEquals(documentInfo1.getOtherType(), documentListDTO.getList().get(0).getOtherTypeName());
assertEquals(documentInfo1.getSourceType().getType(), documentListDTO.getList().get(0).getSourceType().name());
assertEquals(documentInfo1.getSourceURL(), documentListDTO.getList().get(0).getSourceUrl());
assertEquals(documentInfo1.getFileName(), documentListDTO.getList().get(0).getFileName());
assertEquals(documentInfo1.getSummary(), documentListDTO.getList().get(0).getSummary());
assertEquals(documentInfo1.getVisibility().toString(), documentListDTO.getList().get(0).getVisibility().name());
assertEquals(documentInfo1.getType().toString(), documentListDTO.getList().get(0).getType().name());
assertEquals(documentInfo2.getName(), documentListDTO.getList().get(1).getName());
assertEquals(documentInfo2.getId(), documentListDTO.getList().get(1).getDocumentId());
assertEquals(documentInfo2.getOtherType(), documentListDTO.getList().get(1).getOtherTypeName());
assertEquals(documentInfo2.getSourceType().getType(), documentListDTO.getList().get(1).getSourceType().name());
assertEquals(documentInfo2.getSourceURL(), documentListDTO.getList().get(1).getSourceUrl());
assertEquals(documentInfo2.getFileName(), documentListDTO.getList().get(1).getFileName());
assertEquals(documentInfo2.getSummary(), documentListDTO.getList().get(1).getSummary());
assertEquals(documentInfo2.getVisibility().toString(), documentListDTO.getList().get(1).getVisibility().name());
assertEquals(documentInfo2.getType().toString(), documentListDTO.getList().get(1).getType().name());
}
use of org.wso2.carbon.apimgt.core.models.DocumentInfo in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdDocumentsDocumentIdContentPostFile.
@Test
public void testApisApiIdDocumentsDocumentIdContentPostFile() throws Exception {
String fileName = "swagger.json";
String contentType = "text/json";
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource(fileName).getFile());
FileInfo fileDetail = new FileInfo();
fileDetail.setFileName(fileName);
fileDetail.setContentType(contentType);
FileInputStream fis = null;
fis = new FileInputStream(file);
printTestMethodName();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
String api1Id = UUID.randomUUID().toString();
String documentId = UUID.randomUUID().toString();
DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultDocumentationInfo().fileName(fileName).sourceType(DocumentInfo.SourceType.FILE).build();
Mockito.doReturn(documentInfo).doThrow(new IllegalArgumentException()).when(apiPublisher).getDocumentationSummary(documentId);
Mockito.doNothing().doThrow(new IllegalArgumentException()).when(apiPublisher).uploadDocumentationFile(documentId, fis, contentType);
Response response = apisApiService.apisApiIdDocumentsDocumentIdContentPost(api1Id, documentId, fis, fileDetail, null, null, null, getRequest());
fis.close();
assertEquals(response.getStatus(), 201);
}
use of org.wso2.carbon.apimgt.core.models.DocumentInfo in project carbon-apimgt by wso2.
the class APIImportExportTestCase method testGetApiDetails.
@Test(description = "Test getAPIDetails - single API")
void testGetApiDetails() throws APIManagementException {
printTestMethodName();
apiPublisher = Mockito.mock(APIPublisher.class);
String api1Id = UUID.randomUUID().toString();
Endpoint api1SandBoxEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("abcd").build();
Endpoint api1ProdEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("cdef").build();
API api1 = createApi("provider1", api1Id, "testapi1", "1.0.0", "Test API 1 - version 1.0.0", createEndpointTypeToIdMap(api1SandBoxEndpointId, api1ProdEndpointId)).build();
String api1Doc1Id = UUID.randomUUID().toString();
DocumentInfo api1Doc1Info = createAPIDoc(api1Doc1Id, "api1doc1", "", "API 1 DOC 1", DocumentInfo.DocType.HOWTO, "other type", DocumentInfo.SourceType.INLINE, "", DocumentInfo.Visibility.PRIVATE);
String api1Doc2Id = UUID.randomUUID().toString();
DocumentInfo api1Doc2Info = createAPIDoc(api1Doc2Id, "api1doc2.pdf", "api1doc2.pdf", "API 1 DOC 2", DocumentInfo.DocType.PUBLIC_FORUM, "other type", DocumentInfo.SourceType.FILE, "", DocumentInfo.Visibility.API_LEVEL);
String api1Doc3Id = UUID.randomUUID().toString();
DocumentInfo api1Doc3Info = createAPIDoc(api1Doc3Id, "api1doc3", "", "API 1 DOC 3", DocumentInfo.DocType.OTHER, "other type", DocumentInfo.SourceType.OTHER, "", DocumentInfo.Visibility.API_LEVEL);
List<DocumentInfo> api1DocumentInfo = new ArrayList<>();
api1DocumentInfo.add(api1Doc1Info);
api1DocumentInfo.add(api1Doc2Info);
api1DocumentInfo.add(api1Doc3Info);
// contents for documents
DocumentContent api1Doc1Content = createDocContent(api1Doc1Info, "Sample inline content for API1 DOC 1", null);
DocumentContent api1Doc2Content = createDocContent(api1Doc2Info, "", api1Doc2Stream);
DocumentContent api1Doc3Content = createDocContent(api1Doc3Info, "", null);
Mockito.when(apiPublisher.getAPIbyUUID(api1Id)).thenReturn(api1);
Mockito.when(apiPublisher.getApiSwaggerDefinition(api1Id)).thenReturn(api1Definition);
Mockito.when(apiPublisher.getApiGatewayConfig(api1Id)).thenReturn(api1GatewayConfig);
Mockito.when(apiPublisher.getAllDocumentation(api1Id, 0, Integer.MAX_VALUE)).thenReturn(api1DocumentInfo);
Mockito.when(apiPublisher.getDocumentationContent(api1Doc1Id)).thenReturn(api1Doc1Content);
Mockito.when(apiPublisher.getDocumentationContent(api1Doc2Id)).thenReturn(api1Doc2Content);
Mockito.when(apiPublisher.getDocumentationContent(api1Doc3Id)).thenReturn(api1Doc3Content);
Mockito.when(apiPublisher.getThumbnailImage(api1Id)).thenReturn(getClass().getClassLoader().getResourceAsStream("api1_thumbnail.png"));
List<API> apis = new ArrayList<>();
apis.add(api1);
Mockito.when(apiPublisher.searchAPIs(Integer.MAX_VALUE, 0, "*")).thenReturn(apis);
ApiImportExportManager importExportManager = new ApiImportExportManager(apiPublisher);
Set<APIDetails> apiDetailsSet = importExportManager.getAPIDetails(Integer.MAX_VALUE, 0, "*");
Assert.assertEquals(new ArrayList<>(apiDetailsSet).get(0).getApi().getId().equals(api1Id), true, "APIDetails not retrieved correctly for API: " + api1.getName() + ", version: " + api1.getVersion());
}
use of org.wso2.carbon.apimgt.core.models.DocumentInfo in project carbon-apimgt by wso2.
the class APIImportExportTestCase method testGetMultipleApiDetailsWithNonFatalErrors.
@Test(description = "Test getAPIDetails - multiple APIs with non-critical error in retrieving information of one API")
void testGetMultipleApiDetailsWithNonFatalErrors() throws APIManagementException {
printTestMethodName();
apiPublisher = Mockito.mock(APIPublisher.class);
String api4Id = UUID.randomUUID().toString();
Endpoint api4SandBoxEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("abcd").build();
Endpoint api4ProdEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("cdef").build();
API api4 = createApi("provider4", api4Id, "testapi4", "1.0.0", "Test API 4 - version 1.0.0", createEndpointTypeToIdMap(api4SandBoxEndpointId, api4ProdEndpointId)).build();
String api4Doc1Id = UUID.randomUUID().toString();
DocumentInfo api4Doc1Info = createAPIDoc(api4Doc1Id, "api1doc1", "", "API 4 DOC 1", DocumentInfo.DocType.HOWTO, "other type", DocumentInfo.SourceType.INLINE, "", DocumentInfo.Visibility.PRIVATE);
String api4Doc2Id = UUID.randomUUID().toString();
DocumentInfo api4Doc2Info = createAPIDoc(api4Doc2Id, "api1doc2.pdf", "api1doc2.pdf", "API 4 DOC 2", DocumentInfo.DocType.PUBLIC_FORUM, "other type", DocumentInfo.SourceType.FILE, "", DocumentInfo.Visibility.API_LEVEL);
String api4Doc3Id = UUID.randomUUID().toString();
DocumentInfo api4Doc3Info = createAPIDoc(api4Doc3Id, "api1doc3", "", "API 4 DOC 3", DocumentInfo.DocType.OTHER, "other type", DocumentInfo.SourceType.OTHER, "", DocumentInfo.Visibility.API_LEVEL);
List<DocumentInfo> api1DocumentInfo = new ArrayList<>();
api1DocumentInfo.add(api4Doc1Info);
api1DocumentInfo.add(api4Doc2Info);
api1DocumentInfo.add(api4Doc3Info);
// contents for documents
DocumentContent api4Doc1Content = createDocContent(api4Doc1Info, "Sample inline content for API1 DOC 1", null);
DocumentContent api4Doc2Content = createDocContent(api4Doc2Info, "", api1Doc2Stream);
DocumentContent api4Doc3Content = createDocContent(api4Doc3Info, "", null);
Mockito.when(apiPublisher.getAPIbyUUID(api4Id)).thenReturn(api4);
Mockito.when(apiPublisher.getApiSwaggerDefinition(api4Id)).thenReturn(api1Definition);
Mockito.when(apiPublisher.getApiGatewayConfig(api4Id)).thenReturn(api1GatewayConfig);
Mockito.when(apiPublisher.getAllDocumentation(api4Id, 0, Integer.MAX_VALUE)).thenReturn(api1DocumentInfo);
Mockito.when(apiPublisher.getDocumentationContent(api4Doc1Id)).thenReturn(api4Doc1Content);
Mockito.when(apiPublisher.getDocumentationContent(api4Doc2Id)).thenReturn(api4Doc2Content);
Mockito.when(apiPublisher.getDocumentationContent(api4Doc3Id)).thenReturn(api4Doc3Content);
Mockito.when(apiPublisher.getThumbnailImage(api4Id)).thenReturn(null);
String api5Id = UUID.randomUUID().toString();
Endpoint api5SandBoxEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("abcd").build();
Endpoint api5ProdEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("cdef").build();
API api5 = createApi("provider5", api5Id, "testapi4", "1.0.0", "Test API 5 - version 1.0.0", createEndpointTypeToIdMap(api5SandBoxEndpointId, api5ProdEndpointId)).build();
String api5Doc1Id = UUID.randomUUID().toString();
DocumentInfo api5Doc1Info = createAPIDoc(api5Doc1Id, "api1doc1", "", "API 5 DOC 1", DocumentInfo.DocType.HOWTO, "other type", DocumentInfo.SourceType.INLINE, "", DocumentInfo.Visibility.PRIVATE);
String api5Doc3Id = UUID.randomUUID().toString();
DocumentInfo api5Doc3Info = createAPIDoc(api5Doc3Id, "api1doc3", "", "API 5 DOC 3", DocumentInfo.DocType.OTHER, "other type", DocumentInfo.SourceType.OTHER, "", DocumentInfo.Visibility.API_LEVEL);
List<DocumentInfo> api5DocumentInfo = new ArrayList<>();
api5DocumentInfo.add(api5Doc1Info);
api5DocumentInfo.add(api5Doc3Info);
// contents for documents
DocumentContent api5Doc1Content = createDocContent(api5Doc1Info, "Sample inline content for API1 DOC 1", null);
DocumentContent api5Doc3Content = createDocContent(api5Doc3Info, "", null);
Mockito.when(apiPublisher.getAPIbyUUID(api5Id)).thenReturn(api5);
Mockito.when(apiPublisher.getApiSwaggerDefinition(api5Id)).thenReturn(api1Definition);
Mockito.when(apiPublisher.getApiGatewayConfig(api5Id)).thenReturn(api1GatewayConfig);
Mockito.when(apiPublisher.getAllDocumentation(api5Id, 0, Integer.MAX_VALUE)).thenReturn(api5DocumentInfo);
Mockito.when(apiPublisher.getDocumentationContent(api5Doc1Id)).thenReturn(api5Doc1Content);
Mockito.when(apiPublisher.getDocumentationContent(api5Doc3Id)).thenReturn(api5Doc3Content);
Mockito.when(apiPublisher.getThumbnailImage(api5Id)).thenReturn(getClass().getClassLoader().getResourceAsStream("api1_thumbnail.png"));
Mockito.when(apiPublisher.getAllDocumentation(api4Id, 0, Integer.MAX_VALUE)).thenThrow(APIManagementException.class);
List<API> apis = new ArrayList<>();
apis.add(api4);
apis.add(api5);
Mockito.when(apiPublisher.searchAPIs(Integer.MAX_VALUE, 0, "*")).thenReturn(apis);
ApiImportExportManager importExportManager = new ApiImportExportManager(apiPublisher);
Set<APIDetails> apiDetailsSet = importExportManager.getAPIDetails(Integer.MAX_VALUE, 0, "*");
Assert.assertEquals(apiDetailsSet.size() == 2, true, "Error getting API details");
}
Aggregations