use of org.wso2.carbon.apimgt.api.model.Documentation in project carbon-apimgt by wso2.
the class AbstractAPIManagerTestCase method testGetDocumentationContentErrorOnRetrieval.
@Test(description = "Exception when getting Documentation content due to error retrieving document content", expectedExceptions = APIManagementException.class)
public void testGetDocumentationContentErrorOnRetrieval() throws APIManagementException {
ApiDAO apiDAO = mock(ApiDAO.class);
AbstractAPIManager apiPublisher = getApiPublisherImpl(apiDAO);
when(apiDAO.getDocumentInfo(DOC_ID)).thenThrow(new APIMgtDAOException("Error occurred while retrieving document content", new SQLException()));
apiPublisher.getDocumentationContent(DOC_ID);
verify(apiDAO, times(0)).getDocumentFileContent(DOC_ID);
verify(apiDAO, times(0)).getDocumentInlineContent(DOC_ID);
}
use of org.wso2.carbon.apimgt.api.model.Documentation in project carbon-apimgt by wso2.
the class AbstractAPIManagerTestCase method testGetDocumentationContentFile.
@Test(description = "Getting Documentation content when source type is FILE")
public void testGetDocumentationContentFile() throws APIManagementException {
ApiDAO apiDAO = mock(ApiDAO.class);
AbstractAPIManager apiPublisher = getApiPublisherImpl(apiDAO);
DocumentInfo.Builder builder = new DocumentInfo.Builder();
builder.name("CalculatorDoc");
builder.sourceType(DocumentInfo.SourceType.FILE);
DocumentInfo documentInfo = builder.build();
when(apiDAO.getDocumentInfo(DOC_ID)).thenReturn(documentInfo);
String stream = "This is sample file content";
InputStream inputStream = new ByteArrayInputStream(stream.getBytes());
when(apiDAO.getDocumentFileContent(DOC_ID)).thenReturn(inputStream);
apiPublisher.getDocumentationContent(DOC_ID);
verify(apiDAO, times(1)).getDocumentFileContent(DOC_ID);
}
use of org.wso2.carbon.apimgt.api.model.Documentation in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUnableToUpdateDocumentationException.
@Test(description = "Unable to update documentation info")
public void testUnableToUpdateDocumentationException() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultDocumentationInfo();
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
Mockito.when(apiDAO.isDocumentExist(API_ID, documentInfo)).thenReturn(true);
Mockito.doThrow(APIMgtDAOException.class).when(apiDAO).updateDocumentInfo(API_ID, documentInfo, USER);
try {
apiPublisher.updateDocumentation(API_ID, documentInfo);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Unable to update the documentation");
}
}
use of org.wso2.carbon.apimgt.api.model.Documentation in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testAddDocumentationContent.
@Test(description = "Add documentation inline content")
public void testAddDocumentationContent() throws APIManagementException, IOException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
String inlineContent = SampleTestObjectCreator.createDefaultInlineDocumentationContent();
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
apiPublisher.addDocumentationContent(DOC_ID, inlineContent);
Mockito.verify(apiDAO, Mockito.times(1)).addDocumentInlineContent(DOC_ID, inlineContent, USER);
}
use of org.wso2.carbon.apimgt.api.model.Documentation in project ballerina by ballerina-lang.
the class SignatureHelpUtil method getSignatureInfoModel.
/**
* Get the required signature information filled model.
*
* @param bInvokableSymbol Invokable symbol
* @param signatureContext Signature operation context
* @return {@link SignatureInfoModel} SignatureInfoModel containing signature information
*/
private static SignatureInfoModel getSignatureInfoModel(BInvokableSymbol bInvokableSymbol, TextDocumentServiceContext signatureContext) {
Map<String, String> paramDescMap = new HashMap<>();
SignatureInfoModel signatureInfoModel = new SignatureInfoModel();
List<ParameterInfoModel> paramModels = new ArrayList<>();
String functionName = signatureContext.get(SignatureKeys.CALLABLE_ITEM_NAME);
CompilerContext compilerContext = signatureContext.get(DocumentServiceKeys.COMPILER_CONTEXT_KEY);
BLangPackage bLangPackage = signatureContext.get(DocumentServiceKeys.LS_PACKAGE_CACHE_KEY).findPackage(compilerContext, bInvokableSymbol.pkgID);
BLangFunction blangFunction = bLangPackage.getFunctions().stream().filter(bLangFunction -> bLangFunction.getName().getValue().equals(functionName)).findFirst().orElse(null);
if (!blangFunction.getDocumentationAttachments().isEmpty()) {
// Get the first documentation attachment
BLangDocumentation bLangDocumentation = blangFunction.getDocumentationAttachments().get(0);
signatureInfoModel.setSignatureDescription(bLangDocumentation.documentationText.trim());
bLangDocumentation.attributes.forEach(attribute -> {
if (attribute.docTag.equals(DocTag.PARAM)) {
paramDescMap.put(attribute.documentationField.getValue(), attribute.documentationText.trim());
}
});
} else {
// TODO: Should be deprecated in due course
// Iterate over the attachments list and extract the attachment Description Map
blangFunction.getAnnotationAttachments().forEach(annotationAttachment -> {
BLangExpression expr = annotationAttachment.expr;
if (expr instanceof BLangRecordLiteral) {
List<BLangRecordLiteral.BLangRecordKeyValue> recordKeyValues = ((BLangRecordLiteral) expr).keyValuePairs;
for (BLangRecordLiteral.BLangRecordKeyValue recordKeyValue : recordKeyValues) {
BLangExpression key = recordKeyValue.key.expr;
BLangExpression value = recordKeyValue.getValue();
if (key instanceof BLangSimpleVarRef && ((BLangSimpleVarRef) key).getVariableName().getValue().equals("value") && value instanceof BLangLiteral) {
String annotationValue = ((BLangLiteral) value).getValue().toString();
if (annotationAttachment.getAnnotationName().getValue().equals("Param")) {
String paramName = annotationValue.substring(0, annotationValue.indexOf(UtilSymbolKeys.PKG_DELIMITER_KEYWORD));
String annotationDesc = annotationValue.substring(annotationValue.indexOf(UtilSymbolKeys.PKG_DELIMITER_KEYWORD) + 1).trim();
paramDescMap.put(paramName, annotationDesc);
} else if (annotationAttachment.getAnnotationName().getValue().equals("Description")) {
signatureInfoModel.setSignatureDescription(annotationValue);
}
}
}
}
});
}
bInvokableSymbol.getParameters().forEach(bVarSymbol -> {
ParameterInfoModel parameterInfoModel = new ParameterInfoModel();
parameterInfoModel.setParamType(bVarSymbol.getType().toString());
parameterInfoModel.setParamValue(bVarSymbol.getName().getValue());
parameterInfoModel.setDescription(paramDescMap.get(bVarSymbol.getName().getValue()));
paramModels.add(parameterInfoModel);
});
signatureInfoModel.setParameterInfoModels(paramModels);
return signatureInfoModel;
}
Aggregations