use of org.wso2.carbon.apimgt.core.models.DocumentInfo in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testAddDocumentationInfo.
@Test(description = "Add Documentation Info")
public void testAddDocumentationInfo() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
DocumentInfo documentInfo = new DocumentInfo.Builder().fileName("sample_doc.pdf").name("howto_guide").id(DOC_ID).permission("[{\"groupId\": \"testGroup\",\"permission\":[\"READ\",\"UPDATE\",\"DELETE\"]}]").build();
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
apiPublisher.addDocumentationInfo(API_ID, documentInfo);
Mockito.verify(apiDAO, Mockito.times(1)).addDocumentInfo(API_ID, documentInfo);
}
use of org.wso2.carbon.apimgt.core.models.DocumentInfo in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdDocumentsGet.
@Test
public void testApisApiIdDocumentsGet() throws APIManagementException, NotFoundException {
printTestMethodName();
String apiId = UUID.randomUUID().toString();
String documentId = UUID.randomUUID().toString();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
DocumentInfo documentInfo1 = TestUtil.createAPIDoc(UUID.randomUUID().toString(), "documentInfo1", "", "API1 documentation 1", DocumentInfo.DocType.HOWTO, "other type", DocumentInfo.SourceType.FILE, "", DocumentInfo.Visibility.PRIVATE);
DocumentInfo documentInfo2 = TestUtil.createAPIDoc(UUID.randomUUID().toString(), "documentInfo2", "", "API1 documentation 2", DocumentInfo.DocType.HOWTO, "other type", DocumentInfo.SourceType.FILE, "", DocumentInfo.Visibility.PRIVATE);
List<DocumentInfo> documentInfoList = new ArrayList<>();
documentInfoList.add(documentInfo1);
documentInfoList.add(documentInfo2);
Mockito.when(apiStore.getAllDocumentation(apiId, 0, 10)).thenReturn(documentInfoList);
Response response = apisApiService.apisApiIdDocumentsGet(apiId, 10, 0, null, request);
Assert.assertEquals(200, response.getStatus());
}
use of org.wso2.carbon.apimgt.core.models.DocumentInfo 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;
}
use of org.wso2.carbon.apimgt.core.models.DocumentInfo in project carbon-apimgt by wso2.
the class DocMetaDataDAO method getDocumentInfoList.
static List<DocumentInfo> getDocumentInfoList(Connection connection, String apiID) throws SQLException {
final String query = "SELECT meta.UUID, meta.NAME, meta.SUMMARY, meta.TYPE, meta.OTHER_TYPE_NAME, " + "meta.SOURCE_URL, meta.FILE_NAME, meta.SOURCE_TYPE, meta.VISIBILITY " + "FROM AM_API_DOC_META_DATA meta, AM_API_RESOURCES rec WHERE " + "meta.UUID = rec.UUID AND rec.API_ID = ?";
List<DocumentInfo> metaDataList = new ArrayList<>();
try (PreparedStatement statement = connection.prepareStatement(query)) {
statement.setString(1, apiID);
statement.execute();
try (ResultSet rs = statement.getResultSet()) {
while (rs.next()) {
metaDataList.add(new DocumentInfo.Builder().id(rs.getString("UUID")).name(rs.getString("NAME")).summary(rs.getString("SUMMARY")).type(DocumentInfo.DocType.valueOf(rs.getString("TYPE"))).otherType(rs.getString("OTHER_TYPE_NAME")).sourceURL(rs.getString("SOURCE_URL")).fileName(rs.getString("FILE_NAME")).sourceType(DocumentInfo.SourceType.valueOf(rs.getString("SOURCE_TYPE"))).visibility(DocumentInfo.Visibility.valueOf(rs.getString("VISIBILITY"))).build());
}
}
}
return metaDataList;
}
use of org.wso2.carbon.apimgt.core.models.DocumentInfo in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUnableToAddDocumentationException.
@Test(description = "Unable to add documentation info", expectedExceptions = APIManagementException.class)
public void testUnableToAddDocumentationException() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultDocumentationInfo();
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
Mockito.doThrow(new APIMgtDAOException("Unable to add documentation")).when(apiDAO).addDocumentInfo(API_ID, documentInfo);
apiPublisher.addDocumentationInfo(API_ID, documentInfo);
}
Aggregations