use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.
the class HtmlDocTest method testAnnotations.
@Test(description = "Annotation in a package should be shown in the constructs")
public void testAnnotations() throws Exception {
BLangPackage bLangPackage = createPackage("package x.y; " + "public annotation ParameterInfo;" + "public annotation ReturnInfo;");
Page page = generatePage(bLangPackage);
Assert.assertEquals(page.constructs.size(), 2);
Assert.assertEquals(page.constructs.get(0).name, "ParameterInfo");
Assert.assertEquals(page.constructs.get(1).name, "ReturnInfo");
}
use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.
the class Generator method generatePage.
/**
* Generate the page when the bal package is passed.
* @param balPackage The current package that is being viewed.
* @param packages List of available packages.
* @return A page model for the current package.
*/
public static Page generatePage(BLangPackage balPackage, List<Link> packages) {
ArrayList<Documentable> documentables = new ArrayList<>();
String currentPackageName = (balPackage.symbol).pkgID.name.value;
// Check for structs in the package
if (balPackage.getStructs().size() > 0) {
for (BLangStruct struct : balPackage.getStructs()) {
if (struct.getFlags().contains(Flag.PUBLIC)) {
documentables.add(createDocForNode(struct));
}
}
}
// Check for functions in the package
if (balPackage.getFunctions().size() > 0) {
for (BLangFunction function : balPackage.getFunctions()) {
if (function.getFlags().contains(Flag.PUBLIC)) {
if (function.getReceiver() != null) {
if (documentables.size() > 0) {
for (Documentable parentDocumentable : documentables) {
TypeNode langType = function.getReceiver().getTypeNode();
String typeName = (langType instanceof BLangUserDefinedType ? ((BLangUserDefinedType) langType).typeName.value : langType.toString());
if (typeName.equals(parentDocumentable.name)) {
parentDocumentable.children.add(createDocForNode(function));
}
}
}
} else {
// If there's no receiver type i.e. no struct binding to the function
documentables.add(createDocForNode(function));
}
}
}
}
// Check for connectors in the package
for (BLangConnector connector : balPackage.getConnectors()) {
if (connector.getFlags().contains(Flag.PUBLIC)) {
documentables.add(createDocForNode(connector));
}
}
// Check for connectors in the package
for (EnumNode enumNode : balPackage.getEnums()) {
if (enumNode.getFlags().contains(Flag.PUBLIC)) {
documentables.add(createDocForNode(enumNode));
}
}
// Check for annotations
for (BLangAnnotation annotation : balPackage.getAnnotations()) {
if (annotation.getFlags().contains(Flag.PUBLIC)) {
documentables.add(createDocForNode(annotation));
}
}
// Check for global variables
for (BLangVariable var : balPackage.getGlobalVariables()) {
if (var.getFlags().contains(Flag.PUBLIC)) {
documentables.add(createDocForNode(var));
}
}
// Create the links to select which page or package is active
List<Link> links = new ArrayList<>();
PackageName packageNameHeading = null;
for (Link pkgLink : packages) {
if (pkgLink.caption.value.equals(currentPackageName)) {
packageNameHeading = (PackageName) pkgLink.caption;
links.add(new Link(pkgLink.caption, pkgLink.href, true));
} else {
links.add(new Link(pkgLink.caption, pkgLink.href, false));
}
}
return new Page(packageNameHeading, documentables, links);
}
use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.
the class DocumentationTest method testDocEnum.
@Test(description = "Test doc annotation enum.")
public void testDocEnum() {
CompileResult compileResult = BCompileUtil.compile("test-src/documentation/enum.bal");
Assert.assertEquals(0, compileResult.getWarnCount());
PackageNode packageNode = compileResult.getAST();
List<BLangDocumentation> docNodes = ((BLangEnum) packageNode.getEnums().get(0)).docAttachments;
BLangDocumentation dNode = docNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, " Documentation for state enum\n");
Assert.assertEquals(dNode.getAttributes().size(), 2);
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "foo");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " enum `field foo` documentation\n");
Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "bar");
Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " enum `field bar` documentation");
}
use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.
the class DocumentationTest method testMultiple.
@Test(description = "Test doc multiple.")
public void testMultiple() {
CompileResult compileResult = BCompileUtil.compile("test-src/documentation/multiple.bal");
Assert.assertEquals(0, compileResult.getWarnCount());
PackageNode packageNode = compileResult.getAST();
List<BLangDocumentation> docNodes = ((BLangStruct) packageNode.getStructs().get(0)).docAttachments;
BLangDocumentation dNode = docNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, " Documentation for Tst struct\n");
Assert.assertEquals(dNode.getAttributes().size(), 3);
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "a");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " annotation `field a` documentation\n");
Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "b");
Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " annotation `field b` documentation\n");
Assert.assertEquals(dNode.getAttributes().get(2).documentationField.getValue(), "c");
Assert.assertEquals(dNode.getAttributes().get(2).documentationText, " annotation `field c` documentation");
docNodes = ((BLangEnum) packageNode.getEnums().get(0)).docAttachments;
dNode = docNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, " Documentation for state enum\n");
Assert.assertEquals(dNode.getAttributes().size(), 2);
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "foo");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " enum `field foo` documentation\n");
Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "bar");
Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " enum `field bar` documentation");
docNodes = ((BLangTransformer) packageNode.getTransformers().get(0)).docAttachments;
dNode = docNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "\n" + " Transformer Foo Person -> Employee\n" + " ");
Assert.assertEquals(dNode.getAttributes().size(), 3);
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "p");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " input struct Person source used for transformation\n ");
Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "e");
Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " output struct Employee struct which Person transformed to\n ");
Assert.assertEquals(dNode.getAttributes().get(2).documentationField.getValue(), "defaultAddress");
Assert.assertEquals(dNode.getAttributes().get(2).documentationText, " address which serves Eg: `POSTCODE 112`\n");
BLangService service = (BLangService) packageNode.getServices().get(0);
docNodes = service.docAttachments;
dNode = docNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, "PizzaService HTTP Service");
/*
// Commented due to https://github.com/ballerina-lang/ballerina/issues/5586 issue
dNode = service.getResources().get(0).docAttachments.get(0);
Assert.assertEquals(dNode.getAttributes().size(), 2);
Assert.assertEquals(dNode.documentationText, "Check orderPizza resource. ");
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "conn");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText,
" HTTP connection. ");
Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "req");
Assert.assertEquals(dNode.getAttributes().get(1).documentationText,
" In request.");
dNode = service.getResources().get(1).docAttachments.get(0);
Assert.assertEquals(dNode.documentationText, "Check status resource. ");
Assert.assertEquals(dNode.getAttributes().size(), 2);
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "conn");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText,
" HTTP connection. ");
Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "req");
Assert.assertEquals(dNode.getAttributes().get(1).documentationText,
" In request.");*/
}
use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.
the class ProducesConsumesAnnotationTest method testBogusProducesAnnotation.
@Test(description = "Test bogus Produces annotation with URL. /echo66/test2 ")
public void testBogusProducesAnnotation() {
String path = "/echo66/test2";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
cMsg.setHeader(HttpHeaderNames.ACCEPT.toString(), ":,;,v567br");
HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_EP, cMsg);
Assert.assertNotNull(response, "Response message not found");
int trueResponse = (int) response.getProperty(HttpConstants.HTTP_STATUS_CODE);
Assert.assertEquals(trueResponse, 406, "Not acceptable");
}
Aggregations